• How to make dead npc drop money in Darkrp ?.
    13 replies, posted
Well, like the title say :). I tried to create a function that make npc drop money in darkrp when they get killed, but it's don't work at all. :(. function GM:OnNPCKilled( victim, killer, weapon ) local RandomNumber = math.random(1,3) local NpcPos = victim:GetPos if RandomNumber == 1 then local Mn = DarkRPCreateMoneyBag local amount = GetConVarNumber("npckillpay") Mn:SetPos(NpcPos+Vector(0,0,64)) end end Please help. ! Thanks in advance :D.
try [lua]function GM:OnNPCKilled( victim, killer, weapon ) local RandomNumber = math.random(1,3) if RandomNumber == 1 then local amount = GetConVarNumber("npckillpay") DarkRPCreateMoneyBag(victim:GetPos() + Vector(0,0,64), amount) end end [/lua]
Thank you ! It's worked XD. Now my friends will can't camping anymore :3.
I tried to make it more custom. Can you guys help me one more time ? :D Thanks first. function GM:OnNPCKilled( victim, killer, weapon ) local RandomNumber = math.random(1,3) if RandomNumber == 1 and victim:GetClass() == "npc_zombie" then local amount = GetConVarNumber("npckillpay") DarkRPCreateMoneyBag(victim:GetPos() + Vector(0,0,64), amount) end if RandomNumber == 1 and victim:GetClass() == "npc_fastzombie" then local amount = GetConVarNumber("npckillpay") + 10 DarkRPCreateMoneyBag(victim:GetPos() + Vector(0,0,64), amount ) end if RandomNumber == 1 and victim:GetClass() == "npc_poisonzombie" then local amount = GetConVarNumber("npckillpay") + 20 DarkRPCreateMoneyBag(victim:GetPos() + Vector(0,0,64), amount ) end end end end
[QUOTE=minhmap512;23675797]I tried to make it more custom. Can you guys help me one more time ? :D Thanks first. function GM:OnNPCKilled( victim, killer, weapon ) local RandomNumber = math.random(1,3) if RandomNumber == 1 and victim:GetClass() == "npc_zombie" then local amount = GetConVarNumber("npckillpay") DarkRPCreateMoneyBag(victim:GetPos() + Vector(0,0,64), amount) end if RandomNumber == 1 and victim:GetClass() == "npc_fastzombie" then local amount = GetConVarNumber("npckillpay") + 10 DarkRPCreateMoneyBag(victim:GetPos() + Vector(0,0,64), amount ) end if RandomNumber == 1 and victim:GetClass() == "npc_poisonzombie" then local amount = GetConVarNumber("npckillpay") + 20 DarkRPCreateMoneyBag(victim:GetPos() + Vector(0,0,64), amount ) end end end end[/QUOTE] Use these: [LUA ] [/LUA ] when you posting lua code, makes understanding the code so much better.. Anyway this is a little bit more cleaned up code[LUA]function GM:OnNPCKilled(victim, killer, weapon) if math.random(1,3) == 1 then if victim:GetClass() == "npc_zombie" then DarkRPCreateMoneyBag(victim:GetPos()+ Vector(0,0,64), GetConVarNumber("npckillpay")) end if victim:GetClass() == "npc_fastzombie" then DarkRPCreateMoneyBag(victim:GetPos()+ Vector(0,0,64), GetConVarNumber("npckillpay") + 10) end if victim:GetClass() == "npc_poisonzombie" then DarkRPCreateMoneyBag(victim:GetPos()+ Vector(0,0,64), GetConVarNumber("npckillpay") + 20) end end end[/LUA]But whats the problem?
[QUOTE=minhmap512;23675797]I tried to make it more custom. Can you guys help me one more time ? :D Thanks first. function GM:OnNPCKilled( victim, killer, weapon ) local RandomNumber = math.random(1,3) if RandomNumber == 1 and victim:GetClass() == "npc_zombie" then local amount = GetConVarNumber("npckillpay") DarkRPCreateMoneyBag(victim:GetPos() + Vector(0,0,64), amount) end if RandomNumber == 1 and victim:GetClass() == "npc_fastzombie" then local amount = GetConVarNumber("npckillpay") + 10 DarkRPCreateMoneyBag(victim:GetPos() + Vector(0,0,64), amount ) end if RandomNumber == 1 and victim:GetClass() == "npc_poisonzombie" then local amount = GetConVarNumber("npckillpay") + 20 DarkRPCreateMoneyBag(victim:GetPos() + Vector(0,0,64), amount ) end end end end[/QUOTE] You're not actually spawning it anywhere, are you?
[QUOTE=freemmaann;23677944]Use these: [LUA ] [/LUA ] when you posting lua code, makes understanding the code so much better.. Anyway this is a little bit more cleaned up code[LUA]function GM:OnNPCKilled(victim, killer, weapon) if math.random(1,3) == 1 then if victim:GetClass() == "npc_zombie" then DarkRPCreateMoneyBag(victim:GetPos()+ Vector(0,0,64), GetConVarNumber("npckillpay")) end if victim:GetClass() == "npc_fastzombie" then DarkRPCreateMoneyBag(victim:GetPos()+ Vector(0,0,64), GetConVarNumber("npckillpay") + 10) end if victim:GetClass() == "npc_poisonzombie" then DarkRPCreateMoneyBag(victim:GetPos()+ Vector(0,0,64), GetConVarNumber("npckillpay") + 20) end end end[/LUA]But whats the problem?[/QUOTE] How did you make this work? like did you put this into a .lua and put it in addons?
So as not to interfere with any other addons/the gamemode trying to use the OnNPCKilled hook, I recommend rewriting this as a hook use rather than overriding the function itself. [URL="https://wiki.garrysmod.com/page/hook/Add"]hook.Add[/URL]
Why doesn't this work? [CODE]function GM:OnNPCKilled(victim, killer, weapon) if math.random(1,3) == 1 then if victim:GetClass() == "npc_zombie" then killer:AddMoney(10) notification.AddLegacy( "Killed Zombie. $10", 1, 2) end if victim:GetClass() == "npc_fastzombie" then killer:AddMoney(20) notification.AddLegacy( "Killed Fast Zombie. $20", 1, 2) end if victim:GetClass() == "npc_poisonzombie" then killer:AddMoney(100) notification.AddLegacy( "Killed Poison Zombie. $100", 1, 2) end end end[/CODE] I got this [CODE][ERROR] gamemodes/darkrp/gamemode/modules/zombie cash/sv_zombiecash.lua:8: attempt to call method 'AddMoney' (a nil value) 1. unknown - gamemodes/darkrp/gamemode/modules/zombie cash/sv_zombiecash.lua:8 2. TakeDamageInfo - [C]:-1 3. IndividualThink - lua/weapons/cw_melee_base/shared.lua:225 4. unknown - lua/weapons/cw_base/shared.lua:1051[/CODE]
[QUOTE=Bear1ySane;52457939]Why doesn't this work? [CODE][ERROR] gamemodes/darkrp/gamemode/modules/zombie cash/sv_zombiecash.lua:8: attempt to call method 'AddMoney' (a nil value) 1. unknown - gamemodes/darkrp/gamemode/modules/zombie cash/sv_zombiecash.lua:8 2. TakeDamageInfo - [C]:-1 3. IndividualThink - lua/weapons/cw_melee_base/shared.lua:225 4. unknown - lua/weapons/cw_base/shared.lua:1051[/CODE][/QUOTE] Your issue is occurring because you're not referencing a valid function. If you're using DarkRP its actually addMoney(amt) not AddMoney(amt).
[QUOTE=QuackDuck;52458043]Your issue is occurring because you're not referencing a valid function. If you're using DarkRP its actually addMoney(amt) not AddMoney(amt).[/QUOTE] :/ Here is my code [editline]11th July 2017[/editline] [CODE]function GM:OnNPCKilled(victim, killer, weapon) if math.random(1,3) == 1 then if victim:GetClass() == "npc_zombie" then killer:AddMoney(10) notification.AddLegacy( "Killed Zombie. $10", 0, 2) end if victim:GetClass() == "npc_fastzombie" then killer:AddMoney(20) notification.AddLegacy( "Killed Fast Zombie. $20", 0, 2) end if victim:GetClass() == "npc_poisonzombie" then killer:AddMoney(100) notification.AddLegacy( "Killed Poison Zombie. $100", 0, 2) end end end[/CODE] [editline]11th July 2017[/editline] oh i see
Nope [CODE][ERROR] gamemodes/darkrp/gamemode/modules/zombie cash/sv_zombiecash.lua:3: attempt to call method 'addMoney' (a nil value) 1. unknown - gamemodes/darkrp/gamemode/modules/zombie cash/sv_zombiecash.lua:3[/CODE]
oh my god...This thread has SEVEN YEARS...Stop necrobumping
i need awnsers
Sorry, you need to Log In to post a reply to this thread.