Armor?

<3 to those who have been helping me out.
Lastly. Can anybody help me out with certain jobs spawning with armor on DarkRP?
I want Police,Mayor, etc to spawn with armor. The old function I wrote up doesn’t work anymore.

In gamemode/server/gamemode_functions.lua add this in the GM:PlayerSpawn() function.

[lua] local ok = ply:Team()
if ok == TEAM_POLICE or ok == TEAM_CHIEF or ok == TEAM_MAYOR then
ply:SetArmor(25)
end[/lua]

[lua]
local table = {
“TEAM_POLICE”,
“TEAM_CHIEF”,
“TEAM_MAYOR”
}

function PlayerSpawnArmor(ply)
for k,v in pairs(table) do
if ply:Team() == v then
ply:SetArmor(25)
end
end
end
hook.Add(“PlayerSpawn”, “armorcheck”, PlayerSpawnArmor)
[/lua]

ply:Team() always returns a number, the variables TEAM_POLICE are set to numbers, since you’re using quotes, its going to compare a number to a string and it’s never going to give armour to players. Also keeping that function global is stupid too, utilizes more memory and slows down code, I understand you will hardly notice the performance but if you keep this regular and make all your functions global, you will start noticing things slow down. Also try and refrain from using variable names such as “table”, as you used that outside of the hook, if there were to be another function or code under the hook trying to utilize table functions, it will error. I used something better like “jobs”

[lua]local jobs = {
TEAM_POLICE,
TEAM_CHIEF,
TEAM_MAYOR
}

hook.Add( “PlayerSpawn”, “armorcheck”, function( Player )
for k, v in pairs( jobs ) do
if Player:Team() == v then
Player:SetArmor( 25 )
end
end
end )[/lua]

i didn’t get time to proof-read my code.

No worries, I explained the things in more detail, I was a little bit insulting in the post and have taken back anything that should insult you in any way, you’re clearly new to LUA.

i’m not new lol, i just didn’t get time to proof read

I changed this a bit and it works great. Thanks guys

Instead of for looping, to save space you could use table.HasValue( jobs, ply:Team() )

Makes no difference, the table.HasValue also loops too. If you look at lua/includes/extensions/table.lua you’ll see for yourself.