ive been trying to figure out a way to make sure the player has enough money to buy the weapon so they dont end up getting it for cheaper then actually intended and eventually going into negative money
basicly what i need to do is
[CODE]if( ply:GetNWInt("money", 0) >= 15 ) then [/CODE]
Of course that doesnt work..thats why im here..to find a way to do it.
Thats..what i am doing lol
[lua] function givesmg(ply)
if( ply:GetNWInt("money", 0) >= 75 ) then
ply:Give("weapon_smg1")
ply:GiveAmmo( 75, "smg1" )
ply:ChatPrint("Congrats you have bought a Mp7 and 75 rounds for $75!")
ply:SetNWInt("money", ply:GetNWInt("money") - 75 )
else return false
end
end
concommand.Add("smgtakemoney", givesmg) [/lua]
It gives error attempted to compair number to string...because its retarded and considers ply:GetNWInt("money", 0) a string...
And how does it not work?
[QUOTE=Entoros;19637527]And how does it not work?[/QUOTE]
[quote] It gives error attempted to compair number to string...because its retarded and considers ply:GetNWInt("money", 0) a string...[/quote]
Ninja edit
[code]tonumber( ply:GetNWInt("money",0) )[/code]?
[QUOTE=DocDoomsday;19637500]It gives error attempted to compair number to string...because its retarded and considers ply:GetNWInt("money", 0) a string...[/QUOTE]
I know that's what you were doing, the snippet you posted normally works. You should always post errors and related code when asking for help, would make it a lot easier for us to figure out what is wrong.
Apparently GetNWInt sometimes returns a string instead of a number. Try ply:GetNetworkedInt("money", 0) instead, or tonumber(ply:GetNWInt("money", 0))
Now, I'm a noob in lua, but aren't anything in "s considered a string? Could you just do this?
[lua]
if( ply:GetNWInt(money, 0) >= 15 ) then
[/lua]
Rate dumbs if I'm...dumb.
No, unless the variable money contains the value "money".
[lua]function givesmg(ply)
if( ply:GetNWInt("money") >= 75 ) then
ply:Give("weapon_smg1")
ply:GiveAmmo( 75, "smg1" )
ply:ChatPrint("Congrats you have bought a Mp7 and 75 rounds for $75!")
ply:SetNWInt("money", ply:GetNWInt("money") - 75 )
end
end
concommand.Add("smgtakemoney", givesmg) [/lua]
?
Sorry, you need to Log In to post a reply to this thread.