Jump to content

Need a little help


itHyperoX

Recommended Posts

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
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
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
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 by #_iMr,[E]coo
Link to comment
7 minutes ago, TheMOG said:

I dont want convert the number dude. :D 

 

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

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