@name World of Hats
@persist [Holos Active]:table

if(first()) {
    concmd("say \"/advert Say !hats to toggle HAT-VISION (TM)!\"")
    local HoloID=0
    foreach(I,A:entity=players()) {
        HoloID++
        local Pos=A:attachmentPos("eyes")
        local Ang=A:attachmentAng("eyes")
        local FinPos=toWorld(vec(-4,0,-3.5),Ang,Pos,Ang)
        local FinAng=Ang
        holoCreate(HoloID,FinPos,vec(1),FinAng,vec(255),"models/player/items/sniper/bio_sniper_boater.mdl")
        holoScale(HoloID,vec(0.95))
        holoParentAttachment(HoloID,A,"eyes")
        holoVisible(HoloID,players(),0)
        
        Holos[A:steamID(),number]=HoloID
    }
    
    #holoVisible(1,A,0)
    entity():setAlpha(0)
    entity():propNotSolid(1)
    
    function activate(E:entity) {
        local Steam=E:steamID()
        local ActiveState=!Active[Steam,number]
        Active[Steam,number]=ActiveState
        #print(E:name(),ActiveState)
        foreach(I,V:number=Holos) {
            if(I==Steam){continue}
            holoVisible(V,E,ActiveState)
        }
        local Str="ulx psay \""+E:name()+"\" \""+"Hats have been turned "+(ActiveState ? "on" : "off")+"!\""
        #print(Str)
        concmd(Str)
    }
    
    #activate(owner())
}

runOnChat(1)

if(chatClk() & lastSaid():matchFirst("!hats")) {
    activate(lastSpoke())
}
