• Mayor can't pick up weapons?
    2 replies, posted
[code]function MayorCantWeapon( ply ) local allowed = { "weapon_physgun", "weapon_gravgun" "gmod_tool" "pocket" "keys" } if ply:Team() == TEAM_MAYOR then if allowed then return true else return false else return true end end hook.Add("PlayerCanPickupWeapon", "MayorCantPickup", MayorCantWeapon)[/code] I tried this script I made, but it doesn't work does anyone know whats wrong with this?? Im trying to make it so the mayor can only have the default loadout (Grav gun, physgun, tool gun, camera, pocket, and keys)
[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.
Thanks, I'm not good at lua coding. Trying to learn for my server
Sorry, you need to Log In to post a reply to this thread.