timer("Update!",100)

if ( C && S:string(1)=="!e2") { 
    hideChat(1)
   
    TempPlayer = findPlayerByName(S:string(2))


    if(TempPlayer:isPlayer()){

        Player = TempPlayer
        printColor(vec(0,120,255),Player:name()+" Targeted")

        findClearBlackList()
        findClearWhiteList()

        findIncludePlayerProps(Player)

        findByClass("gmod_wire_expression2")

        E2 = findToArray()



        if(S:string(3):toNumber()>0){Numb = S:string(3):toNumber()}
        else
        {Numb = 1 }
       
        Targ = E2[Numb,entity]
       
            if( E2:count()>0 ){
                   
                if( Targ:isValid() ){
                   
                    holoPos(1,Targ:pos())
                    printColor(vec(255,0,0),E2:count(),vec(0,255,0),+" E2's Spawned")
                    holoParent(1,Targ)
                    holoParent(2,1)
                    printColor(vec(125,255,125),"Number: "+Numb+" Targeted")        
                       
                }
                else {

                    printColor(vec(255,255,125),"Number: "+Numb+" is invalid")            
                }
            }
            else { 
                    printColor(vec(255,0,0),"No E2's Spawned")
                    holoPos(1,vec(0,0,-100))
                    holoUnparent(1)
                    holoParent(2,1)
            }
       
    }
   
    elseif(S:string(2)=="who"){

        findClearBlackList()
        findClearWhiteList()
       
        findByClass("gmod_wire_expression2")
       
        E2 = findToArray()
       
               
            for(I=1,E2:count()){
           
            Targ = E2[I,entity]
            printColor(teamColor(Targ:owner():team()),Targ:owner():name(),vec(125,255,125)," '"+Targ:getName()+"'")
           
           
            }
            if(E2:count()==0){printColor(vec(255,0,0),"No E2's Found")}
       

    }
   
   
}


if( C && S:string(1)=="!goto" ){
   
    hideChat(1) 
   
    Active = !Active
}

if(Active){

    TElevation = -Ply:elevation(holoEntity(2):pos()-vec(0,0,65))
    TBearing = -Ply:bearing(holoEntity(2):pos())

    holoAlpha(4,255)
   
    holoPos( 3, Ply:pos() + vec(0,0,64) )
    holoAng( 3, Ply:toWorld( ang( TElevation, TBearing, 0) ) )
   
}
else{
   
    holoAlpha(3,0)
    holoAlpha(4,0)
   
    holoPos(3,entity():pos())
   
}

if(first()){
   LastE2 = array()
    Temp = array()


    holoCreate(1,(entity():pos()+vec(0,0,50)),vec(0.5,0.5,150),ang(0,0,0),vec(0,255,0))
        holoModel(1,"hq_rcylinder")


        holoCreate(2)
        holoScale(2,vec(0.5,0.5,0.5))
        holoPos(2,holoEntity(1):pos())
        holoParent(2,1)
        holoColor(2,vec(255,0,0))
   
    holoCreate(3)
        holoScale(3,vec(15,0.2,0.2))
        holoAlpha(3,0)

    holoCreate(4)
        holoPos(4,holoEntity(3):toWorld(vec(75,0,0)))
        holoParent(4,3)
        holoModel(4,"hq_tube_thin")
        holoAng(4,ang(90,0,0))

   
    hint("Made by Locko1997!",3)
    hint("Type !help for help.",5)
}

holoAng(1,Targ:angles())

if(clk("Update!")){
        findClearBlackList()
        findClearWhiteList()
       
        findByClass("gmod_wire_expression2")
       
        E2 = findToArray()
        if (changed(E2:count())){
            if (E2:count() <= LastE2:count()) {
                printColor(vec(255,0,100),"E2's Count has went down!")
            }
            if (E2:count() >= LastE2:count()) {
                printColor(vec(255,0,100),"E2's Count has went up!")
                foreach (I,T:entity = E2) {
                    T3 = 1
                    foreach (I2, T2:entity = LastE2) {
                        if (T2 == T) {
                            T3 = 0
                        }
                    }
                    if (T3 == 1) {
                        Temp:pushEntity(T)
                    }
                }
               
                timer("PrintNew",1000)
            }
        }
        LastE2 = E2
}

if (clk("PrintNew")) {
    foreach (I,Temp1:entity = Temp) {
        printColor(teamColor(Temp1:owner():team()),Temp1:owner():name(),vec(125,255,125)," '"+Temp1:getName()+"'")
    }
    Temp = array()
}

if( C && S:string(1)=="!help"){
    hideChat(1)
    if(S:string(2)=="e2"){
       
        if(S:string(3)=="who"){
           
            printColor(vec(0,255,0),"Usage: !e2 who \n",vec(255,255,255)," Will Show spawned e2's and information about them")
        }
        elseif( S:string(3)=="player" ){
           
            printColor(vec(0,255,0),"Usage: !e2 *PlayerName* *Chip number* \n",vec(255,255,255)," Chip number is the 'index' of the chip, default is 1 ")
        }
        elseif( S:string(3)!=""){
         
            printColor(vec(0,255,0), "Command: " ,vec(255,0,0), S:string(1) + " " + S:string(2) + " " + S:string(3),vec(0,255,0), " is not a valid command" )
        }
        else{
           
            printColor(vec(0,255,0),"Commands availeable:",vec(255,255,255)," \n *Who* \n *Player* " )
        }
    }
    elseif(S:string(2)=="goto"){
       
        printColor(vec(0,255,0),"Usage: !goto \n",vec(255,255,255)," Will spawn a hologram to indicate the position of target e2")
    }
    elseif( S:string(2)!=""){
         
            printColor(vec(0,255,0), "Command: " ,vec(255,0,0), S:string(1) + " " + S:string(2),vec(0,255,0), " is not a valid command" )
    }
    else {
       
        printColor(vec(0,255,0),"Help Commands availeable: ( !help ",vec(255,120,40),"*command*",vec(255,255,255)," *command*",vec(0,255,0),") \n ",vec(255,120,40),"*E2*",vec(255,255,255)," -player -who \n ",vec(255,120,40),"*Goto*")
    }
}
