[lua]
local allowed = {
“weapon_physgun”,
“weapon_gravgun”,
“gmod_tool”,
“pocket”,
“keys”
}
function MayorCantWeapon( ply, wep )
if ply:Team() == TEAM_MAYOR then
if not table.HasValue(allowed,wep:GetClass()) then return false end
end
return true
end
hook.Add(“PlayerCanPickupWeapon”, “MayorCantPickup”, MayorCantWeapon)
[/lua]
Why yours did not work:
[lua]
function MayorCantWeapon( ply )
local allowed = {
“weapon_physgun”,
“weapon_gravgun” – You forgot “,” here.
“gmod_tool” – You forgot “,” here.
“pocket” – You forgot “,” here.
“keys”
}
if ply:Team() == TEAM_MAYOR then
if allowed then – You’re checking if allow exists, since the table is created (If you fix the “,” problem). It will always do “return true”.
return true
else – If allowed is nil, then return false.
return false
else – This is not needed and will never be checked.
return true
end
– Add a return true here so people will pickup the weapon if they’re not the mayor.
end
hook.Add(“PlayerCanPickupWeapon”, “MayorCantPickup”, MayorCantWeapon)
[/lua]
Sorry if I could not explain very well why things went wrong, English is not my first language.