benwilkins Posted February 14, 2011 Share Posted February 14, 2011 I have an emergency lights for the front headlights, but at the moment, it can be activated in any vehicle. Link to comment
Castillo Posted February 14, 2011 Share Posted February 14, 2011 1. Make a table with the ID's you want only. 2. When going to activate the lights, check if the vehicle id it's on that table. 3. You are done, and should work fine. Example: allowedIDS = {520 = true, 438 = true} and so on. then to check just do: model = getElementModel(your element) then if allowedIDS[model] then Link to comment
benwilkins Posted February 14, 2011 Author Share Posted February 14, 2011 Care to take a qucik look? Didnt actually make the script, my friend did it, but hes been away for a good few weeks. I have also tried, checking if the vehicle has sirens, and if so then allow the script to work. Heres the script function setBinds() end function setBindsTwo() local players = getElementsByType("player") for k, v in ipairs(players) do bindKey(v, "p", "down", delayedEMToggle) end end addEventHandler("onPlayerJoin", getRootElement(), setBinds) addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), setBindsTwo) function toggleVehicleLights(ply, key, state) local vehicle = getPedOccupiedVehicle(ply) if vehicle then if getVehicleOverrideLights(vehicle) ~= 2 then setVehicleOverrideLights(vehicle, 2) else setVehicleOverrideLights(vehicle, 1) end end end function delayedEMToggle(ply, key, state) setTimer(toggleEmergencyLights, 200, 1, ply, key, state) end local colorTimers = {} local stroboTimers = {} function toggleEmergencyLights(ply, key, state) local vehicle = getPedOccupiedVehicle(ply) if not vehicle then return end if colorTimers[tostring(vehicle)] == nil and stroboTimers[tostring(vehicle)] == nil then -- start timers to flash lights with colors -- 1. timer to change color AND left/right simultaneously -> left = blue, right = red -- 2. timer to flash on/off in a strobo fashion colorTimers[tostring(vehicle)] = setTimer(sirenColorTick, 900, 0, vehicle) stroboTimers[tostring(vehicle)] = setTimer(sirenStroboTick, 90, 0, vehicle) elseif colorTimers[tostring(vehicle)] ~= nil and stroboTimers[tostring(vehicle)] ~= nil then -- stop timers, clear light colors and statuses killTimer(colorTimers[tostring(vehicle)]) killTimer(stroboTimers[tostring(vehicle)]) colorTimers[tostring(vehicle)] = nil stroboTimers[tostring(vehicle)] = nil setVehicleHeadLightColor(vehicle, 255, 255, 255) setVehicleOverrideLights(vehicle, 2) setVehicleLightState(vehicle, 0, 0) setVehicleLightState(vehicle, 1, 0) end end function sirenColorTick(vehicle) local r, g, b = getVehicleHeadLightColor(vehicle) if g > 0 or b > 0 then setVehicleHeadLightColor(vehicle, 255, 0, 0) setVehicleLightState(vehicle, 0, 0) setVehicleLightState(vehicle, 1, 1) elseif r > 0 then setVehicleHeadLightColor(vehicle, 0, 0, 255) setVehicleLightState(vehicle, 0, 1) setVehicleLightState(vehicle, 1, 0) end end function sirenStroboTick(vehicle) if getVehicleOverrideLights(vehicle) == 2 or getVehicleOverrideLights(vehicle) == 0 then setVehicleOverrideLights(vehicle, 1) else setVehicleOverrideLights(vehicle, 2) end end Link to comment
Castillo Posted February 14, 2011 Share Posted February 14, 2011 function setBinds() end function setBindsTwo() local players = getElementsByType("player") for k, v in ipairs(players) do bindKey(v, "p", "down", delayedEMToggle) end end addEventHandler("onPlayerJoin", getRootElement(), setBinds) addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), setBindsTwo) function toggleVehicleLights(ply, key, state) local vehicle = getPedOccupiedVehicle(ply) if vehicle then if getVehicleOverrideLights(vehicle) ~= 2 then setVehicleOverrideLights(vehicle, 2) else setVehicleOverrideLights(vehicle, 1) end end end allowedIDS = {520 = true, 438 = true} function delayedEMToggle(ply, key, state) veh = getPedOccupiedVehicle(ply) model = getElementModel(veh) then if allowedIDS[model] then setTimer(toggleEmergencyLights, 200, 1, ply, key, state) end end local colorTimers = {} local stroboTimers = {} function toggleEmergencyLights(ply, key, state) local vehicle = getPedOccupiedVehicle(ply) if not vehicle then return end if colorTimers[tostring(vehicle)] == nil and stroboTimers[tostring(vehicle)] == nil then -- start timers to flash lights with colors -- 1. timer to change color AND left/right simultaneously -> left = blue, right = red -- 2. timer to flash on/off in a strobo fashion colorTimers[tostring(vehicle)] = setTimer(sirenColorTick, 900, 0, vehicle) stroboTimers[tostring(vehicle)] = setTimer(sirenStroboTick, 90, 0, vehicle) elseif colorTimers[tostring(vehicle)] ~= nil and stroboTimers[tostring(vehicle)] ~= nil then -- stop timers, clear light colors and statuses killTimer(colorTimers[tostring(vehicle)]) killTimer(stroboTimers[tostring(vehicle)]) colorTimers[tostring(vehicle)] = nil stroboTimers[tostring(vehicle)] = nil setVehicleHeadLightColor(vehicle, 255, 255, 255) setVehicleOverrideLights(vehicle, 2) setVehicleLightState(vehicle, 0, 0) setVehicleLightState(vehicle, 1, 0) end end function sirenColorTick(vehicle) local r, g, b = getVehicleHeadLightColor(vehicle) if g > 0 or b > 0 then setVehicleHeadLightColor(vehicle, 255, 0, 0) setVehicleLightState(vehicle, 0, 0) setVehicleLightState(vehicle, 1, 1) elseif r > 0 then setVehicleHeadLightColor(vehicle, 0, 0, 255) setVehicleLightState(vehicle, 0, 1) setVehicleLightState(vehicle, 1, 0) end end function sirenStroboTick(vehicle) if getVehicleOverrideLights(vehicle) == 2 or getVehicleOverrideLights(vehicle) == 0 then setVehicleOverrideLights(vehicle, 1) else setVehicleOverrideLights(vehicle, 2) end end Link to comment
benwilkins Posted February 21, 2011 Author Share Posted February 21, 2011 It doesnt work: Line 23: Expected } near = Tried debuging myself but no look. Link to comment
SDK Posted February 21, 2011 Share Posted February 21, 2011 Well, that's just a syntax mistake: allowedIDS = {[520] = true, [438] = true} 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