Dimos7 Posted February 28, 2017 Share Posted February 28, 2017 (edited) Hello i attempt make my own indcator system but not working not errors or warnings addEventHandler("onPlayerJoin", root, function() bindKey(source,"[", "down", leftIndicator) bindKey(source, "]", "down", rightIndicator) end) addEventHandler("onResourceStart", resourceRoot, function() for i, v in ipairs(getElementsByType("player")) do bindKey(v, "[", "down", leftIndicator) bindKey(v, "]", "down", rightIndicator) end end) function leftIndicator(thePlayer) if isPedInVehicle(thePlayer) then car = getPedOccupiedVehicle(thePlayer) if getPedOccupiedVehicleSeat(thePlayer) == 0 then IdicatiorTimer = setTimer( function() setVehicleOverrideLights(car, 2) if getVehicleLightState(car, 0) == 0 then setVehicleLightState(car, 0, 1) setVehicleLightState(car, 1, 1) setVehicleLightState(car, 2, 1) setVehicleLightState(car, 3, 1) else setVehicleLightState(car, 0, 0) setVehicleLightState(car, 1, 1) setVehicleLightState(car, 2, 1) setVehicleLightState(car, 3, 0) end end, 50, 0) if isTimer(IdicatiorTimer) then killTimer(IdicatiorTimer) setVehicleOverrideLights(car, 1) end end end end function rightIndicator(thePlayer) if isPedInVehicle(thePlayer) then car = getPedOccupiedVehicle(thePlayer) if getPedOccupiedVehicleSeat(thePlayer) == 0 then IdicatiorTimer = setTimer( function() setVehicleOverrideLights(car, 2) if getVehicleLightState(car, 1) == 0 then setVehicleLightState(car, 0, 1) setVehicleLightState(car, 1, 1) setVehicleLightState(car, 2, 1) setVehicleLightState(car, 3, 1) else setVehicleLightState(car, 0, 1) setVehicleLightState(car, 1, 0) setVehicleLightState(car, 2, 0) setVehicleLightState(car, 3, 1) end end, 50, 0) if isTimer(IdicatiorTimer) then killTimer(IdicatiorTimer) setVehicleOverrideLights(car, 1) end end end end Edited February 28, 2017 by Dimos7 Link to comment
Administrators Lpsd Posted February 28, 2017 Administrators Share Posted February 28, 2017 Line 35,36 and 62,63: killTimer(IdicatiorTimer) setVehicleOverrideLights(car, 1) You're killing the timer straight after it's been created. Maybe it'd be better to make the indicators toggle, so you press them once to turn it on, and press again to turn off. Didn't test but it should work. You'll have to fix indentation as the code editor here isn't the best. addEventHandler("onPlayerJoin", root, function() bindKey(source,"[", "down", leftIndicator) bindKey(source, "]", "down", rightIndicator) end) addEventHandler("onResourceStart", resourceRoot, function() leftIndicatorStatus = {} rightIndicatorStatus = {} for i, v in ipairs(getElementsByType("player")) do local playerName = getPlayerName(v) bindKey(v, "[", "down", leftIndicator) bindKey(v, "]", "down", rightIndicator) leftIndicatorStatus[playerName] = false rightIndicatorStatus[playerName] = false end end) function leftIndicator(thePlayer) local playerName = getPlayerName(thePlayer) if leftIndicatorStatus[playerName] == false then if isPedInVehicle(thePlayer) then car = getPedOccupiedVehicle(thePlayer) if getPedOccupiedVehicleSeat(thePlayer) == 0 then leftIndicatorStatus[playerName] = true IdicatiorTimerLeft = setTimer( function() setVehicleOverrideLights(car, 2) if getVehicleLightState(car, 0) == 0 then setVehicleLightState(car, 0, 1) setVehicleLightState(car, 1, 1) setVehicleLightState(car, 2, 1) setVehicleLightState(car, 3, 1) else setVehicleLightState(car, 0, 0) setVehicleLightState(car, 1, 1) setVehicleLightState(car, 2, 1) setVehicleLightState(car, 3, 0) end end, 50, 0) end end else if isTimer(IdicatiorTimerLeft) then killTimer(IdicatiorTimerLeft) setVehicleOverrideLights(car, 1) leftIndicatorStatus[playerName] = false end end end function rightIndicator(thePlayer) local playerName = getPlayerName(thePlayer) if rightIndicatorStatus[playerName] == false then if isPedInVehicle(thePlayer) then car = getPedOccupiedVehicle(thePlayer) if getPedOccupiedVehicleSeat(thePlayer) == 0 then rightIndicatorStatus[playerName] = true IdicatiorTimerRight = setTimer( function() setVehicleOverrideLights(car, 2) if getVehicleLightState(car, 1) == 0 then setVehicleLightState(car, 0, 1) setVehicleLightState(car, 1, 1) setVehicleLightState(car, 2, 1) setVehicleLightState(car, 3, 1) else setVehicleLightState(car, 0, 1) setVehicleLightState(car, 1, 0) setVehicleLightState(car, 2, 0) setVehicleLightState(car, 3, 1) end end, 50, 0) end end else if isTimer(IdicatiorTimerRight) then killTimer(IdicatiorTimerRight) setVehicleOverrideLights(car, 1) rightIndicatorStatus[playerName] = false end 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