developa Posted July 9, 2017 Share Posted July 9, 2017 (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 July 9, 2017 by developa Link to comment
kieran Posted July 9, 2017 Share Posted July 9, 2017 What are you saying? do you mean like setting on there HUD or using a command to give cash? 2 Link to comment
MaK$iM Posted July 10, 2017 Share Posted July 10, 2017 https://wiki.multitheftauto.com/wiki/ConvertNumber 1 Link to comment
developa Posted July 10, 2017 Author Share Posted July 10, 2017 1 hour ago, MaK$iM said: https://wiki.multitheftauto.com/wiki/ConvertNumber 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
koragg Posted July 10, 2017 Share Posted July 10, 2017 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
developa Posted July 10, 2017 Author Share Posted July 10, 2017 (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 July 10, 2017 by developa Link to comment
koragg Posted July 10, 2017 Share Posted July 10, 2017 Sorry but what exactly do you want to do ? Can you please post the full function/code so I can take a look at it as a whole, would be easier. Link to comment
developa Posted July 10, 2017 Author Share Posted July 10, 2017 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
koragg Posted July 10, 2017 Share Posted July 10, 2017 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. 1 Link to comment
developa Posted July 10, 2017 Author Share Posted July 10, 2017 (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 July 10, 2017 by developa 1 Link to comment
koragg Posted July 10, 2017 Share Posted July 10, 2017 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? Link to comment
Simple0x47 Posted July 10, 2017 Share Posted July 10, 2017 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
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