• Money System
    4 replies, posted
Alright, i've been trying to create a very small script to add a money system into sandbox using networked integer's, everything is working fine except the add money on npc death thing. Here my code: [LUA] function NPCkilled ( victim, killer, ply ) ply:GetNWInt( "money" ) if money == nil then ply:SetNWInt( "money", 0 ) ply:SetNWInt( "money", "money" + 10 ) else ply:SetNWInt( "money", "money" + 10 ) end end function Checkmoney( ply ) ply:GetNWInt( "money" ) if money == nil then print( "You got no cash noob" ) else print( money ) end end concommand.Add( "Check_money", Checkmoney ) hook.Add ("OnNPCKilled", "Hai", NPCkilled) [/LUA] Now, if i try this code it says it can't perform arithmetic on string values. If i delete the quote to make it non-string, the NWint commands wont work because it expected strings. I just dont see any options here. Anyone knows how to do this either another way, or how im supposed to do it with NWints
The arguments to OnNPCKilled are NPC, killer [b]Weapon[/b], you are using the last argument as ply, where you should be using the second (killer). [editline]08:05AM[/editline] [b][url=wiki.garrysmod.com/?title=Gamemode.OnNPCKilled]Gamemode.OnNPCKilled [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[lua] hook.Add("OnNPCKilled", "MoneyUp", function(npc,killer,wep) if not( killer:IsPlayer() ) then return end; local mon = killer:GetNWInt("money", 0) killer:SetNWInt("money", mon+10) end) concommand.Add("CheckMoney", function(p) if( p:GetNWInt("money", 0) == 0 ) then p:PrintMessage(3, "You have no money, Nubcaek"); else p:PrintMessage(3, "Money: $"..p:GetNWInt("money", 0)) end end) [/lua]
[url=http://entoros.pastebin.com/f2e88e84a]Here's a money system[/url] I made a while back as an example that you can use as a reference. It includes giving and retrieving money from the player and a SQL database.
ply:SetNWInt( "money", "money" + 10 ) to ply:SetNWInt("money", ply:GetNWInt("money") + 10 ) Just got done with a gamemode that uses money alot :P
Sorry, you need to Log In to post a reply to this thread.