• Make X person get a weapon when reached an amount of kills.
    11 replies, posted
I want to make a script that gives people a weapon when they reach a certain amount of kills. Like: Player X reach 50 kills and he gets weapon_shotgun Basicly thats it. If anyone could lead me in some direction to a help thread for this or could make a code for me I would be happy. Thank you.
[lua] hook.Add( "PlayerDeath", "RewardShotgun" function( victim, inflictor, killer ) if killer:Frags() == 50 then killer:Give( "weapon_shotgun" ) end end) [/lua]
[QUOTE=Drakehawke;23987471][lua] hook.Add( "PlayerDeath", "RewardShotgun" function( victim, inflictor, killer ) if killer:Frags() == 50 then killer:Give( "weapon_shotgun" ) end end) [/lua][/QUOTE] Thank you very much! [editline]04:20PM[/editline] Hook 'RewardShotgun' Failed: gamemodes\ocdm\gamemode\init.lua:67: attempt to call method 'Frags' (a nil value) Whats wrong?
Try this. A non-player may be killing the user. [lua]function GiveShotgun( vic, wep, kl ) if ( kl:IsPlayer() ) then if ( kl:Frags() == 50 ) then kl:Give( "weapon_shotgun" ) end end end hook.Add( "PlayerDeath", "Shotgun", GiveShotgun )[/lua]
[QUOTE=Drakehawke;23987471][lua] hook.Add( "PlayerDeath", "RewardShotgun" function( victim, inflictor, killer ) if killer:Frags() == 50 then killer:Give( "weapon_shotgun" ) end end) [/lua][/QUOTE] Missed a comma after "RewardShotgun". [QUOTE=TommieBoy;23988876]Try this. A non-player may be killing the user. [/QUOTE] Doesent matter - it's only if the killer has 50 frags.
[QUOTE=Busymonkey;23989323]Doesent matter - it's only if the killer has 50 frags.[/QUOTE] There won't be a :Frags property unless it's a player though, so it might error.
I guess it's probably because he missed the comma then.
[QUOTE=Busymonkey;23989323]Missed a comma after "RewardShotgun". Doesent matter - it's only if the killer has 50 frags.[/QUOTE] Oops, and actually, It would matter if it wasn't a player, because killer would be nil.
Yea got it to work. [lua] hook.Add( "PlayerDeath", "RewardShotgun", function( victim, inflictor, killer ) if killer:Frags() == 5 then killer:Give( "weapon_shotgun" ) end end) [/lua] That code ^ Thanks to everyone!
[QUOTE=Crap-Head;23989615]Yea got it to work. [lua] hook.Add( "PlayerDeath", "RewardShotgun", function( victim, inflictor, killer ) if killer:Frags() == 5 then killer:Give( "weapon_shotgun" ) end end) [/lua] That code ^ Thanks to everyone![/QUOTE] I'm positive you'll get errors with this sooner or later because the killer may not always be a player..
Then why not solve this problem with a simple solution? [lua] hook.Add( "PlayerDeath", "RewardShotgun", function( victim, inflictor, killer ) if killer:IsPlayer() and killer:Frags() == 5 then killer:Give( "weapon_shotgun" ) end end) [/lua]
That is what was suggested about 5 posts ago.
Sorry, you need to Log In to post a reply to this thread.