#include "../../config/events.lua"

function init()
    trigger = FindTrigger("respawn_ai")
    vehicles = {}
	RegisterListenerTo(EVENTS.COUNTDOWN_OVER, "OnRaceStart")
end

function OnRaceStart()
    vehicles = FindVehicles("customhealth", true)
    UnregisterListener(EVENTS.COUNTDOWN_OVER, "OnRaceStart")
end

function update(dt)
    for i = 1, #vehicles do
        local vehicle = vehicles[i]
        if vehicle ~= GetPlayerVehicle() and IsVehicleInTrigger(trigger, vehicle) then
            TriggerEvent(EVENTS.BANGER_RESPAWN, vehicle)
        end
    end
end