NPC Kill pay system revised

Hey people of Facepunch.

I betcha all know of the NPC pay pr. kill system in the DarkRP. But if you’re asking me, it’s a bit lame way to do it.
So instead of granting the player magically the chosen amount of money, would there be a way to have the money drop on the ground instead?

& Maybe make it happen randomly, like one drop between every 1 and 5 kills or something?

You could find the dropmoneyondeath hook and use it on OnNPCKilled, then use math.random 1, 5.

Your suggestion didn’t work, and console isn’t coming up with any errors, so I can’t even tell if it’s reading the code.

Any suggestions?

[lua]
function GM:OnNPCKilled(victim, ent, weapon)
local kills = math.random(1, 5)
if ValidEntity(ent) then
if ent:IsVehicle() and ent:GetDriver():IsPlayer() then ent = ent:GetDriver() end
if kills <= 3 then
CreateMoneyBag(victim:GetPos() + Vector(0,0,64), math.random(10,20))
end
end
for k,v in pairs(player.GetAll()) do
if v:IsAdmin() then
v:PrintMessage(HUD_PRINTCONSOLE,victim:GetClass() … " was killed by " … ent:GetName()… " with a " … weapon:GetClass() … ".
" )
end
end
end
[/lua]
Not sure if this is what you’re looking for.

Either that didn’t work, or I’m doing it wrong…

I just replaced the original code with your code, yet it still didn’t work, am I doing something wrong?

[lua]
function GM:OnNPCKilled(victim, ent, weapon)
local kills = math.random(1, 5)
if ValidEntity(ent) then
if ent:IsVehicle() and ent:GetDriver():IsPlayer() then ent = ent:GetDriver() end
if kills <= 3 then
DarkRPCreateMoneyBag(victim:GetPos() + Vector(0,0,64), math.random(10,20))–woops
end
end
for k,v in pairs(player.GetAll()) do
if v:IsAdmin() then
v:PrintMessage(HUD_PRINTCONSOLE,victim:GetClass() … " was killed by " … ent:GetName()… " with a " … weapon:GetClass() … ".
" )
end
end
end
[/lua]
Wrong name… use that instead.

Thanks but the math.random part doesn’t work. It still drops on every kill

Isn’t it supposed to be “local kills = math.random(1,5)” Instead of “local kills = math.random(1, 5)”?

It doesn’t matter if there’s a space after the comma.
You can debug it if you want and put in:
[lua]
if ent:IsVehicle() and ent:GetDriver():IsPlayer() then ent = ent:GetDriver() end
print(kills)–Debug
if kills <= 3 then
[/lua]
Since you say it keeps constantly dropping do:
[lua]
local kills = math.random(1, 2)
if ent:IsVehicle() and ent:GetDriver():IsPlayer() then ent = ent:GetDriver() end
if kills == 2 then-- or 1 do w/e
[/lua]

Mkay, but removing the space after comma fixed my problem.
Thanks for your help, it’s all working now :slight_smile:

No problem but the space really doesn’t matter.