FuriouZ Posted March 18, 2014 Share Posted March 18, 2014 Hello! I have a question, how i can make that i have to hold key down for example 3 secons and then vehicle engine turns on ? so far i have this function toggleEngine() local checkPlayerVehicle = getPedOccupiedVehicle( localPlayer ) if ( checkPlayerVehicle and getVehicleController( checkPlayerVehicle ) == localPlayer ) then local checkState = getVehicleEngineState( checkPlayerVehicle ) setVehicleEngineState( checkPlayerVehicle, not checkState ) end end bindKey("I", "down",toggleEngine) Thanks ! Link to comment
iPrestege Posted March 18, 2014 Share Posted March 18, 2014 Hi You can use timers. setTimer Link to comment
Vision Posted March 18, 2014 Share Posted March 18, 2014 local timer local engineState = false function toggleEngine ( ) local checkPlayerVehicle = getPedOccupiedVehicle ( localPlayer ) if ( checkPlayerVehicle and getVehicleController ( checkPlayerVehicle ) == localPlayer ) then local checkState = getVehicleEngineState ( checkPlayerVehicle ) timer = setTimer ( function ( ) setVehicleEngineState ( checkPlayerVehicle, not checkState ) outputChatBox ( ( checkState and 'OFF' or 'ON' ) ) engineState = false end, 3000, 1 ) engineState = true end end bindKey ( 'I', 'down', toggleEngine ) bindKey ( 'I', 'up', function ( ) if ( engineState ) then if ( isTimer ( timer ) ) then killTimer ( timer ) end engineState = false end end ) Try this. Link to comment
Anubhav Posted March 18, 2014 Share Posted March 18, 2014 I din't made the exact thing. But if you press it one time it will take 5 seconds to toggle! function toggleEngine() setTimer(funcName,5000,1) end bindKey("I", "down",toggleEngine) function funcName() local checkPlayerVehicle = getPedOccupiedVehicle( localPlayer ) if ( checkPlayerVehicle and getVehicleController( checkPlayerVehicle ) == localPlayer ) then local checkState = getVehicleEngineState( checkPlayerVehicle ) setVehicleEngineState( checkPlayerVehicle, not checkState ) end end Link to comment
cheez3d Posted March 18, 2014 Share Posted March 18, 2014 local k = "space" -- the key that turns on/off the engine local t = 3 -- how many seconds to hold the key local function toggle_engine_state(key,state) if key == k and state then local tick = getTickCount() local function check_key() if not getKeyState(key) then removeEventHandler("onClientRender",root,check_key) end if getTickCount()>=tick+t*1000 then removeEventHandler("onClientRender",root,check_key) local vehicle = getPedOccupiedVehicle(localPlayer) setVehicleEngineState(vehicle,not getVehicleEngineState(vehicle)) end end addEventHandler("onClientRender",root,check_key) end end addEventHandler("onClientVehicleEnter",root,function(player,seat) if player and seat == 0 then addEventHandler("onClientKey",root,toggle_engine_state) end end) addEventHandler("onClientVehicleStartExit",root,function(player,seat) if player and seat == 0 then removeEventHandler("onClientKey",root,toggle_engine_state) end 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