@name Build Protection v2
@inputs 
@outputs User:entity 
@persist [CornerPos1 CornerPos2]:vector On 
@trigger 
runOnTick(1)
runOnChat(1)

if (first()) {
    Scale = vec(50) * 12
    
    Holo = holoCreate(1)
    
    holoScale(1,Scale)
    holoPos(1,entity():toWorld(vec(-10,15,40)))
    holoAng(1,entity():angles())
    holoColor(1,vec(255,255,255),255)
    holoParent(1,entity())
    
    CornerPos1 = Scale / 2
    CornerPos2 = -CornerPos1
    
    CornerPos1 = Holo:toWorld(CornerPos1)
    CornerPos2 = Holo:toWorld(CornerPos2)
    
    CornerScale = vec() + 1
    
    holoCreate(2)
    holoPos(2,CornerPos1)
    holoScale(2,CornerScale)
    holoParent(2,Holo)
    
    holoCreate(3)
    holoPos(3,CornerPos2)
    holoScale(3,CornerScale)
    holoParent(3,Holo)
    
    for (I = 2,3) {holoColor(I,vec(),0)}
    
    holoCreate(4)
    holoScale(4,-Scale)
    holoMaterial(4,"models/wireframe")
    holoPos(4,entity():toWorld(vec(-10,15,40)))
    holoAng(4,entity():angles())
    holoColor(4,vec(255,255,255),255)
    holoParent(4,entity())
}

findInBox(CornerPos1,CornerPos2)
findIncludeClass("player")
findExcludePlayer(owner())
User = findClosest(holoEntity(1):pos())

if (lastSaid():left(1) == "!" & chatClk(owner())) {
    hideChat(1)
    if (lastSaid():lower() == "!on") {On = 1,print("BuildSphere activated!")}
    if (lastSaid():lower() == "!off") {On = 0,print("BuildSphere deactivated!")}
    if (lastSaid():lower() == "!color") {holoColor(1,vec(random(255),random(255),random(255))),holoColor(2,holoEntity(1):getColor())}
}

if (changed(User) & User & On) {
    Slay = findToArray():count()
    Name = find():name()
    Find = find()
    
    if (Slay & $Slay) {concmd("say !slay " + Name)}
}
