@name Prop Hunt Disguise
@inputs
@outputs  [Hide Active Holo Lock]:table [Plp Pl Pln]:array Past:string
@persist [Hide Z Lock Holo Active]:table [Plp Pl Pln]:array 
@trigger 
runOnTick(1)
runOnLast(1)
runOnChat(1)

Plp=Pln:clone() #players past

Pl=players() #players
if(Pln:count()!=Pl:count()){
    for(C=1,Pl:count()){Pln[C,number]=Pl[C,entity]:id()}
}
Fri=owner():friends()
 Past=Pln:concat("<")
if(Pl:count()<Plp:count()){
    Pln=array()
    foreach(K,Vn:number=Holo){
        if(!entity(K:toNumber())){print(K+" has left")}
    }
    
}
for(C=1,Pl:count()){
    
    Pla=Pl[C,entity]
    Chat=Pla:lastSaid()
    Pls=toString(Pla:id())
    Aim=Pla:aimEntity()
    if(Pl:count()>Plp:count()){
        Pla:chatPrint("type /help for Prop Hunt options")
        for(C=1,Pl:count()){
            Active[C,number]=1
        } 
    }

    
    if(Aim){BoxC=Aim:boxCenter() BoxS=Aim:boxSize() BoxMin=Aim:boxMin() BoxMax=Aim:boxMax() P=Aim:pos()}
    
    if(((changed(Pla:isAlive())&Pla:isAlive())|!Active[Pls,number]&holoEntity(Pla:id()))|last()){
        holoDelete(Pla:id())
        if(Pla:getAlpha()!=255){
            Command="ulx uncloak \""+Pla:name()
            #print(Command)
            concmd(Command)
        }
        #Pla:setMaterial("")
        #Pla:setColor(vec(1,1,1)*255,255)
        
        Pla:weapon():setAlpha(255)
    }
    if(Active[Pls,number]){
        if(holoEntity(Pla:id())){
            
            holoVisible(Pla:id(),Pl,1)
            holoVisible(Pla:id(),Pla,Hide[Pls,number])
            holoPos(Pla:id(),Pla:pos()-vec(0,0,Z[Pls,vector]:z()))
            if(!Lock[Pls,number]){holoAng(Pla:id(),Pla:angles())}
        }
        if(changed(Pla:keyUse())&Aim:type()=="prop_physics"&Pla:keyUse()&Aim&Pla:pos():distance(Aim:pos())<200){
            Z[Pls,vector]=Aim:aabbMin()
            Holo[Pla:id(),number]=1
            
            
            if(Pla:getAlpha()!=0){
                
                Command="ulx cloak \""+Pla:name()
                #print(Command)
                concmd(Command)
            }
            #Pla:setMaterial("models/props_c17/frostedglass_01a")
            #Pla:setColor(vec(1,1,1)*0)
            #Pla:setColor(vec(),0)
            Pla:weapon():setAlpha(0)
            if(!holoEntity(Pla:id())){
                holoCreate(Pla:id(),Pla:pos())
            }
            holoModel(Pla:id(),Aim:model(),1)
            if(Hide[Pls,number]){H=Hide[Pls,number]}else{H=1}
            holoVisible(Pla:id(),Pla,H)
        }
    }
    if(chatClk()){
        if(Chat=="/lock"){Lock[Pls,number]=1 Pla:chatPrint("your disguise's angle is locked!")}
        if(Chat=="/unlock"){Lock[Pls,number]=0 Pla:chatPrint("your disguise's angle is unlocked!")}
        if(Chat=="/show"){
            holoVisible(Pla:id(),Pla,1)
            Hide[Pls,number]=1
        }
           if(Chat=="/out"){Active[Pls,number]=0 Pla:chatPrint("you've opted out of prop hunt")}
        if(Chat=="/in"){Active[Pls,number]=1 Pla:chatPrint("you've opted into prop hunt")}
        if(Chat=="/remove"){
            holoDelete(Pla:id())
            Holo:remove(Pla:id())
            Pla:setMaterial("")
            Pla:setColor(vec(1,1,1)*255)
            Pla:weapon():setAlpha(255)
            if(Pla:getAlpha()!=255){
                Command="ulx uncloak \""+Pla:name()
                #print(Command)
                concmd(Command)
           }
        }
        if(Chat=="/hide"){
            holoVisible(Pla:id(),Pla,0)
            Hide[Pls,number]=0
        }
        if(Chat=="/help"){
            Pla:chatPrint("type:")
            Pla:chatPrint("/show  -  to show your disguise to you")
            Pla:chatPrint("/hide  -  to hide your disguise from your view")
            Pla:chatPrint("/lock  -  to prevent the disguise from rotating with you")
            Pla:chatPrint("/unlock  -   allows the disguise to rotate with you")
            Pla:chatPrint("/remove  -  to undisguise")
            Pla:chatPrint("/out  -  to opt out of prop hunt")
            Pla:chatPrint("/in  -  to opt into prop hunt")
            Pla:chatPrint("To Disguise walk up close to a prop and press the use key.")
            
           
        }
     
    }

}


