Jump to content

EngineState doesn't change


ViRuZGamiing

Recommended Posts

Posted

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

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted
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 ) 

Omerta Roleplay

  • Moderators
Posted
  
-- 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 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

maybe you should debug it......

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

debuging doesn't mean you only have to watch the errors, you have to check how far the script goes and were it stops working. By using outputChatBox.

I am not going to test it,

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

Thx IIYAMA nice strategy to use outputChatbox to see where's the problem.

Script fixed!

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

  • Moderators
Posted

and what was the problem?

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

I didn't had any problems I've added the outputChatBox and everything worked (indeed weird)

So I changed it to an outputConsole... problem solved

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

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