Jump to content

Money


Recommended Posts

1 hour ago, MaK$iM said:

Thanks, it works but I have a problem.
I have a heel system for the element-date with pennies, and they are badly changed. Now I have this code:

convertNumber(string.format("%.02f$", getElementData(localPlayer, "player:money")))

 and pennies change every 20 cents, whatever I type for example 10 cents and not add it, only change every 30, 50, 80 cents. I tried this:

string.format("%.02f$", convertNumber(getElementData(localPlayer, "player:money")))

 but it does not work (there is an error in debugscript3 - bad argument # 2 is 'format' (number expected, got string)). Help.

Link to comment
string convertNumber( int/string number )

The function wants a number and you're giving it a string by using the 'string.format' thing. And about the second attempt are you sure that the "player:money" data is saved as a number and not a string? You can try this and see if it's ok:

string.format("%.02f$", convertNumber(tonumber(getElementData(localPlayer, "player:money"))))

 

Link to comment
sW,sH = guiGetScreenSize()

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

addEventHandler("onClientRender", root, function()
    local money = string.format("%.02f$", convertNumber(tonumber(getElementData(localPlayer, "player:money"))))
   	dxDrawText(money, sW*0.8045, sH*0.0840, sW*0.9832, sH*0.1589, tocolor(255,255, 255, 255), 1, "default-bold", "right", "center", false, false, false, true, false)
end)

He wants to display the money with a space, depending on how much he holds. Everything works fine, except for pennies, because they change every 20 minutes ie 30,50,80 and so in a wheel like I add 10 cents for example, I have to type it three times, otherwise it will not appear. I suppose this function is pissing me off because it's contained in string.gsub.

Link to comment

Wait a second. Did you save both dollars and pennies in the same element data (player:money)? Put this below your code:

function test()
	local money = getElementData(localPlayer, "player:money")
	outputChatBox(money)
end
addCommandHandler("testcash", test)

Restart the script and type '/testcash' in your server's chatbox. Tell me what shows up after that in the chat.

  • Like 1
Link to comment

Displayed: 3815818.3
If I add the function string.format there will appear 3815818.30.
Everything works, and if you add this feature it will cracks up.

If I add 5 cents to my cash it will be 3815818.35, and in the hud with this function will appear 3815818.30 ;/

Edited by developa
  • Like 1
Link to comment
47 minutes ago, developa said:

Displayed: 3815818.3
If I add the function string.format there will appear 3815818.30.
Everything works, and if you add this feature it will cracks up.

If I add 5 cents to my cash it will be 3815818.35, and in the hud with this function will appear 3815818.30 ;/

Like Koragg said the player:money elementData is not being updated so expect the initial 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...