Jump to content

How do I check if a vehicle is an emergency vehicle.


benwilkins

Recommended Posts

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

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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...