Jump to content

Money


Recommended Posts

Posted (edited)

Hello how to separate player cash? Does that mean that if a player holds a thousand dollars for example, instead of 1000, he writes 1 000 if he has 10000 and he writes 10 000 and so on?

Edited by developa
Posted
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.

Posted
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"))))

 

Posted (edited)

Unfortunately, this example does not work. Without this feature everything works, and as you add it will give you something else because every 20 cents.

Edited by developa
Posted

Sorry but what exactly do you want to do :D? Can you please post the full function/code so I can take a look at it as a whole, would be easier.

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

Posted

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
Posted (edited)

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
Posted

Maybe you don't update your element data when you earn more money? I don't know what could be the problem... how do you save the 'player:money' data?

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

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