Jump to content

DayZ End of fuel and still driving


maffius97

Recommended Posts

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
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
  • Other Languages Moderators

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

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
  • Other Languages Moderators
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

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