Make certain teams spawn with armor

I have tried several methods of setting certain team armor amounts in DarkRP. Unfortunately, none of them have been successful.

So far:

[lua]
hook.Add(“PlayerSpawn”, “LawArmor”, function(ply)
if ply:Team() == TEAM_POLICE then
ply:SetArmor( 35 )
elseif ply:Team() == TEAM_CHIEF then
ply:SetArmor( 50 )
elseif ply:Team() == TEAM_MAYOR then
ply:SetArmor( 50 )
else
ply:SetArmor( 0 )
end
end)
[/lua]

[lua]
hook.Add(‘PlayerLoadout’, ‘setarmor’, function(ply) if ply:Team() == TEAM_POLICE then
ply:SetArmor(35)
end
end)
[/lua]

Neither of these methods worked (both placed within the GM:PlayerSpawn function withith gamemode_functions.lua). However one did work partially. The first code shown worked, except it only gave the police team 50 armor. Should’ve been 35. Every other specified team didn’t work. Any input would be highly appreciated.

http://forum.facepunch.com/showthread.php?t=1249475
Use [lua] tags.

I’ve set these as lua tags many times now. They keep resetting, sorry about that.

I’ve been scripting in gLua for 3+ years and never had issues like this til GMod13 came out. It seems Garry has changed how the Lua module parses Lua files. It’s strange. But this is the work-around I’ve figured out. Give it a shot.

[lua]hook.Add(“PlayerSpawn”, “LawArmor”, function(ply)
if ply:Team() == TEAM_POLICE then ply:SetArmor( 35 ); return; end
if ply:Team() == TEAM_CHIEF then ply:SetArmor( 50 ); return; end
if ply:Team() == TEAM_MAYOR then ply:SetArmor( 50 ); return; end
ply:SetArmor(0);
end) [/lua]

Any idea how he’s modified the parsing? Is it the conditional logic that he’s changed, or is it returning, or what?

Just curious. I don’t want to code something in the future using elseifs if there’s a chance that, for whatever reason, it won’t work properly.

I’m not sure if he has, or what. But sometimes elseif’s work, sometimes they don’t. It throws me off. But did that code work out for you?

I’m not the OP, just curious, haha.

Well, time for me to get some sleep ._.

Try putting hook.add below the end), it seems to work for me 90% of the time.
Happy scripting!

Why not use modules?

Alright guys, sorry about the delay. Had a job orientation today as well as other responsibilities. I’ll test the code now and get back to you all immediately.

[editline]2nd July 2013[/editline]

Okay, it appears one of two things are happening. Does the gamemode_functions.lua update automatically or does it require a server restart for the changes to apply? The new hook didn’t break anything this time around but also didn’t make the changes it was supposed to make. I’m thinking either it worked but the server needs to be restarted or it simply didn’t work and needs to be tweaked. Ideas?