Jump to content

convertNumber.


MajdMTA

Recommended Posts

Posted

Hello.. Some for this stupid thing, I tried to convert gridList number, Example my one is 5000 I wanna it 5,000, can someone gimme a function? and I'll put it.

Posted
you mean you want to convert any number that has 3 digits or more?

In my vehicle script grid list the price for Faggio-car is 5000 I wanna it 5,000

Posted

You have the simplest example on the website:

function convertPlayerMoney() 
    local pMoney = getPlayerMoney() --get the players money 
    local convertedMoney = convertNumber(pMoney) --converts it and saves it in variable 
    outputChatBox(convertedMoney) --outputs it 
end 
addCommandHandler("money", convertPlayerMoney) 

You would just have to change the local pMoney to get the value of the vehicle, and that would be it, but if you need more help you can post the code,

Posted
Post code and i will try to help you

"Try" words didn't work with me.

He is gonna try to help you, he doesnt have an obligation to do it, so if "try" doesnt work for you then hire a scripter

Posted
     local carCost = guiGridListGetItemText (carGrid, guiGridListGetSelectedItem(carGrid), 2) 
            local convertedMoney = convertNumber(carCost) 
            local carprice = guiGridListGetItemText(carGrid, guiGridListGetSelectedItem(carGrid), 2) 
            local convertedMoney = convertNumber(carprice) 
  
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 

So tell me where's the bug?

Posted (edited)
     local carCost = guiGridListGetItemText (carGrid, guiGridListGetSelectedItem(carGrid), 2) 
            local convertedMoney = convertNumber(carCost) 
            local carprice = guiGridListGetItemText(carGrid, guiGridListGetSelectedItem(carGrid), 2) 
            local convertedMoney = convertNumber(carprice) 
  
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 

So tell me where's the bug?

You made the prices in table then loop it ?

Edited by Guest
Posted
     local carCost = guiGridListGetItemText (carGrid, guiGridListGetSelectedItem(carGrid), 2) 
            local convertedMoney = convertNumber(carCost) 
            local carprice = guiGridListGetItemText(carGrid, guiGridListGetSelectedItem(carGrid), 2) 
            local convertedMoney = convertNumber(carprice) 
  
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 

So tell me where's the bug?

That has to throw an error since you're trying to call function 'convertNumber' that is nil. It is nil because it wasn't defined yet until few lines later. You have to put the function definition outside of this function (I assume it is a function called by some event handler).

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