Jump to content

[Help] Engine


D3vZ

Recommended Posts

Posted

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 :?

Posted

Well if you want it to turn off when he gets in you can make a timer for 100ms ( or w/e min is) to turn it off after he gets in or something. I mean, its not the best way, but if its not turning it off it may be that the event you are using is called before he is actually in the car.

Posted

Not so! The problem is that I want to leave the car with engine running and when another player get in engine still running

(Sorry My Bad English)

Posted

Oh you need to do this like. When a player does /engine check the element data of that vehicle element. If it is nil or off then set it to, on, and when you get it in it checks the element data and turns it on or off according to that. I am at school and dont really wanna write the code, but yeah, easy concept

Posted

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

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