D3vZ Posted February 11, 2014 Share Posted February 11, 2014 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
Damien_Teh_Demon Posted February 11, 2014 Share Posted February 11, 2014 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. Link to comment
D3vZ Posted February 11, 2014 Author Share Posted February 11, 2014 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) Link to comment
Damien_Teh_Demon Posted February 11, 2014 Share Posted February 11, 2014 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 Link to comment
D3vZ Posted February 11, 2014 Author Share Posted February 11, 2014 Sorry Damien, but i don't understand Link to comment
Damien_Teh_Demon Posted February 11, 2014 Share Posted February 11, 2014 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
D3vZ Posted February 11, 2014 Author Share Posted February 11, 2014 I tested it, but not func. Link to comment
Damien_Teh_Demon Posted February 11, 2014 Share Posted February 11, 2014 Its not the compelte code, you need to fill out the rest, i was just showing you some things you would need todo.. Whats the error you got? Link to comment
D3vZ Posted February 12, 2014 Author Share Posted February 12, 2014 Script fixed! Thanks! Close topic please! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now