Stylez Posted August 16, 2013 Share Posted August 16, 2013 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 comment
Castillo Posted August 16, 2013 Share Posted August 16, 2013 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 Link to comment
Stylez Posted August 16, 2013 Author Share Posted August 16, 2013 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 comment
Castillo Posted August 16, 2013 Share Posted August 16, 2013 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 comment
Stylez Posted August 16, 2013 Author Share Posted August 16, 2013 No, you see carsTable = { [415] = 100, [413] = 50 } the 100 and 50 are prices for cars.. Link to comment
Castillo Posted August 16, 2013 Share Posted August 16, 2013 So? my script will check if the vehicle is on the table, if so, then it'll check if you have enough money. Link to comment
Stylez Posted August 16, 2013 Author Share Posted August 16, 2013 oh, i jumped over few lines when i was looking at script, thanks 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