@name Tag
@outputs Var
@persist [O,T,T2]:entity Ply:array Delay Var

if(first()) {
    runOnTick(1)
    runOnChat(1)
    O=owner()
    T = O
    Ply:pushEntity(O)
    
    holoCreate(1,O:pos(),vec(1,1,1),ang(180,0,0),vec(0  ,255,0),"tetra")
    
    Ply = players()
    
    holoParent(1,O)
}

holoPos(1,T:pos()+vec(0,0,sin(curtime()*100)*10+100))

if(!Delay) {
    for(I=1,Ply:count()) {
        if(T:pos():distance(Ply[I,entity]:pos())<200&T:aimEntity()==Ply[I,entity]&T:keyUse()) {
            T=Ply[I,entity]
            
            holoParent(1,T)
            holoColor(1,vec(255,0,0))
            
            concmd("say "+T:name()+" is now tagger!")
            
            Delay = 1
            timer("delay",7000)
        }
    }
}
if(T:vel():length()==0&!changed(T:eyeAngles())&!T:isTyping()) {
    Var++
    if(Var>1000) {
        T = Ply[randint(1,Ply:count()),entity]
        holoParent(1,T)
        holoColor(1,vec(255,0,0))
        Delay = 1
        timer("delay",7000)
        concmd("say The tagger has been afk for too long! New tagger is "+T:name())
    }
}
else {
    Var = 0
}
if(Delay==1) {
    if(clk("delay")) {
        Delay=0
        holoColor(1,vec(0,255,0))
    }
}
