Jump to content

[Help] Engine


D3vZ

Recommended Posts

The problem of my script is that: when I leave car with the engine running, to get into the car it shuts it down, and I want to get in the car he let it run!

How i do that?

Script:

local root = getRootElement () 
local thisResourceRoot = getResourceRootElement(getThisResource()) 
  
function thisResourceStart () 
    local players = getElementsByType ( "player" ) 
    for _,this_player in ipairs(players) do 
        bindKey ( this_player, "lctrl", "down", stopEngine, "Motor on/off" ) 
    end 
end 
  
function stopEngine ( player, key, state ) 
    if getPedOccupiedVehicleSeat ( player ) == 0 then 
        local vehicle = getPedOccupiedVehicle ( player ) 
        setVehicleEngineState ( vehicle, not getVehicleEngineState ( vehicle ) ) 
    end 
end 
  
function playerJoined() 
    bindKey ( source, "lctrl", "down", stopEngine, "Motor on/off" ) 
end 
addEventHandler ("onResourceStart", getRootElement(), thisResourceStart) 
  
addEventHandler ( "onVehicleEnter", root, 
    function ( player ) 
        setVehicleEngineState ( source, getElementData ( source, "Motor on/off" ) ) 
    end 
) 
  
 addEventHandler ( "onVehicleExit", stopEngine, 
    function ( player ) 
        setVehicleEngineState ( source, getElementData ( source, "Motor on/off" ) ) 
    end 
) 

Sorry my bad english :?

Link to comment

This is the concept, the code is probally not written right, but you would put this where the neter and exit stuff is at, and do it server side.

enter code

  
if(getElementData(vehicle,"onOrOff")0then 
setVehicleEngineState(vehicle,true) 
else 
setVehicleEngineState(vehicle,false) 
end 
  

exit code

  
setElementData(vehicle,"onOrOff", getVehicleEngineState(vehicle)) 
  

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