Jump to content

pay issue


Recommended Posts

givePlayerMoney (person, math.abs(tonumber(amount)))

It workd before i did checks but i died like a million times when my friends and random people got on my server and killed me. So then i lost tons of money for hospital bills. So i had -$0011890 then someone pays me 5$ , I then have -$0011895 when i should of had -$0011885. Not sure how to prevent that.

So right now the code does not work and if it did it would allow people who are negative to keep going negative with they get paid positive.

function pay(Player, command, who, amount)
local person = getPlayerFromName ( who )
local playerMoney = getPlayerMoney (Player)
if ( playerMoney >= tonumber (amount)) and (tonumber (amount) > 0) then
         givePlayerMoney (person, math.abs(tonumber(amount)))
	  takePlayerMoney (Player, math.abs(tonumber(amount)))
         outputChatBox ( tostring (amount) .. "$ has been paid to " .. who, Player, 255, 0, 0, false)
       else
         outputChatBox ("You cannot pay more money than you have!", Player, 255, 0, 0, false)
   end
addCommandHandler ("pay", pay)

Also does MTA care about upper and lowercase on a Linux server?

Link to comment

There is the script.

function pay(Player, command, who, amount)
  local person = getPlayerFromName ( who )
  local playerMoney = getPlayerMoney (Player)
  if ( playerMoney >= tonumber (amount)) and (tonumber (amount) > 0) then
         givePlayerMoney (person, math.abs(tonumber(amount)))
       takePlayerMoney (Player, math.abs(tonumber(amount)))
         outputChatBox ( tostring (amount) .. "$ has been paid to " .. who, Player, 255, 0, 0, false)
       else
         outputChatBox ("You cannot pay more money than you have!", Player, 255, 0, 0, false)
   end
end
addCommandHandler ("pay", pay)

Link to comment

i think he emans that math.abs is unneded, what was the reason you puted it there?

btw heres fix:

function pay(Player, command, who, amount)
local person = getPlayerFromName ( who )
local playerMoney = getPlayerMoney (Player)
if ( playerMoney >= tonumber (amount)) and (tonumber (amount) > 0) then
if getPlayerMoney (Player) >= 0 then
givePlayerMoney (person, tonumber(amount))
else
takePlayerMoney (person, tonumber(amount))
end
takePlayerMoney (Player, tonumber(amount))
outputChatBox ( tostring (amount) .. "$ has been paid to " .. who, Player, 255, 0, 0, false)
else
outputChatBox ("You cannot pay more money than you have!", Player, 255, 0, 0, false)
end
end
addCommandHandler ("pay", pay)

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