@name Athena
@inputs EGP:wirelink
@outputs 
@persist Hidden:number Secure:number Trackers:table Plate:entity Swarm:entity
@trigger
runOnTick(1)
runOnChat(1)
if(first())
{
    EGP:egpClear()
    EGP:egp3DTracker(1,vec())
    EGP:egpParent(1, entity())
    EGP:egpLine(2,vec2(0,-100000),vec2(0,100000))
    EGP:egpLine(3,vec2(-100000,0),vec2(100000,0))
    EGP:egpParent(2,1)
    EGP:egpParent(3,1)
    
    Plate = entity():isConstrainedTo()
    
    noCollideAll(Plate,1)
    
    Cons = Plate:getConstraints()
    for(I=1,Cons:count()+1)
    {
        noCollideAll(Cons[I,entity],1)
    }
    
    Secure = 1
    
}


Chat = owner():lastSaid()
Com = Chat:find("Athena")
if(Com & chatClk(owner()))
{
    ChatArgs = Chat:explode("|")
    if(ChatArgs[2,string] == "Secure")
    {
        Secure = 1
    }
    
    if(ChatArgs[2,string] == "Unsecure")
    {
        Secure = 0
    }
}

if(Swarm:isValid())
{
    Swarm:takeDamage(10000)
}

if(Secure == 1)
{
    Players = players()
    
    for(I=1,Players:count()+1)
    {
        Player = Players[I,entity]
        if(Player == owner() || owner():isSteamFriend(Player))
        {
            continue
        }
        else
        {
            if(Player:isPlayer() && Player:isAlive())
            {
                Detection = Player:eyeTrace()
                if(Detection:entity() == Plate || Detection:entity() == entity())
                {
                    if(Swarm:isValid() == 0)
                    {
                        if(Player:isPlayer())
                        {
                            Swarm = propSpawn("models/props_c17/oildrum001_explosive.mdl", Player:pos(),1)
                        }
                        Swarm:propGravity(0)
                    }
                }
            }
        }
    }
}
