Jump to content

/pay command help


CourtezBoi

Recommended Posts

Posted

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?

Sup

Posted

amount = tonumber(amount) -- convert amount to number
givePlayerMoney(toWho,amount)
takePlayerMoney(source,amount)

and

outputChatBox(name .. " has given you $" .. amount .. "!",toWho,255,255,245)

MTASA.LV - Latvian MTA Community

Posted (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 by Guest

MTASA.LV - Latvian MTA Community

Posted

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 :S

Sup

Posted

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".

MTASA.LV - Latvian MTA Community

Posted

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!"

Posted

I suggest to use search feature before posting new topic.

https://forum.multitheftauto.com/viewtop ... nd#p303758

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...