Jump to content

Some help needed


Stylez

Recommended Posts

Posted

Hey guys, can someone help me with this. I need to check if entered carID matches the carID in the carsTable. when i type /v buy its says bad car id...

carsTable = { [415] = 100, [413] = 50 } 
 carShopMarker = createMarker( -2424.12036, -609.69904, 131.62, "cylinder", 1.8, 130, 180, 0, 50 ) 
    
function buyCar(thePlayer, cmd, cmdType, carID) 
    if isElementWithinMarker(thePlayer, carShopMarker) and cmdType == "buy" then 
        for i,v in pairs(carsTable) do 
            if carID == i then 
                --local playerMoney = getPlayerMoney(thePlayer) 
                --if playerMoney <= v then 
                  outputChatBox("good  car id") 
                --end 
           else 
                  outputChatBox("bad car id") 
           end 
       end 
    end 
 end 
 addCommandHandler("v", buyCar) 

Posted

That's because "carID" returns a string, you must convert it to number using tonumber.

Also, what's the point of the loop? you can just do:

if ( carsTable [ tonumber ( carID ) ] ) then 
end 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

but look, now.. i tried to make it if player has enough money to be able to buy a car.. now error says line 9 attempt to compare nil with number. cant understand...

carsTable = { [415] = 100, [413] = 50 } 
carShopMarker = createMarker( -2424.12036, -609.69904, 131.62, "cylinder", 1.8, 130, 180, 0, 50 ) 
  
function buyCar(thePlayer, cmd, cmdType, carID) 
    if isElementWithinMarker(thePlayer, carShopMarker) and cmdType == "buy" then 
        if (carsTable[tonumber(carID)]) then 
            for i,v in pairs(carsTable) do 
                local playerMoney = getPlayerMoney(thePlayer) 
                if playerMoney > carsTable[v] then 
                    outputChatBox("nigga got a car") 
                else 
                    outputChatBox("bbz, arba ner pinige") 
                end 
            end 
        else 
            outputChatBox("Neteisingas Masinos ID", thePlayer) 
        end 
    end 
end 
addCommandHandler("v", buyCar) 

Posted
carsTable = { [415] = 100, [413] = 50 } 
carShopMarker = createMarker( -2424.12036, -609.69904, 131.62, "cylinder", 1.8, 130, 180, 0, 50 ) 
  
function buyCar ( thePlayer, cmd, cmdType, carID ) 
    if isElementWithinMarker ( thePlayer, carShopMarker ) and cmdType == "buy" then 
        local price = carsTable [ tonumber ( carID ) ] 
        if ( price ) then 
            local playerMoney = getPlayerMoney ( thePlayer ) 
            if ( playerMoney >= price ) then 
                outputChatBox ( ":O got a car" ) 
            else 
                outputChatBox ( "bbz, arba ner pinige" ) 
            end 
        else 
            outputChatBox ( "Neteisingas Masinos ID", thePlayer ) 
        end 
    end 
end 
addCommandHandler ( "v", buyCar ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

So? my script will check if the vehicle is on the table, if so, then it'll check if you have enough money.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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