if die respawn with

hey anyone know a script that will change the loadout the second time u spawn

basicly my idea is that you start with an ak an deagle but after dieing are punished by giving a lower class weapon so i was wondering if anyone knows of any scripts thanx in advance


(User was banned for this post ("Undescriptive thread title" - mahalis))

[lua]function GM:PlayerLoadout(ply)
if ply:Deaths() == 0 then
–Loadout 1
else
–Loadout 2
end
end[/lua]
[Gamemode.PlayerLoadout

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?search=Gamemode.PlayerLoadout) <-- See this page if you’re not making a gamemode
[Player.Deaths

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?search=Player.Deaths)

:science:

thanks im new to this forum (only been posting just today) can already tell your the best of the best but one quick noob question, heres my autorun lua so far

local weapons = {
“weapon_physcannon”,
“weapon_physgun”,
“gmod_tool”,
“gmod_camera”,
}

hook.Add(“PlayerLoadout”,“RestrictWeapons”,function(ply)
for _,v in ipairs(weapons) do ply:Give(v) end
return true
end)

using ure code would i remove this and then enter the weapons into your code where it says loadout 1 and loadout 2 or would i have to keep this code and then enter the weapons in loadout 1 and loadout 2?

[lua]function GM:PlayerLoadout(ply)
if ply:Deaths() == 0 then
ply:Give(“weapon_physgun”)
ply:Give(“gmod_tool”)
else
ply:Give(“weapon_physcannon”)
ply:Give(“gmod_camera”)
end
end[/lua]

A bit like that, just with changed weapon entities.

Well assuming the only thing you want to change is giving a deagle on the first spawn you would do this :


local weapons = {
"weapon_physcannon",
"weapon_physgun",
"gmod_tool",
"gmod_camera",
}

hook.Add("PlayerLoadout","CustomLoadout",function(ply)
	if ply:Deaths() == 0 then --If the player has yet to die then 
		ply:Give("weapon_deagle") -- give him his sweet deagle
	end
	
	for _,v in ipairs(weapons) do	--For key and value pair of the weapons table
		ply:Give(v) -- Give the player the content of the value
	end 
	
	return true --Returning here overrides the gamemode's default loadout.
end)

Also for readability please post your code in either [noparse]




or [lua][/lua] [/noparse] tags.

And I’m not the best of the best!:aaa:

That would work assuming you are using this in a gamemode, for a script you need to use hook.Add like in the example I’ve posted.

[hook.Add

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?search=hook.Add)

True, I just copypastad your code for a quick example. He was already using hook.Add, but he would have copied it. Sorry :slight_smile:

hey thanx for the great help guys

worked like a charm after adding this i decided to basicly make it so that ur not only stripped of your ak but rather ur stripped of it and then given another weapon in this case a crowbar so i basicly copied the code used for if player has yet to die ie if deaths = 0 with if deaths = 1 to crowbar however it isnt working i was wondering if you could tell me whats going wrong here thanx in advance


 
local weapons = {
"weapon_deagle",

}

hook.Add("PlayerLoadout","CustomLoadout",function(ply)
	if ply:Deaths() == 0 then --If the player has yet to die then 
		ply:Give("weapon_AK47") -- give him his sweet AK47
	end

	if ply:Deaths() == 1 then --If the player has yet to die then 
		ply:Give("weapon_crowbar") -- give him his sweet AK47
	end
	
	
	for _,v in ipairs(weapons) do	--For key and value pair of the weapons table
		ply:Give(v) -- Give the player the content of the value
	end 
	
	return true --Returning here overrides the gamemode's default loadout.
end)



[editline]12:31AM[/editline]

bump