Jump to content

/pay command help


CourtezBoi

Recommended Posts

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

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
Link to comment

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

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