Money received from NPC

Well i tried using this function so when someone kills a NPC they get 50$ but it didn’t seem to work. And i did defined AddMoney

function GM:OnNPCKilled( victim, killer, weapon )
Killer:AddMoney(50)
end

the other function for Player works fine…

function playerDies( victim, weapon, killer )

killer:AddMoney(50)

end

use lua tags, And lua is case sensitive you wrote Killer it should be killer

-snip-

[lua]
function GM:OnNPCKilled( victim, killer, weapon )
killer:SetNWInt(“money”, killer:GetNWInt(“money”) + 50)
end

the other function for Player works fine…

function playerDies( victim, weapon, killer )
killer:SetNWInt(“money”, killer:GetNWInt(“money”) + 50)
end
[/lua]

And what Tobba said

Still dosen’t work…

You havn’t set the NWInt for money have you?

i did XD.

What do you mean when you say it doesn’t work, does it error? You need to be more specific if you want help.

Ok this is what happens. I put in the function. I launch my GM. I kill a zombie NPC and i don’t any money. i Have a HUD that shows how much cash i got and it works fine…

Are you sure the AddMoney method is working?

function playerDies( victim, weapon, killer )

killer:AddMoney(50)
end

that works fine for Players

I can see in your first post that in the OnNPCKilled Function, you have the argument as killer but are using Killer in the function, could this be the problem?

That playerDies function does nothing on it’s own, there is a hook.Add command somewhere in your code that makes use of it. I’m guessing that this script is not run in a gamemode environement thus the GM table is unavailable and you are getting errors which you are not reporting. Try using hook.Add for OnNPCKilled as well.

ok heres my new function im going to test it

function NpcMoney(killer,attacker,inflictor)
killer:AddMoney(50)
end
hook.Add(“OnNpcKilled”,“MoneyMoneyMoney”,NpcMoney)

[editline]09:23PM[/editline]

nope…

GM:OnNPCKilled( NPC, killer, weapon )

You mixed it up, dog.

Like BoingBoing said you capitalized it wrong, and from now on “nope…” is not an acceptable answer. Your code IS producing lua errors, you should be able to find out your problems just by reading them or you could at least post them here so that people can help you fix them. They’re there, all the way up in your console.

[editline]09:05PM[/editline]

And if you can’t find the errors use lua_openscript “path/to/yourscript.lua”

The code is part of a GM.

Good, load it up and search the console for errors. Come back when you’re done.

Maplecaca, try this snippet of code out, it might work, but I am unsure.
It is untested

init.lua
[lua]function GM:OnNPCKilled( victim, killer, weapon )

if ( victim:GetClass()  == "npc_*" ) then 

	killer:AddMoney( 50 )
	
else return

end

end[/lua]
if it dosen’t work, make a check:
init.lua
[lua]function GM:OnNPCKilled( victim, killer, weapon )

if ( victim:GetClass()  == "npc_*" ) and ( killer:IsPlayer() ) then 

	killer:AddMoney( 50 )
	
else return

end

end[/lua]
Hope this works out good for you.
Good luck.

Sylph found the error , the error is that the NPC im using to spawn are SNPC’s