• When Player Spawns, if x=1 then give weapon
    5 replies, posted
I'm trying to make it so when a player spawns they are given a weapon if a certain variable equals 1. But it doesn't seem to work.. I tried using PlayerLoadOut and PlayerInitialSpawn.. How would I do this
Is this variable set per-player or globally? If it is per player use:[lua]function Loadout( ply ) if ply.VariableName == 1 then ply:Give("weapon_shotgun") //what gun you want to give end end hook.Add( "PlayerLoadout", "Loadout", Loadout)[/lua] Otherwise: [lua]function Loadout( ply ) if VariableName == 1 then ply:Give("weapon_shotgun") //what gun you want to give end end hook.Add( "PlayerLoadout", "Loadout", Loadout)[/lua] should work fine
Also, if you want to override the gamemode's default PlayerLoadout, so the player is [B]only[/B] given the weapons you add in the callback, just return true.
[lua]function PlayersLoadout( ply ) local GlockVar = ply:GetPData( "PermGlockVar" ) if GlockVar == 1 then ply:Give("weapon_real_cs_glock18") end end [/lua] GlockVar is equal to 1... and I don't get a gun.
You forgot the most important part. [lua] hook.Add( "PlayerLoadout", "whatever", PlayersLoadout) [/lua] Also, make sure player:GetPData("PermGlockVar") really is returning 1, and not "1", or something else.
I'm sure that pdata converts numbers to strings, so you would have to do 'if tonumber(GlockVar) == 1 then'
Sorry, you need to Log In to post a reply to this thread.