Skarbonke Posted July 24, 2018 Share Posted July 24, 2018 (edited) Hey guys! Skarbonke here, need some help on binding this "blinker" script on a <,> and / idk why it isin't working, please help. It should work when you press the button, and when you press it again it stops blinking. -- Global data and pointers toggler = { } dtype = { } syncTimer = { } currHeadLightColor = {{ }} function isVehicleBlinking( vehicle) if currHeadLightColor[vehicle] then return true else return false end end -- Toggling lights function toggleLights( veh ) if isElement( veh ) then setVehicleOverrideLights( veh, 2 ) if toggler[veh] == 1 then setVehicleLightState( veh, 0, 1 ) setVehicleLightState( veh, 1, 1 ) setVehicleLightState( veh, 2, 1 ) setVehicleLightState( veh, 3, 1 ) if veh and isElement(veh) and (getElementType(veh) == "vehicle") and getVehicleTowedByVehicle( veh ) then local veh2 = getVehicleTowedByVehicle( veh ) setVehicleLightState( veh2, 0, 1 ) setVehicleLightState( veh2, 1, 1 ) setVehicleLightState( veh2, 2, 1 ) setVehicleLightState( veh2, 3, 1 ) end toggler[veh] = 0 else if dtype[veh] == "lleft" then setVehicleLightState( veh, 0, 0 ) setVehicleLightState( veh, 1, 1 ) setVehicleLightState( veh, 2, 1 ) setVehicleLightState( veh, 3, 0 ) if veh and isElement(veh) and (getElementType(veh) == "vehicle") and getVehicleTowedByVehicle( veh ) then local veh2 = getVehicleTowedByVehicle( veh ) setVehicleLightState( veh2, 0, 0 ) setVehicleLightState( veh2, 1, 1 ) setVehicleLightState( veh2, 2, 1 ) setVehicleLightState( veh2, 3, 0 ) end elseif dtype[veh] == "lright" then setVehicleLightState( veh, 0, 1 ) setVehicleLightState( veh, 1, 0 ) setVehicleLightState( veh, 2, 0 ) setVehicleLightState( veh, 3, 1 ) if (getElementType(veh) == "vehicle") and getVehicleTowedByVehicle( veh ) then local veh2 = getVehicleTowedByVehicle( veh ) setVehicleLightState( veh2, 0, 1 ) setVehicleLightState( veh2, 1, 0 ) setVehicleLightState( veh2, 2, 0 ) setVehicleLightState( veh2, 3, 1 ) end elseif (getElementType(veh) == "vehicle") and dtype[veh] == "warn" then setVehicleLightState( veh, 0, 0 ) setVehicleLightState( veh, 1, 0 ) setVehicleLightState( veh, 2, 0 ) setVehicleLightState( veh, 3, 0 ) if veh and isElement(veh) and (getElementType(veh) == "vehicle") and getVehicleTowedByVehicle( veh ) then local veh2 = getVehicleTowedByVehicle( veh ) setVehicleLightState( veh2, 0, 0 ) setVehicleLightState( veh2, 1, 0 ) setVehicleLightState( veh2, 2, 0 ) setVehicleLightState( veh2, 3, 0 ) end end toggler[veh] = 1 end end end -- Left function lightHandler( player, cmd ) if player and isElement( player ) and getPedOccupiedVehicle( player ) then local veh = getPedOccupiedVehicle( player ) if ( not isTimer( syncTimer[veh] ) or cmd ~= dtype[veh] ) and getVehicleOccupants(veh)[0] == player then -- Save the current head light color setVehicleLightState( veh, 0, 1 ) setVehicleLightState( veh, 1, 1 ) setVehicleLightState( veh, 2, 1 ) setVehicleLightState( veh, 3, 1 ) if veh and isElement(veh) and (getElementType(veh) == "vehicle") and getVehicleTowedByVehicle( veh ) then local veh2 = getVehicleTowedByVehicle( veh ) setVehicleLightState( veh2, 0, 1 ) setVehicleLightState( veh2, 1, 1 ) setVehicleLightState( veh2, 2, 1 ) setVehicleLightState( veh2, 3, 1 ) end if not currHeadLightColor[veh] then currHeadLightColor[veh] = { } currHeadLightColor[veh][1],currHeadLightColor[veh][2],currHeadLightColor[veh][3] = getVehicleHeadLightColor( veh ) end -- Set the new headlight color to yellow setVehicleHeadLightColor( veh, 255, 200, 0 ) -- Start the syn timer if isTimer( syncTimer[veh] ) then killTimer( syncTimer[veh] ) end syncTimer[veh] = setTimer( toggleLights, 380, 0, veh ) toggler[veh] = 1 dtype[veh] = cmd toggleLights( veh ) else if isTimer( syncTimer[veh] ) then killTimer( syncTimer[veh] ) local vehID = getElementData( veh, "vehicleID") if vehID then local vehID = tonumber( vehID) local colorTable = exports.GTIvehicles:getVehicleData( vehID, "light_color") or "255,255,255" local cData = split( colorTable, ",") --setVehicleHeadLightColor( veh, currHeadLightColor[veh][1],currHeadLightColor[veh][2],currHeadLightColor[veh][3] ) setVehicleHeadLightColor( veh, cData[1], cData[2], cData[3]) currHeadLightColor[veh] = nil else setVehicleHeadLightColor( veh, 255, 255, 255) end end setVehicleLightState( veh, 0, 0 ) setVehicleLightState( veh, 1, 0 ) setVehicleLightState( veh, 2, 0 ) setVehicleLightState( veh, 3, 0 ) setVehicleOverrideLights( veh, 2 ) if veh and isElement(veh) and (getElementType(veh) == "vehicle") and getVehicleTowedByVehicle( veh ) then local veh2 = getVehicleTowedByVehicle( veh ) setVehicleLightState( veh2, 0, 0 ) setVehicleLightState( veh2, 1, 0 ) setVehicleLightState( veh2, 2, 0 ) setVehicleLightState( veh2, 3, 0 ) setVehicleOverrideLights( veh2, 2 ) end end end end addCommandHandler( "lleft", lightHandler ) addCommandHandler( "lright", lightHandler ) addCommandHandler( "warn", lightHandler ) function addKeyInBlinkers() if (not isKeyBound(source, ",")) and (not isKeyBound(source, ".")) then bindKey(",", "down", "lleft") bindKey(".", "down", "lright") bindKey("/", "down", "warn") end end addEventHandler("onResourceStart", resourceRoot, addKeyInBlinkers) Edited July 24, 2018 by Skarbonke Link to comment
myonlake Posted July 24, 2018 Share Posted July 24, 2018 BindKey takes in a player element as the first argument. Loop through all players and bind them that way. Your isKeyBound is currently using "source", which is the resource. This is not right. You should move that into the for loop and then use the player element as the first argument there as well. 1 Link to comment
Skarbonke Posted July 24, 2018 Author Share Posted July 24, 2018 35 minutes ago, myonlake said: BindKey takes in a player element as the first argument. Loop through all players and bind them that way. Your isKeyBound is currently using "source", which is the resource. This is not right. You should move that into the for loop and then use the player element as the first argument there as well. thank you for the replay, but it doesn't work or I do something wrong ;/ Link to comment
myonlake Posted July 24, 2018 Share Posted July 24, 2018 53 minutes ago, Skarbonke said: thank you for the replay, but it doesn't work or I do something wrong ;/ Show the code on how you're doing it now. 1 Link to comment
Skarbonke Posted July 24, 2018 Author Share Posted July 24, 2018 8 minutes ago, myonlake said: Show the code on how you're doing it now. function addKeyInBlinkers() if (not isKeyBound(player, ",")) and (not isKeyBound(player, ".")) then bindKey(player,",", "down", "lleft") bindKey(player,".", "down", "lright") bindKey(player,"/", "down", "warn") end end addEventHandler("onResourceStart", resourceRoot, addKeyInBlinkers) The Loop through all players part I really really don't get... Link to comment
myonlake Posted July 24, 2018 Share Posted July 24, 2018 Just now, Skarbonke said: function addKeyInBlinkers() if (not isKeyBound(player, ",")) and (not isKeyBound(player, ".")) then bindKey(player,",", "down", "lleft") bindKey(player,".", "down", "lright") bindKey(player,"/", "down", "warn") end end addEventHandler("onResourceStart", resourceRoot, addKeyInBlinkers) The Loop through all players part I really really don't get... You need to use getElementsByType as described in the link (see the examples section). Try this. function addKeyInBlinkers() for _, player in pairs(getElementsByType("player")) do if (not isKeyBound(player, ",")) and (not isKeyBound(player, ".")) then bindKey(player, ",", "down", "lleft") bindKey(player, ".", "down", "lright") bindKey(player, "/", "down", "warn") end end end addEventHandler("onResourceStart", resourceRoot, addKeyInBlinkers) 1 Link to comment
Skarbonke Posted July 25, 2018 Author Share Posted July 25, 2018 13 hours ago, myonlake said: You need to use getElementsByType as described in the link (see the examples section). Try this. function addKeyInBlinkers() for _, player in pairs(getElementsByType("player")) do if (not isKeyBound(player, ",")) and (not isKeyBound(player, ".")) then bindKey(player, ",", "down", "lleft") bindKey(player, ".", "down", "lright") bindKey(player, "/", "down", "warn") end end end addEventHandler("onResourceStart", resourceRoot, addKeyInBlinkers) Thank you, it worked! <3 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