xXMADEXx Posted March 28, 2013 Share Posted March 28, 2013 Im trying to make my fuel system, but i get an error. I dont know how to fix it, here is my code to set the vehicle fuel: (server) setTimer( function () for i,v in ipairs (getElementsByType("vehicle")) do if (getElementData(v,"fuel")=="") then -- I have also tried: if (getElementData(v,"fuel")==nil) then setElementData(v,"fuel",'50',true) outputChatBox(v) end end end, 500, 0 ) And, here is my code to get the fuel. local fuel = getElementData(getPedOccupiedVehicle(localPlayer),"fuel") dxDrawBorderedText("Fuel: "..fuel.."%", screenWidth*0.750, screenHeight*0.9, screenWidth, screenHeight, tocolor(255, 255, 255), scale, "arial", "left", "center") and the error: attempt to concatenate local "fuel" (a boolean value) Link to comment
Dev Posted March 28, 2013 Share Posted March 28, 2013 Why are you storing fuel as a string? store it as an integer, and then use the 'tostring' to output it in your directX drawing. setTimer( function( ) for i, v in ipairs ( getElementsByType("vehicle") ) do if ( tonumber( getElementData(v, "fuel") ) == 0 ) then setElementData( v, "fuel", 50, true) -- outputChatBox( v ) 'v' is a vehicle element, you can't output it to chatbox.. end end end, 500, 0 ) local fuel = getElementData( getPedOccupiedVehicle(localPlayer), "fuel" ) dxDrawBorderedText("Fuel: ".. tostring( fuel ) .."%", screenWidth*0.750, screenHeight*0.9, screenWidth, screenHeight, tocolor(255, 255, 255), scale, "arial", "left", "center") Link to comment
Renkon Posted March 28, 2013 Share Posted March 28, 2013 if not getElementData(v, "fuel") then .... if that's what you want to fix Link to comment
xXMADEXx Posted March 28, 2013 Author Share Posted March 28, 2013 Thanks for that, but there is a new issue. For some reason, when the engine dies, it just turns back on setTimer( function () for i,v in ipairs (getElementsByType("vehicle")) do if (tonumber(getElementData(v,"fuel"))==1) and (getVehicleEngineState(v)==true) then setVehicleEngineState(v,false) elseif (tonumber(getElementData(v,"fuel")) > 0) and (getVehicleEngineState(v)==false) then setVehicleEngineState(v,true) end end end, 1000, 0 ) Link to comment
K4stic Posted March 28, 2013 Share Posted March 28, 2013 setTimer( function () for i,v in ipairs (getElementsByType("vehicle")) do if (tonumber(getElementData(v,"fuel")) <=1) and (getVehicleEngineState(v)==true) then setVehicleEngineState(v,false) elseif (tonumber(getElementData(v,"fuel")) >= 0) and (getVehicleEngineState(v)==false) then setVehicleEngineState(v,true) end end end, 1000, 0 ) try this 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