Make X person get a weapon when reached an amount of kills.

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]

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]

Missed a comma after “RewardShotgun”.

Doesent matter - it’s only if the killer has 50 frags.

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.

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!

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.