Nich Posted October 18, 2009 Share Posted October 18, 2009 How could I put deafult engine status to false/turned off? Thanks. Link to comment
50p Posted October 18, 2009 Share Posted October 18, 2009 What do you mean "default"? https://wiki.multitheftauto.com/wiki/Set ... ngineState Link to comment
Nich Posted October 18, 2009 Author Share Posted October 18, 2009 If I spawn a vehicle, then by deafult the engine is always on. I want to develop a system, that when I enter a car, the engine would be off and when I exit a vehicle with a running engine it would still work. At the moment all the engines are running and when I shut down the engine with a command, it would be running again when I enter it next time. Link to comment
CallumD Posted October 18, 2009 Share Posted October 18, 2009 (edited) function turnOffEngine ( theVehicle ) setVehicleEngineState ( getRootElement(), false ) end addEventHandler ( "onResourceStart", getResourceFromName ( "RESOURCE NAME HERE" ), turnOffEngine ) function toggleEngine ( playerSource ) local theVehicle = getPlayerOcuppiedVehicle ( playerSource ) if theVehicle and getVehicleController ( theVehicle ) == playerSource then local state = getVehicleEngineState ( theVehicle ) setVehicleEngineState ( theVehicle, not state ) end end addCommandHandler ( "engine", toggleEngine ) Edited October 19, 2009 by Guest Link to comment
Nich Posted October 18, 2009 Author Share Posted October 18, 2009 function turnOffEngine ( theVehicle ) setVehicleEngineState ( theVehicle, false ) end addEventHandler ( "onVehicleEnter", getRootElement(), turnOffEngine ) That means that I can't let the engine running, am I right? I need it for my roleplay GM, and it wouldn't be a good thing, if car's engine would start/stop by it-self, all has to be done by an in game character. Link to comment
50p Posted October 18, 2009 Share Posted October 18, 2009 function turnOffEngine ( theVehicle ) setVehicleEngineState ( getRootElement(), false ) end addEventHandler ( "onResourceStart", getResourceFromName ( "RESOURCE NAME HERE" ), turnOffEngine ) function toggleEngine ( playerSource ) local theVehicle = getPlayerOcuppiedVehicle ( playerSource ) if theVehicle and getVehicleController ( theVehicle ) == playerSource then local state = getVehicleEngineState ( theVehicle ) setVehicleEngineState ( theVehicle, not state ) end end addCommandHandler ( "engine", toggleEngine ) Don't use getResorceFromName in addEventHandler unless you do it in function. It's useless. Why would you want to add the event handler to a different resource not "this"? Link to comment
Nich Posted October 18, 2009 Author Share Posted October 18, 2009 Callumd's way didn't work.. how should i do it then? Link to comment
DakiLLa Posted October 19, 2009 Share Posted October 19, 2009 function turnOffEngine() for i, vehicle in ipairs( getElementsByType( 'vehicle' ) ) do setVehicleEngineState ( vehicle, false ) end end addEventHandler ( "onResourceStart", getResourceRootElement( getThisResource() ), turnOffEngine ) function toggleEngine ( player ) local theVehicle = getPlayerOcuppiedVehicle ( player ) if theVehicle and getVehicleController ( theVehicle ) == player then local state = getVehicleEngineState ( theVehicle ) setVehicleEngineState ( theVehicle, not state ) end end addCommandHandler ( "engine", toggleEngine ) ^ should work Link to comment
Nich Posted October 19, 2009 Author Share Posted October 19, 2009 function turnOffEngine() for i, vehicle in ipairs( getElementsByType( 'vehicle' ) ) do setVehicleEngineState ( vehicle, false ) end end addEventHandler ( "onResourceStart", getResourceRootElement( getThisResource() ), turnOffEngine ) function toggleEngine ( player ) local theVehicle = getPlayerOcuppiedVehicle ( player ) if theVehicle and getVehicleController ( theVehicle ) == player then local state = getVehicleEngineState ( theVehicle ) setVehicleEngineState ( theVehicle, not state ) end end addCommandHandler ( "engine", toggleEngine ) ^ should work Didn't work for me Link to comment
subenji99 Posted October 19, 2009 Share Posted October 19, 2009 getPlayerOcuppiedVehicle should be getPedOccupiedVehicle. Link to comment
CallumD Posted October 19, 2009 Share Posted October 19, 2009 You did make a meta.xml and all the other stuff, right? Link to comment
Nich Posted October 19, 2009 Author Share Posted October 19, 2009 You did make a meta.xml and all the other stuff, right? Yeah. Link to comment
DakiLLa Posted October 19, 2009 Share Posted October 19, 2009 did you write the '/engine' command in chat? Link to comment
Nich Posted October 19, 2009 Author Share Posted October 19, 2009 did you write the '/engine' command in chat? Yes Link to comment
Nich Posted October 19, 2009 Author Share Posted October 19, 2009 Sorry, I left the ocuppied typo in, the /engine works, but still, engine working when I shut it off and sit back on it. And also when I spawn vehicle, it's already working. Link to comment
Gamesnert Posted October 19, 2009 Share Posted October 19, 2009 Just a small example of how it might work: function setStateToData() for index,vehicle in ipairs(getElementsByType("vehicle")) do -- Do this for every vehicle existing: local state=getVehicleEngineState(vehicle) -- See if the engine is on setElementData(vehicle,"engine",state,false) -- Store the result end end addEventHandler("onResourceStart",getResourceRootElement(),setStateToData) function vehicleEnterStuff() local state=getElementData(source,"engine") -- Get the stored data setVehicleEngineState(source,state) -- Set it to that end addEventHandler("onVehicleEnter",getRootElement(),vehicleEnterStuff) -- Make sure this happens if a player enters a vehicle function vehicleExitStuff() -- Exact opposite local state=getVehicleEngineState(source) setElementData(source,"engine",state,false) end addEventHandler("onVehicleExit",getRootElement(),vehicleExitStuff) There might be several issues with this, but well, I guess it should help out a bit. 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