@name ESP Test
@inputs 
@outputs 
@persist Own:entity Dist Entities:array
@trigger 
runOnTick(1)

timer("clean",60000)

if (clk("clean") | dupefinished()) {
    holoDeleteAll()
    reset()
}

if (first()) {
    Own = owner()
    Dist = 10
    entity():setAlpha(0)
    
    function array entity:projection(Distance)
    {
        local OwnPos = owner():shootPos()
        local EntPos = This:boxCenterW()
                
        local Direction = OwnPos + (EntPos - OwnPos):normalized() * Distance
        
        local Projection = positive((Distance * This:boxSize()) / (OwnPos:distance(EntPos)))
        
        local Angle = This:angles()
        
        return array(Direction, Projection, Angle)
    }
}

timer("entities",20000)

if (first() | clk("entities")) {
    findIncludeClass("printer")
    findIncludeClass("player")
    findInSphere(vec(),999999)
    
    Entities = findToArray()
}

for (I=1, Entities:count()) {
    Entity = Entities[I,entity]
    
    if (Entity != owner()) {
        ID = Entity:id()
        
        if (!holoEntity(ID)) {
            holoCreate(ID)
            holoAlpha(ID,50)
            holoDisableShading(ID,1)
            holoVisible(ID,players(),0)
            holoVisible(ID,Own,1)
        }
        
        holoColor(ID,teamColor(Entity:team()))
        
        Projection = Entity:projection(Dist)
        
        holoPos(ID,Projection[1,vector])
        holoScaleUnits(ID,Projection[2,vector])
        holoAng(ID,Projection[3,angle])
    }
}

