ViRuZGamiing Posted May 18, 2013 Share Posted May 18, 2013 Hello, I have an Engine off/on but I want to use "x" instead of the command /switchengine function switchEngine ( playerSource ) local theVehicle = getPedOccupiedVehicle ( playerSource ) if theVehicle and getVehicleController ( theVehicle ) == playerSource then local state = getVehicleEngineState ( theVehicle ) setVehicleEngineState ( theVehicle, not state ) end end addCommandHandler ( "switchengine", switchEngine ) Thanks Link to comment
Castillo Posted May 18, 2013 Share Posted May 18, 2013 You can bind it when they enter on a vehicle ( onVehicleEnter ) and unbind it when they exit ( onVehicleExit ). Link to comment
ViRuZGamiing Posted May 18, 2013 Author Share Posted May 18, 2013 @Solidsnake14 Should I make something like: local root = getRootElement () local thisResourceRoot = getResourceRootElement(getThisResource()) function thisResourceStart () local players = getElementsByType ( "player" ) for k,v in ipairs(players) do bindKey ( v, "x", "down", setVehicleEngine ) end end function playerJoin () bindKey ( source, "x", "down", setVehicleEngine ) end addEventHandler ( "onResourceStart", thisResourceRoot, thisResourceStart ) addEventHandler ( "onPlayerJoin", root, playerJoin ) function setVehicleEngine ( player, key, state ) if ( getPedOccupiedVehicleSeat ( player ) == 0 ) then local veh = getPedOccupiedVehicle ( player ) end end end Please don't be mad if I made a mistake, i'm still learning Link to comment
iPrestege Posted May 18, 2013 Share Posted May 18, 2013 You didn't use what SolidSnake Gave you event's . Link to comment
ViRuZGamiing Posted May 18, 2013 Author Share Posted May 18, 2013 I know, I didn't know if there is a unbindKey code Please help me a bit further Link to comment
Castillo Posted May 18, 2013 Share Posted May 18, 2013 @Solidsnake14 Should I make something like: local root = getRootElement () local thisResourceRoot = getResourceRootElement(getThisResource()) function thisResourceStart () local players = getElementsByType ( "player" ) for k,v in ipairs(players) do bindKey ( v, "x", "down", setVehicleEngine ) end end function playerJoin () bindKey ( source, "x", "down", setVehicleEngine ) end addEventHandler ( "onResourceStart", thisResourceRoot, thisResourceStart ) addEventHandler ( "onPlayerJoin", root, playerJoin ) function setVehicleEngine ( player, key, state ) if ( getPedOccupiedVehicleSeat ( player ) == 0 ) then local veh = getPedOccupiedVehicle ( player ) end end end Please don't be mad if I made a mistake, i'm still learning Read again what I wrote on my first post, it'll be easier for you to do it . Link to comment
ViRuZGamiing Posted May 18, 2013 Author Share Posted May 18, 2013 Can you please tell me which codes I need; -bindKey -onVehicleEnter -onVehicleExit -getPedoccupiedVehicle More codes? Link to comment
iPrestege Posted May 18, 2013 Share Posted May 18, 2013 Can you please tell me which codes I need;-bindKey -onVehicleEnter -onVehicleExit -getPedoccupiedVehicle More codes? There's no need for 'getPedoccupiedVehicle' You need : unbindKey Link to comment
ViRuZGamiing Posted May 19, 2013 Author Share Posted May 19, 2013 Okay, I readed the Parameters on Wiki bindKey(player, x, down, onEnter) function onEnter (player, x, down) end addEventHandler("onVehicleEnter", onEnter) unbindKey(player, x, down, onEnter) function onExit (player, x, down) end addEventHandler("onVehicleExit", onEnter) How does this look? Only the Engine thing needs to be added Link to comment
iPrestege Posted May 19, 2013 Share Posted May 19, 2013 Make it easy try this server side : function SwitchEngine( playerSource ) local theVehicle = getPedOccupiedVehicle ( playerSource ) if theVehicle and getVehicleController ( theVehicle ) == playerSource then local state = getVehicleEngineState ( theVehicle ) setVehicleEngineState ( theVehicle, not state ) end end function BindKeys ( player ) if ( eventName == "onVehicleStartEnter" ) then bindKey ( player,"x","down",SwitchEngine ) else unbindKey ( player,"x","down",SwitchEngine ) end end addEventHandler ( "onVehicleStartEnter", root, BindKeys ) addEventHandler ( "onVehicleStartExit", root, BindKeys ) Not tested yet . 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