// Switch script to toggle the CAS_PLC_VFXTRAP hazard

void StartHazard(object oTrap);
void StopHazard(object oTrap);

void StartHazard(object oTrap)
{
    SetLocalInt(oTrap, "bActive", TRUE);
    ExecuteScript("cas_plcvfxobject", oTrap); // Run the hazard script on the placeable
}

void StopHazard(object oTrap)
{
    SetLocalInt(oTrap, "bActive", FALSE);
}

void main()
{
    object oSelf = OBJECT_SELF; // The switch
    object oTrap = GetObjectByTag("CAS_PLC_VFXTRAP"); // Find the trap placeable in the same area

    if (!GetIsObjectValid(oTrap))
    {
        SendMessageToPC(GetLastUsedBy(), "No hazard found in this area.");
        return;
    }

    int bActive = GetLocalInt(oTrap, "bActive");

    if (bActive == FALSE) 
    {
        SetLocalInt(oTrap, "bActive", TRUE);
        SendMessageToPC(GetLastUsedBy(), "You activate the hazard!");
        StartHazard(oTrap);
    }
    else 
    {
        SetLocalInt(oTrap, "bActive", FALSE);
        SendMessageToPC(GetLastUsedBy(), "You deactivate the hazard.");
        StopHazard(oTrap);
    }
}
