Jump to content

Vehicle Engine state.


NextGenRP

Recommended Posts

Turn off the engine when a player enter the vehicle: setVehicleEngineState combined with the event: onVehicleEnter.
setVehicleEngineState 

On wiki already have example with this function.

function turnEngineOff ( theVehicle, leftSeat, jackerPlayer ) 
    -- if it's the driver who got out, and he was not jacked, 
    if leftSeat == 0 and not jackerPlayer then 
        -- turn off the engine 
        setVehicleEngineState ( theVehicle, false ) 
    end 
end 
-- add 'turnEngineOff' as a handler for "onPlayerExitVehicle" 
addEventHandler ( "onPlayerVehicleExit", getRootElement ( ), turnEngineOff ) 

Just change to 'onPlayerVehicleEnter'

Edited by Guest
Link to comment

Yeah i have made it like this;

  
  
for k, i in ipairs(getElementsByType("vehicle")) do  
setVehicleEngineState(i,false) 
setVehicleLocked(i,true) 
end 
  
  

But when the player gets in the vehicle it just turns back on.

  
  
function enter(player,seat) 
if seat == 0 then 
local eniginestate = getVehicleEngineState(source) 
if eniginestate == false then 
outputChatBox("Press J to start the "..getVehicleName(source).."'s engine.",player,255,255,0) 
end 
end 
end 
addEventHandler("onVehicleEnter", getRootElement(), enter) 
  
  

It will output to the chat but then the engine just comes on.

Link to comment

Changed it to this;

  
function enter(player,seat) 
if seat == 0 then 
local eniginestate = getVehicleEngineState(source) 
if eniginestate == false then 
setVehicleEngineState(source,false) 
outputChatBox("Press J to start the "..getVehicleName(source).."'s engine.",player,255,255,0) 
end 
end 
end 
addEventHandler("onVehicleEnter", getRootElement(), enter) 
  

Now it doesn't output and the engine still starts :P

Link to comment
function enter ( player, seat ) 
    if ( seat == 0 ) then 
        setVehicleEngineState ( source, false ) 
        local eniginestate = getVehicleEngineState ( source ) 
        if ( eniginestate == false ) then 
            outputChatBox ( "Press J to start the ".. getVehicleName ( source ) .."'s engine.", player, 255, 255, 0 ) 
        end 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enter ) 

Link to comment

Tested

function setVehicleEngineOff ( pVehicle, nLeftSeat, pJackerPlayer ) 
    if nLeftSeat == 0 and not pJackerPlayer then 
        -- turn off the engine 
         outputChatBox ( "Press J to start the ".. getVehicleName ( pVehicle ) .."'s engine.", source, 255, 255, 0 ) 
        setVehicleEngineState ( pVehicle, false ) 
    end 
end 
addEventHandler ( 'onPlayerVehicleEnter', root, setVehicleEngineOff ) 

Link to comment

Thanks guys i managed to get it working, I have another problem though im trying to create a /handbrake and im using setVehicleFrozen but if i bind it and jump off something then press the key it will freeze my vehicle in mid air, Is there anything else i can use other than setVehicleFrozen?

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