Jump to content

Some help needed


Stylez

Recommended Posts

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) 

Link to post

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) 

Link to post
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 ) 

Link to post

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