szlend Posted January 27, 2008 Share Posted January 27, 2008 Since there is no getVehicleEngineState function, I decided to code it. Enjoy The function: function getVehicleEngineState(source) if isElement(source) and getElementType(source) == "vehicle" then return getElementData(source, "engineState") end end We'll also need a new setVehicleEngineState function: function setVehicleEngineState2(source, state) if isElement(source) and getElementType(source) == "vehicle" then setElementData(source, "engineState", state) setVehicleEngineState(source, state) end end And to set vehicle engine off on resource start: function resourceStart() local vehicles = getElementsByType("vehicle") for index, vehicle in pairs(vehicles) do setElementData(vehicle, "engineState", false) end end OnVehicleEnter and OnVehicleRespawn fix: function vehicleEnter() setVehicleEngineState2(source, getVehicleEngineState(source)) end function vehicleRespawn() setVehicleEngineState2(source, false) end ----------------------------------------- Example: function getVehicleEngineState(source) if isElement(source) and getElementType(source) == "vehicle" then return getElementData(source, "engineState") end end function setVehicleEngineState2(source, state) if isElement(source) and getElementType(source) == "vehicle" then setElementData(source, "engineState", state) setVehicleEngineState(source, state) end end function toggleEngine(source) local vehicle = getPlayerOccupiedVehicle(source) if (vehicle) then if (getVehicleEngineState(vehicle) == true) then setVehicleEngineState2(vehicle, false) else setVehicleEngineState2(vehicle, true) end end end function resourceStart() local vehicles = getElementsByType("vehicle") for index, vehicle in pairs(vehicles) do setElementData(vehicle, "engineState", false) end end function vehicleEnter() setVehicleEngineState2(source, getVehicleEngineState(source)) end function vehicleRespawn() setVehicleEngineState2(source, false) end addEventHandler("onResourceStart", getRootElement(), resourceStart) addEventHandler("onVehicleEnter", getRootElement(), vehicleEnter) addEventHandler("OnVehicleRespawn", getRootElement(), vehicleRespawn) addCommandHandler("engine", toggleEngine) Link to comment
eAi Posted January 27, 2008 Share Posted January 27, 2008 Why not release this as a resource and export it getVehicleEngineState as a function? Link to comment
szlend Posted January 27, 2008 Author Share Posted January 27, 2008 Good idea Will do tommorow Link to comment
lil Toady Posted March 5, 2008 Share Posted March 5, 2008 function setVehicleEngineState2(source, state) if isElement(source) and getElementType(source) == "vehicle" then setElementData(source, "engineState", state) setVehicleEngineState(source, state) end end You could redefine the setVehicleEngineState itself, like _setVehicleEngineState = setVehicleEngineState function setVehicleEngineState(source, state) if isElement(source) and getElementType(source) == "vehicle" then setElementData(source, "engineState", state) _setVehicleEngineState(source, state) end end Link to comment
KillerX Posted September 16, 2018 Share Posted September 16, 2018 21 hours ago, Debo15 said: Good Job January 27, 2008 +___+ 1 1 Link to comment
MrBiG Posted September 17, 2018 Share Posted September 17, 2018 On 16/09/2018 at 07:02, KillerX said: January 27, 2008 +___+ Yes I know, but I love to go back very old topics 1 Link to comment
Captain Cody Posted September 17, 2018 Share Posted September 17, 2018 @Debo15 #1 you bumped a 10 year old topic, #2 the function has been natively added to MTA. 1 Link to comment
Recommended Posts