@name Chaqua Sentry
@persist [E O M Ba T]:entity
@persist S B N R
@persist FA:angle
@persist [WL WP]:array
if(first())
{
    runOnTick(1)
    runOnChat(1)
    
    E = entity()
    O = owner()
    
    holoCreate(1,E:toWorld(vec()),vec(1.25,1.25,0.75),E:toWorld(ang()))
    holoModel(1,"models/props_combine/combine_mortar01b.mdl")
    holoMaterial(1,"models/shiny")
    holoColor(1,vec(40,54,24))
    holoParent(1,E)
    
    Ba = holoCreate(2,E:toWorld(vec(0,0,44.25)),vec(1.5))
    holoModel(2,"hq_sphere")
    holoMaterial(2,"models/shiny")
    holoColor(2,vec(20,27,12))
    holoParent(2,E)
    
    holoCreate(3,holoEntity(2):toWorld(vec(24,0,0)),vec(1,1,4),E:toWorld(ang(90,0,0)))
    holoModel(3,"hq_tube_thin")
    holoMaterial(3,"models/shiny")
    holoColor(3,vec(20,27,12))
    holoParent(3,2)
    
    R = 1500
    
    WL = array(
    "STEAM_0:0:32759932",
    "STEAM_0:0:33397564",
    "STEAM_0:0:33994222",
    "STEAM_0:0:38933156"
    )
}

if(changed(numPlayers()))
{
    WP:clear()
    foreach(I, Ply:entity = players())
    {
        foreach(J, Str:string = WL)
        {
            if(Ply:steamID() == Str)
            {
                WP:pushEntity(Ply)
                break
            }
        }
    }
}

if(changed(R))
{
    setName("Chaqua Sentry
Radius: "+R)
}

if(chatClk())
{
    if(lastSpoke():team()==owner():team())
    {
        local LS = lastSaid():lower():explode(" ")
        
        if(LS[1,string]=="-r")
        {
            R = LS[2,string]:toNumber()
        }
    }
}

if(S)
{
    FA = (T:shootPos() - Ba:pos()):toAngle()
    
    if(!B & !M:isValid())
    {
        M = propSpawn("models/props_phx/ww2bomb.mdl",Ba:toWorld(vec(12,0,0)),FA,1)
        M:setTrails(10,100,3,"trails/smoke",vec(255),255)
        
        B = 1
        timer("ub",1500)
    }
    
    S = T:isAlive()
}else
{
    if(findCanQuery())
    {
        findByClass("player")
        findExcludeEntities(WP)
        findSortByDistance(Ba:pos())
        local F = find()
        
        S = F:pos():distance(Ba:pos())<R & F:isAlive()
        if(S)
        {
            T = F
        }
    }
    
    N++
    FA = ang(cos(N*2)*5,N/2,0)
}

if(M:isValid())
{
    local RD = rangerOffset(60,M:pos(),M:forward())
    if(RD:hit() | M:pos():distance(T:pos()) < 100)
    {
        M:propBreak()
    }else
    {
        M:setPos(M:toWorld(vec(50,0,0)))
        
        local A = (T:shootPos() - M:pos()):toAngle()
        M:setAng(M:toWorld(M:toLocal(A)/3))
    }
}

if(clk("ub"))
{
    stoptimer("ub")
    
    B = 0
}

holoAng(2,Ba:toWorld(Ba:toLocal(FA)/10))
