Tails Posted November 23, 2015 Share Posted November 23, 2015 (edited) Hello everybody, I'm working on a script that lets you control the state of the engine. Is there any way to get a vehicle's initial engine state? For example, I need to know whether the engine of the vehicle you're entering is on or off. So when the engine is off and you're entering it, the engine should stay off and vice versa. I can easily manage this but it won't work as soon as I enter another vehicle. So if we had some sort of function to detect a vehicle's initial engine state then that would solve the problem. Any help is much appreciated, Tails Edited December 27, 2015 by Guest Link to comment
Captain Cody Posted November 23, 2015 Share Posted November 23, 2015 https://wiki.multitheftauto.com/wiki/Ge ... ngineState Link to comment
Tails Posted November 23, 2015 Author Share Posted November 23, 2015 That's not getting the initial state. When a player gets in a vehicle it turns on the engine by itself so it's always going to be true. I could set the engine state to false through onPlayerVehicleEnter but that's not what I'm looking for. Because with my code, I can choose to leave the engine on when I exit a vehicle. But when I choose to leave the engine off and exit en re-enter the vehicle it'll turn the engine back on. So to be more clear: When I leave the engine off and exit, when I enter again and use getVehicleEngineState then it will return true because the engine turns back on by it self. I hope you understand what I mean. Link to comment
jingzhi Posted December 2, 2015 Share Posted December 2, 2015 That's not getting the initial state. When a player gets in a vehicle it turns on the engine by itself so it's always going to be true.I could set the engine state to false through onPlayerVehicleEnter but that's not what I'm looking for. Because with my code, I can choose to leave the engine on when I exit a vehicle. But when I choose to leave the engine off and exit en re-enter the vehicle it'll turn the engine back on. So to be more clear: When I leave the engine off and exit, when I enter again and use getVehicleEngineState then it will return true because the engine turns back on by it self. I hope you understand what I mean. I remember there is an event that is triggered when the player starts entering a vehicle, you can use this one and if the engine is off then after the player enter the vehicle use setEngineState to turn it off. When the player exit you can just easily use the onPlayerVehicleExit trigger and turn the engine off with setEngineState Link to comment
JanriKallas Posted December 2, 2015 Share Posted December 2, 2015 function setEngineState(source) if (source) then local car = getPedOccupiedVehicle(source) if (car) then local state = getVehicleEngineState ( car) setVehicleEngineState ( car, not state ) setElementData(car,"enginestate", not state) end end end function enterVehicle ( player, seat, jacked ) --when a player enters a vehicle local state = getElementData(source, "enginestate") if (state) then setVehicleEngineState(source, state) end end addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle ) Link to comment
Tails Posted December 7, 2015 Author Share Posted December 7, 2015 Thank you both for your help! I managed to do it the way you described it jingzhi. Never knew about that function. addEventHandler("onVehicleStartEnter",root, function(player,seat) local e_state = getVehicleEngineState(source) if seat == 0 and e_state == false then function onEnter(player) setVehicleEngineState(source,false) removeEventHandler("onVehicleEnter",root,onEnter) end addEventHandler("onVehicleEnter",root,onEnter) end end ) This way you don't have to use tables or setElementData, JanriKallas. Link to comment
JanriKallas Posted December 13, 2015 Share Posted December 13, 2015 Oh yeahh.. didnt thought of that! 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