Jump to content

EngineState doesn't change


ViRuZGamiing

Recommended Posts

Hi,

root = getRootElement() 
  
function SwitchEngine( source ) 
    local theVehicle = getPedOccupiedVehicle ( source ) 
    if theVehicle and getVehicleController ( theVehicle ) == source then 
        local state = getVehicleEngineState ( theVehicle ) 
        setVehicleEngineState ( theVehicle, not state ) 
    end 
end 
  
function BindKeys ( source ) 
    if ( eventName == "onVehicleStartEnter" ) then 
        bindKey ( source,"x","down",SwitchEngine ) 
    else 
        unbindKey ( source,"x","down",SwitchEngine ) 
    end 
end 
  
addEventHandler ( "onVehicleStartEnter", root, BindKeys ) 
addEventHandler ( "onVehicleStartExit", root, BindKeys ) 

No errors only on bindKey "x" the car engine doesn't turn on/off

Link to comment
root = getRootElement() 
  
function SwitchEngine( source ) 
    local theVehicle = getPedOccupiedVehicle ( source ) 
    if theVehicle and getVehicleController ( theVehicle ) == source then 
        local state = getVehicleEngineState ( theVehicle ) 
        setVehicleEngineState ( theVehicle, not state ) 
    end 
end 
  
function BindKeys ( source ) 
    if ( eventName == "onVehicleStartEnter" ) then 
        bindKey ( source,"x","down",SwitchEngine ) 
    else 
        unbindKey ( source,"x","down",SwitchEngine ) 
    end 
end 
  
addEventHandler ( "onPlayerVehicleEnter", root, BindKeys ) 
addEventHandler ( "onPlayerVehicleExit", root, BindKeys ) 

Link to comment
  • Moderators
  
-- root = getRootElement() --  don't redefine something that is already defined. 
  
local SwitchEngine 
SwitchEngine = function ( source ) 
    local theVehicle = getPedOccupiedVehicle ( source ) 
    if theVehicle and getVehicleController ( theVehicle ) == source then 
        local state = getVehicleEngineState ( theVehicle ) 
        setVehicleEngineState ( theVehicle, not state ) 
    else 
         unbindKey ( source,"x","down",SwitchEngine ) 
    end 
end 
  
  
  
  
local BindKeyEnter = function (vehicle) 
        bindKey ( source,"x","down",SwitchEngine ) 
end 
  
local BindKeyExit = function (vehicle) 
        unbindKey ( source,"x","down",SwitchEngine ) 
end 
  
addEventHandler ( "onVehicleEnter", root, BindKeyEnter ) -- not onVehicleStartEnter 
addEventHandler ( "onVehicleExit", root, BindKeyExit ) -- not onVehicleStartExit 

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