• Will my code work? [beginner]
    6 replies, posted
First off all, i want a code that can give a specific playerid a weapon. (Donator thing so i can make a donator kit like assault kit wich gives a assault rifle etc..) Ok, so the steamid is not real nor is the weapon id real, it's just a example. Would this work? I am just starting out and barely learned any lua but will it work? [lua]PlayerSpawn = function(ply) if userid == "steam_0:16627382" then ply:Give( "m9k_glock" ) end,[/lua]
Assuming "userid" was declared, and PlayerSpawn belongs in a table, then yes, the syntax seems correct, except you missed an "end" to close the function "PlayerSpawn" Here's the completed code: [code] PlayerSpawn = function( Player ) if ( Player:SteamID() == "STEAM_0:16627382" ) then Player:Give( "m9k_glock" ) end end, [/code] Or, as a line: [code] PlayerSpawn = function( Player ) if ( Player:SteamID() == "STEAM_0:16627382" ) then Player:Give("m9k_glock" ) end end, [/code]
Ok, so is there any other way to do this so i don't have to place it in every single job?
[CODE] hook.Add( "PlayerSpawn", "name whatever", function( ply ) if ply:SteamID() == "STEAM_0:16627382" then ply:Give( "m9k_glock" ) end end ) [/CODE]
better hook to use is [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerLoadout]GM/PlayerLoadout[/url] [code] hook.Add( "PlayerLoadout", "name whatever", function( ply ) if ply:SteamID() == "STEAM_0:16627382" then ply:Give( "m9k_glock" ) end end ) [/code]
[QUOTE=Potatofactory;49882952]better hook to use is [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerLoadout]GM/PlayerLoadout[/url] [code] hook.Add( "PlayerLoadout", "name whatever", function( ply ) if ply:SteamID() == "STEAM_0:16627382" then ply:Give( "m9k_glock" ) end end ) [/code][/QUOTE] Where do i put this? Do i just put it somewhere in jobs.lua?
Anywhere serverside
Sorry, you need to Log In to post a reply to this thread.