Jump to content

Cents


developa

Recommended Posts

Hello, I have something wrong with pennies. At about three million groschen bugs and jumps at twenty, instead of as much as I want, it means showing in turn: 30, 50, 80. Help!

Code: 

function takeMoney(player, price)
	if player and price then
		local cash = tonumber(getElementData(player, "player:money"))
		if cash >= tonumber(price) then
			setElementData(player, "player:money", tonumber(getElementData(player, "player:money") or 0)-price)
			return true
		else
			return false
		end
	end
end

function giveCash(player, price)
	if player and price then
		setElementData(player, "player:money", tonumber(getElementData(player, "player:money") or 0)+price)
	end
end

addEvent("giveCash", true)
addEventHandler("giveCash", root, function(value)
	if value then
		giveCash(source, value)
	end
end)

addEvent("takeCash", true)
addEventHandler("takeCash", root, function(price)
	if price then
		takeMoney(source, price)
	end
end)

 

Link to comment
18 minutes ago, developa said:

Hello, I have something wrong with pennies. At about three million groschen bugs and jumps at twenty, instead of as much as I want, it means showing in turn: 30, 50, 80. Help!

Code: 


function takeMoney(player, price)
	if player and price then
		local cash = tonumber(getElementData(player, "player:money"))
		if cash >= tonumber(price) then
			setElementData(player, "player:money", tonumber(getElementData(player, "player:money") or 0)-price)
			return true
		else
			return false
		end
	end
end

function giveCash(player, price)
	if player and price then
		setElementData(player, "player:money", tonumber(getElementData(player, "player:money") or 0)+price)
	end
end

addEvent("giveCash", true)
addEventHandler("giveCash", root, function(value)
	if value then
		giveCash(source, value)
	end
end)

addEvent("takeCash", true)
addEventHandler("takeCash", root, function(price)
	if price then
		takeMoney(source, price)
	end
end)

 

Try this :) btw seeing your code you might get an error 

function takeMoney(player, price)
  	local cash = getElementData(player, "player:money")
	if cash then
		cash = tonumber(cash)
		if cash >= tonumber(price) then
			setElementData(player, "player:money", cash-price)
			return true
		else
			return false
		end
    else
    	setElementData(player,"player:money",0)
    	return false
    end
end

function giveCash(player, price)
  	local cash = getElementData(player, "player:money")
	if cash then
    	setElementData(player, "player:money", cash+price)	
    	return true
    else
    	setElementData(player, "player:money", 0)
    	return false
    end
end

addEvent("giveCash", true)
addEventHandler("giveCash", root, function(value)
	if client and value then
		giveCash(client, value)
	end
end)

addEvent("takeCash", true)
addEventHandler("takeCash", root, function(price)
	if client and price then
		takeMoney(client, price)
	end
end)

 

Link to comment
4 hours ago, developa said:

Hello, I have something wrong with pennies. At about three million groschen bugs and jumps at twenty, instead of as much as I want, it means showing in turn: 30, 50, 80. Help!

Code: 


function takeMoney(player, price)
	if player and price then
		local cash = tonumber(getElementData(player, "player:money"))
		if cash >= tonumber(price) then
			setElementData(player, "player:money", tonumber(getElementData(player, "player:money") or 0)-price)
			return true
		else
			return false
		end
	end
end

function giveCash(player, price)
	if player and price then
		setElementData(player, "player:money", tonumber(getElementData(player, "player:money") or 0)+price)
	end
end

addEvent("giveCash", true)
addEventHandler("giveCash", root, function(value)
	if value then
		giveCash(source, value)
	end
end)

addEvent("takeCash", true)
addEventHandler("takeCash", root, function(price)
	if price then
		takeMoney(source, price)
	end
end)

 

If you want to show up cents then you should make a new money HUD which would show your "player:money" elementData's value.

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