CourtezBoi Posted August 11, 2010 Share Posted August 11, 2010 Alright so I tried to create a command to be able to transfer money from one player to the next. I got the following error: [14:38:19] WARNING: bank\bank.lua:586: Bad argument @ 'givePlayerMoney' [14:38:19] ERROR: bank\bank.lua:590: attempt to concatenate local 'source' (a userdata value) Heres a copy of the code. function pay(source , cmd, thePlayer, amount) toWho = getPlayerFromName ( thePlayer) local cash = getPlayerMoney( source ) if cmd == "pay" then if (tonumber(amount)>0) then givePlayerMoney(toWho,amount) takePlayerMoney(source,amount) name = getPlayerName(source) outputChatBox("You've given " .. thePlayer .. " $" .. amount .. "." ,source,255,255,150) outputChatBox(source .. " has given you $" .. amount .. "!",toWho,255,255,245) else outputChatBox("[usage] /pay [iD] [amount]", source) end else outputChatBox("Amount have to be greater than 0!",source,255,0,0) end end addCommandHandler("pay", pay); Any ideas as to how I can fix this? Link to comment
The_Ex Posted August 11, 2010 Share Posted August 11, 2010 amount = tonumber(amount) -- convert amount to number givePlayerMoney(toWho,amount) takePlayerMoney(source,amount) and outputChatBox(name .. " has given you $" .. amount .. "!",toWho,255,255,245) Link to comment
CourtezBoi Posted August 11, 2010 Author Share Posted August 11, 2010 I got the error [14:49:09] WARNING: bank\bank.lua:587: Bad argument @ 'givePlayerMoney' Link to comment
The_Ex Posted August 11, 2010 Share Posted August 11, 2010 (edited) You really should spend some time to learn Lua scripting... You have too much mistakes and unused code. function pay(source , cmd, thePlayer, amount) toWho = getPlayerFromName ( thePlayer ) if toWho then amount = tonumber(amount) or 0 if amount > 0 and getPlayerMoney(source) >= amount then givePlayerMoney(toWho,amount) takePlayerMoney(source,amount) outputChatBox("You've given " ..thePlayer .. " $" .. amount .. "." ,source,255,255,150) outputChatBox(getPlayerName(source) .. " has given you $" .. amount .. "!",toWho,255,255,245) else outputChatBox("Amount have to be greater than 0 or you don't have that much cash!",source,255,0,0) end else outputChatBox( "There is no such player online!", source ) end end addCommandHandler("pay", pay) This should work but you have to try to understand the code. Edited August 11, 2010 by Guest Link to comment
illone Posted August 11, 2010 Share Posted August 11, 2010 error no such player online - Link to comment
CourtezBoi Posted August 11, 2010 Author Share Posted August 11, 2010 Thats what I'm trying to do, but I really couldn't figure out the error with this. The code you gave doesn't seem to work, it just always says player not found Link to comment
LonelyRoad Posted August 11, 2010 Share Posted August 11, 2010 Slightly irrelevant but it's a pointless check on line 4 (In the original post) since the only command handler you have is pay. Link to comment
The_Ex Posted August 11, 2010 Share Posted August 11, 2010 Ok, i tested the code i wrote and it IS working, probably you're just typing it like /pay amount playername not /pay playername amount. But i had one mistake, which wasn't related to outputting "there is not such player". Link to comment
illone Posted August 11, 2010 Share Posted August 11, 2010 Issue is, that it removes the money from you but the receiver doesn't get the money. Using /pay [amount] [user] /pay [user] [amount] just takes 2 bucks off "sometimes" and the receiver still doesn't receive it. update - I get also a "Amount have to be greater than 0 or you don't have that much cash!" Link to comment
dzek (varez) Posted August 12, 2010 Share Posted August 12, 2010 I suggest to use search feature before posting new topic. https://forum.multitheftauto.com/viewtop ... nd#p303758 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now