maffius97 Posted January 20, 2015 Share Posted January 20, 2015 Hey, you know that bug when you drive a car and it ends of fuel, but you can press K to turn on engine, and continue drive on -1 fuel. How can I solve it? Here's the code: function onPlayerEnterDayzVehicle(veh,seat) local col = getElementData(veh,"parent") local id = getElementModel(veh) if not seat == 1 then return end local tires,engine,parts = getVehicleAddonInfos (id) setVehicleEngineState ( veh, false ) setElementData(veh,"maxfuel",getVehicleMaxFuel(col)) setElementData(veh,"needtires",tires) setElementData(veh,"needengines",engine) setElementData(veh,"needparts",parts) if ((getElementData(col,"Tire_inVehicle") or 0) < tonumber(tires)) then setVehicleEngineState ( veh, false ) return end if ((getElementData(col,"Engine_inVehicle") or 0) < tonumber(engine)) then setVehicleEngineState ( veh, false ) return end if not getElementData(col,"Parts_inVehicle") then setElementData(col,"Parts_inVehicle",math.random(0,parts)) end if (getElementData(col,"fuel") or 0) <= 1 then if not getElementModel(veh) == 509 then triggerClientEvent (source, "displayClientInfo", source,"Vehicle","No tank left in this vehicle!",22,255,0) setVehicleEngineState ( veh, false ) return end end setVehicleEngineState ( veh, true ) bindKey(source,"k","down",setEngineStateByPlayer) outputChatBox("Press 'K' to turn the engine on/off!",source) end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), onPlayerEnterDayzVehicle ) function onPlayerExitDayzVehicle(veh,seat) if seat == 0 then setVehicleEngineState ( veh, false ) unbindKey(source,"k","down",setEngineStateByPlayer) end end addEventHandler ( "onPlayerVehicleExit", getRootElement(), onPlayerExitDayzVehicle ) Link to comment
TAPL Posted January 21, 2015 Share Posted January 21, 2015 Show the function setEngineStateByPlayer. Link to comment
maffius97 Posted January 21, 2015 Author Share Posted January 21, 2015 function setEngineStateByPlayer (playersource) local veh = getPedOccupiedVehicle (playersource) if (getPedOccupiedVehicleSeat (playersource) == 0) then setVehicleEngineState (veh, not getVehicleEngineState(veh)) if getElementData(getElementData(veh,"parent"),"fuel") <1 then return end if getVehicleEngineState(veh) == true then triggerClientEvent (playersource, "displayClientInfo", playersource,"Vehicle","Engine started!",22,255,0) else triggerClientEvent (playersource, "displayClientInfo", playersource,"Vehicle","Engine stopped!",255,22,0) end end end Link to comment
TAPL Posted January 21, 2015 Share Posted January 21, 2015 Try. function setEngineStateByPlayer (playersource) local veh = getPedOccupiedVehicle (playersource) if (getPedOccupiedVehicleSeat (playersource) == 0) then if getElementData(getElementData(veh,"parent"),"fuel") <1 then return end setVehicleEngineState (veh, not getVehicleEngineState(veh)) if getVehicleEngineState(veh) == true then triggerClientEvent (playersource, "displayClientInfo", playersource,"Vehicle","Engine started!",22,255,0) else triggerClientEvent (playersource, "displayClientInfo", playersource,"Vehicle","Engine stopped!",255,22,0) end end end Link to comment
maffius97 Posted January 21, 2015 Author Share Posted January 21, 2015 Works, but now when I leave car and get in again I can still drive for a while Link to comment
maffius97 Posted January 21, 2015 Author Share Posted January 21, 2015 15-20 seconds function setVehiclesFuelPerMinute () for i,veh in ipairs(getElementsByType("vehicle")) do if getVehicleEngineState(veh) == true then if getElementData(getElementData(veh,"parent"),"fuel") >= 0 then setElementData(getElementData(veh,"parent"),"fuel",getElementData(getElementData(veh,"parent"),"fuel")-getVehicleFuelRemove(getElementModel(veh),getElementData(veh,"parent"))) else setVehicleEngineState ( veh, false ) end end end end setTimer(setVehiclesFuelPerMinute,20000,0) function isVehicleReadyToStart2 (veh) if getElementData(getElementData(veh,"parent"),"fuel") >= 1 then local tires,engine,parts = getVehicleAddonInfos (getElementModel(veh)) if (getElementData(getElementData(veh,"parent"),"Tire_inVehicle") or 0) > tonumber(tires) and (getElementData(getElementData(veh,"parent"),"Engine_inVehicle") or 0) > tonumber(engine) then setVehicleEngineState ( veh, true ) end end setTimer(isVehicleReadyToStart2,1000,1,veh) end Link to comment
TAPL Posted January 21, 2015 Share Posted January 21, 2015 Was it possible to drive 15-20 sec before the K toggle code change? Link to comment
maffius97 Posted January 21, 2015 Author Share Posted January 21, 2015 Yes. I changed time in function setVehiclesFuelPerMinute setTimer from 20000 to 1000 and then I can drive just one second, so here's the problem. Link to comment
TAPL Posted January 21, 2015 Share Posted January 21, 2015 Hey, you know that bug when you drive a car and it ends of fuel, but you can press K to turn on engine, and continue drive on -1 fuel. How can I solve it? Here's the code: function onPlayerEnterDayzVehicle(veh,seat) local col = getElementData(veh,"parent") local id = getElementModel(veh) if not seat == 1 then return end local tires,engine,parts = getVehicleAddonInfos (id) setVehicleEngineState ( veh, false ) setElementData(veh,"maxfuel",getVehicleMaxFuel(col)) setElementData(veh,"needtires",tires) setElementData(veh,"needengines",engine) setElementData(veh,"needparts",parts) if ((getElementData(col,"Tire_inVehicle") or 0) < tonumber(tires)) then setVehicleEngineState ( veh, false ) return end if ((getElementData(col,"Engine_inVehicle") or 0) < tonumber(engine)) then setVehicleEngineState ( veh, false ) return end if not getElementData(col,"Parts_inVehicle") then setElementData(col,"Parts_inVehicle",math.random(0,parts)) end if (getElementData(col,"fuel") or 0) <= 1 then if not getElementModel(veh) == 509 then triggerClientEvent (source, "displayClientInfo", source,"Vehicle","No tank left in this vehicle!",22,255,0) setVehicleEngineState ( veh, false ) return end end setVehicleEngineState ( veh, true ) bindKey(source,"k","down",setEngineStateByPlayer) outputChatBox("Press 'K' to turn the engine on/off!",source) end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), onPlayerEnterDayzVehicle ) function onPlayerExitDayzVehicle(veh,seat) if seat == 0 then setVehicleEngineState ( veh, false ) unbindKey(source,"k","down",setEngineStateByPlayer) end end addEventHandler ( "onPlayerVehicleExit", getRootElement(), onPlayerExitDayzVehicle ) Line 4 the driver seat is 0 not 1. Link to comment
maffius97 Posted January 24, 2015 Author Share Posted January 24, 2015 I just solved my problem. Thanks for help. 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