illestiraqi Posted February 24, 2013 Share Posted February 24, 2013 This script turns the vehicle engine off by pressing F to turn on/off. Pressing L will toggle the lights on/off. this is not made by me just a notice! Anyways I want the "F" button changed to /engine to turn vehicle on/off please help. function engineOffOn(source) if isPedInVehicle(source) then local sourceVehicle = getPedOccupiedVehicle( source ) if getVehicleEngineState ( sourceVehicle ) then setVehicleEngineState ( sourceVehicle, false ) else setVehicleEngineState ( sourceVehicle, true ) end end end function changeLightsState(source) if isPedInVehicle(source) then local sourceVehicle = getPedOccupiedVehicle( player ) if getVehicleOverrideLights ( sourceVehicle ) ~= 2 then setVehicleOverrideLights( sourceVehicle, 2 ) else setVehicleOverrideLights( sourceVehicle, 1 ) end end end addEventHandler ( "onPlayerVehicleEnter",root,function( theVehicle, driver, jackerPlayer ) -- if it's the driver who got out, and he was not jacked, if driver == 0 and not jackerPlayer then -- turn on the engine setVehicleEngineState ( theVehicle, true ) end end) addEventHandler ( "onPlayerVehicleExit",root,function( theVehicle, driver, jackerPlayer ) -- if it's the driver who got out, and he was not jacked, if driver == 0 and not jackerPlayer then -- turn off the engine setVehicleEngineState ( theVehicle, false ) setVehicleOverrideLights ( theVehicle, 1 ) end end) addEventHandler ( "onResourceStart",resourceRoot,function() if res~= getThisResource() then return end local engineKey = get("@jengine.engineKey") local lightsKey = get("@jengine.lightsKey") for _, player in ipairs(getElementsByType("player")) do bindKey (player, engineKey, "down", engineOffOn ) bindKey(player,lightsKey, "down", changeLightsState ) end end) addEventHandler("onResourceStop",resourceRoot,function(res) if res~= getThisResource() then return end for _, player in ipairs(getElementsByType("player")) do unbindKey (player, engineKey, "down", engineOffOn ) unbindKey(player,lightsKey, "down", changeLightsState ) end end) addEventHandler ( "onPlayerJoin",root,function() bindKey (source,engineKey, "down", engineOffOn) bindKey(source,lightsKey, "down", changeLightsState) end) addEventHandler ( "onPlayerQuit",root,function() unbindKey (source,engineKey, "down", engineOffOn) unbindKey(source,lightsKey, "down", changeLightsState) end) Link to comment
Castillo Posted February 24, 2013 Share Posted February 24, 2013 function engineOffOn(source) if isPedInVehicle(source) then local sourceVehicle = getPedOccupiedVehicle( source ) if getVehicleEngineState ( sourceVehicle ) then setVehicleEngineState ( sourceVehicle, false ) else setVehicleEngineState ( sourceVehicle, true ) end end end addCommandHandler ( "engine", engineOffOn ) function changeLightsState(source) if isPedInVehicle(source) then local sourceVehicle = getPedOccupiedVehicle( player ) if getVehicleOverrideLights ( sourceVehicle ) ~= 2 then setVehicleOverrideLights( sourceVehicle, 2 ) else setVehicleOverrideLights( sourceVehicle, 1 ) end end end addEventHandler ( "onPlayerVehicleEnter",root,function( theVehicle, driver, jackerPlayer ) -- if it's the driver who got out, and he was not jacked, if driver == 0 and not jackerPlayer then -- turn on the engine setVehicleEngineState ( theVehicle, true ) end end) addEventHandler ( "onPlayerVehicleExit",root,function( theVehicle, driver, jackerPlayer ) -- if it's the driver who got out, and he was not jacked, if driver == 0 and not jackerPlayer then -- turn off the engine setVehicleEngineState ( theVehicle, false ) setVehicleOverrideLights ( theVehicle, 1 ) end end) addEventHandler ( "onResourceStart",resourceRoot,function() if res~= getThisResource() then return end local lightsKey = get("@jengine.lightsKey") for _, player in ipairs(getElementsByType("player")) do bindKey(player,lightsKey, "down", changeLightsState ) end end) addEventHandler("onResourceStop",resourceRoot,function(res) if res~= getThisResource() then return end for _, player in ipairs(getElementsByType("player")) do unbindKey(player,lightsKey, "down", changeLightsState ) end end) addEventHandler ( "onPlayerJoin",root,function() bindKey(source,lightsKey, "down", changeLightsState) end) addEventHandler ( "onPlayerQuit",root,function() unbindKey(source,lightsKey, "down", changeLightsState) end) 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