itHyperoX Posted January 5, 2017 Share Posted January 5, 2017 function pay_function(player,cmd,playername,money) if not (playername) or not tonumber(money) or not type(tonumber(money)) == "number" then outputChatBox("[Help]: #ffffff/" .. cmd .. " [Name] [Amount]", player, 255, 0, 0, true) else local targetPlayer = exports.enExport:findPlayer(playername, player) if targetPlayer then if (targetPlayer==player) then outputChatBox("[Error]: #ffffffYou cant give money to yourself.", player, 255, 0, 0, true) elseif tonumber(money) <= 0 then outputChatBox("[Error]: #ffffff Bigger than 0", player, 255, 0, 0, true) elseif getPlayerMoney(player) >= tonumber(money) then givePlayerMoney(targetPlayer,tonumber(money)) takePlayerMoney(player,tonumber(money)) outputChatBox("[PAY]: #ffffffYou gaved $" .. tostring(money) .. " to " ..getPlayerName(targetPlayer).. "", player, 255, 0, 0, true) outputChatBox("[PAY]: #ffffff"..getPlayerName(player).." #ffffff gaved you $" .. tostring(money) .. "", targetPlayer, 255, 0, 0, true) else outputChatBox("[Error] #ffffffyou dont have enough money.", player, 177,9,45, true) end end end end addCommandHandler("pay",pay_function) The problem is in the picture: Problem The problem is, i already added to the script ' type(tonumber(money)) == "number" then ' but the script is accept the 0.01.1.4.545 amount. What is this? Link to comment
^iiEcoo'x_) Posted January 5, 2017 Share Posted January 5, 2017 function convertNumber ( number ) local formatted = number while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if ( k==0 ) then break end end return formatted end function pay_function(player,cmd,playername,money, cantidad) if not (playername) or not tonumber(money) or not type(tonumber(money)) == "number" then outputChatBox("[Help]: #ffffff/" .. cmd .. " [Name] [Amount]", player, 255, 0, 0, true) else local targetPlayer = exports.enExport:findPlayer(playername, player) if targetPlayer then if (targetPlayer==player) then outputChatBox("[Error]: #ffffffYou cant give money to yourself.", player, 255, 0, 0, true) elseif tonumber(cantidad) <= 0 then outputChatBox("[Error]: #ffffff Bigger than 0", player, 255, 0, 0, true) elseif getPlayerMoney(player) >= tonumber(cantidad) then givePlayerMoney(targetPlayer, tonumber(cantidad)) takePlayerMoney(player, tonumber(cantidad)) outputChatBox("[PAY]: #ffffffYou gaved $" tonumber(cantidad)" to " ..getPlayerName(targetPlayer).. "", player, 255, 0, 0, true) outputChatBox("[PAY]: #ffffff"..getPlayerName(player).." #ffffff gaved you $".. tonumber(cantidad).."", targetPlayer, 255, 0, 0, true) else outputChatBox("[Error] #ffffffyou dont have enough money.", player, 177,9,45, true) end end end end addCommandHandler("pay",pay_function) Link to comment
itHyperoX Posted January 5, 2017 Author Share Posted January 5, 2017 attempt to 'compare' nil with number Link to comment
^iiEcoo'x_) Posted January 5, 2017 Share Posted January 5, 2017 function convertNumber ( number ) local formatted = number while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if ( k==0 ) then break end end return formatted end function pay_function(player,cmd,playername,money, cantidad) outputChatBox("[Help]: #ffffff/" .. cmd .. " [Name] [Amount]", player, 255, 0, 0, true) else local targetPlayer = exports.enExport:findPlayer(playername, player) if targetPlayer then if (targetPlayer==player) then outputChatBox("[Error]: #ffffffYou cant give money to yourself.", player, 255, 0, 0, true) elseif tonumber(cantidad) <= 0 then outputChatBox("[Error]: #ffffff Bigger than 0", player, 255, 0, 0, true) elseif getPlayerMoney(player) >= tonumber(cantidad) then givePlayerMoney(targetPlayer, tonumber(cantidad)) takePlayerMoney(player, tonumber(cantidad)) outputChatBox("[PAY]: #ffffffYou gaved $" tonumber(cantidad)" to " ..getPlayerName(targetPlayer).. "", player, 255, 0, 0, true) outputChatBox("[PAY]: #ffffff"..getPlayerName(player).." #ffffff gaved you $".. tonumber(cantidad).."", targetPlayer, 255, 0, 0, true) else outputChatBox("[Error] #ffffffyou dont have enough money.", player, 177,9,45, true) end end end end addCommandHandler("pay",pay_function) Link to comment
itHyperoX Posted January 5, 2017 Author Share Posted January 5, 2017 i asked the problem, player,cmd,playername,money, ( cantidad ) what the ... is ????? Link to comment
^iiEcoo'x_) Posted January 5, 2017 Share Posted January 5, 2017 (edited) 50 minutes ago, #_iMr,[E]coo said: function convertNumber ( number ) local formatted = number while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if ( k==0 ) then break end end return formatted end function pay_function(player,cmd,playername,money, cantidad) outputChatBox("[Help]: #ffffff/" .. cmd .. " [Name] [Amount]", player, 255, 0, 0, true) else local targetPlayer = exports.enExport:findPlayer(playername, player) if targetPlayer then if (targetPlayer==player) then outputChatBox("[Error]: #ffffffYou cant give money to yourself.", player, 255, 0, 0, true) elseif tonumber(cantidad) <= 0 then outputChatBox("[Error]: #ffffff Bigger than 0", player, 255, 0, 0, true) elseif getPlayerMoney(player) >= tonumber(cantidad) then givePlayerMoney(targetPlayer, tonumber(cantidad)) takePlayerMoney(player, tonumber(cantidad)) outputChatBox("[PAY]: #ffffffYou gaved $"..convertNumber(cantidad).." to " ..getPlayerName(targetPlayer).. "", player, 255, 0, 0, true) outputChatBox("[PAY]: #ffffff"..getPlayerName(player).." #ffffff gaved you $"..convertNumber(cantidad), targetPlayer, 255, 0, 0, true) else outputChatBox("[Error] #ffffffyou dont have enough money.", player, 177,9,45, true) end end end end addCommandHandler("pay",pay_function) Edited January 5, 2017 by #_iMr,[E]coo Link to comment
itHyperoX Posted January 5, 2017 Author Share Posted January 5, 2017 I dont want convert the number dude. I WANT to block that player can'not give money if lower than 0. If you see the picture, you see that! I want to block like this: /pay XYZ 0.0.14844 ONLY number!! like: /pay XYZ 646446 Link to comment
myonlake Posted January 5, 2017 Share Posted January 5, 2017 7 minutes ago, TheMOG said: I dont want convert the number dude. I WANT to block that player can'not give money if lower than 0. If you see the picture, you see that! I want to block like this: /pay XYZ 0.0.14844 ONLY number!! like: /pay XYZ 646446 Just math.floor it, then. function pay_function(player,cmd,playername,money) money = tonumber(money) and math.floor(tonumber(money)) or nil if not (playername) or not (money) then outputChatBox("[Help]: #ffffff/" .. cmd .. " [Name] [Amount]", player, 255, 0, 0, true) else local targetPlayer = exports.enExport:findPlayer(playername, player) if targetPlayer then if (targetPlayer==player) then outputChatBox("[Error]: #ffffffYou cant give money to yourself.", player, 255, 0, 0, true) elseif money <= 0 then outputChatBox("[Error]: #ffffff Bigger than 0", player, 255, 0, 0, true) elseif getPlayerMoney(player) >= money then givePlayerMoney(targetPlayer,money) takePlayerMoney(player,money) outputChatBox("[PAY]: #ffffffYou gaved $" .. money .. " to " ..getPlayerName(targetPlayer).. "", player, 255, 0, 0, true) outputChatBox("[PAY]: #ffffff"..getPlayerName(player).." #ffffff gaved you $" .. money .. "", targetPlayer, 255, 0, 0, true) else outputChatBox("[Error] #ffffffyou dont have enough money.", player, 177,9,45, true) end end end end addCommandHandler("pay",pay_function) Link to comment
^iiEcoo'x_) Posted January 5, 2017 Share Posted January 5, 2017 @myonlake X X X X @TheMOG Use . if ( tonumber(Money) < 200 ) then return end Link to comment
itHyperoX Posted January 5, 2017 Author Share Posted January 5, 2017 @myonlake finally work. Thanks buddy. Link to comment
myonlake Posted January 5, 2017 Share Posted January 5, 2017 1 hour ago, TheMOG said: @myonlake finally work. Thanks buddy. You're welcome. 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