Killswitch to this script

How can I make a killswitch to this script so that when I press shift (155) again the automation cuts?

You already kind of have the killswitch, because this line already toggles it on and off “automationActive = not automationActive”. The reason it does not stop instantly is that your script is sitting inside long Citizen.Wait(5600) and Citizen.Wait(12000) calls, so it cannot see the second key press until those waits finish

The usual fix is to replace the long waits with a small loop that keeps checking whether automationActive was turned off:

local automationActive = false

local function waitWithKillSwitch(ms)
    local endTime = GetGameTimer() + ms

    while GetGameTimer() < endTime do
        Citizen.Wait(0)

        if IsControlJustPressed(0, 155) then
            automationActive = false
            return false
        end

        if not automationActive then
            return false
        end
    end

    return true
end

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)

        if IsControlJustPressed(0, 155) then
            automationActive = not automationActive
        end

        if automationActive then
            local playerPed = PlayerPedId()

            if IsPedInAnyVehicle(playerPed, false) then
                local vehicle = GetVehiclePedIsIn(playerPed, false)

                if GetPedInVehicleSeat(vehicle, -1) == playerPed and IsVehicleSirenOn(vehicle) then
                    SetControlNormal(0, 158, 1.0)
                    if not waitWithKillSwitch(5600) then goto continue end
                    SetControlNormal(0, 158, 0.0)

                    SetControlNormal(0, 157, 1.0)
                    if not waitWithKillSwitch(12000) then goto continue end
                    SetControlNormal(0, 157, 0.0)
                else
                    Citizen.Wait(500)
                end
            else
                automationActive = false
                Citizen.Wait(1000)
            end
        end

        ::continue::
    end
end)

So basically, the toggle is already there, you just need to stop using one big wait and keep checking the key during the delay. If you want, I can rewrite his whole script a bit cleaner so you can paste it as a ready-to-use reply.

Hey, that would be super appreciated if you could do it! The reason for the long waits 5600ms and 12000ms is so that the siren has time to play out. So this script is for ELS to change automatically sirentones. The first tone plays for 5600ms and other for 12000ms.

I would be so thankful if you could help me with this!!

Thank you!

I already explained that to you in my previous reply. The function I was talking about is in the code section. I’ve already done it for you.

Yeah, thanks for that. I figured after I wrote my reply. Thank you so much!