@name EGP GangList
@inputs EGP:wirelink
@outputs 
@persist List:array Z
@trigger 

interval(1000)
if (first() || changed(EGP:entity()) || changed(List:count()))
{
    # Clear the EGP screen
    EGP:egpClear()
    
    #Run on chat commands
    runOnChat(1)
    
    # Background Boxes
    EGP:egpRoundedBox(1,vec2(256,256),vec2(512,512))
    EGP:egpColor(1,vec(100,0,0))
    EGP:egpRoundedBox(2,vec2(256,256),vec2(500,500))
    EGP:egpColor(2,vec(255,255,255))
    
    # Top Title Boxes + Title
    EGP:egpRoundedBox(3,vec2(256,40),vec2(490,50))
    EGP:egpColor(3,vec(100,0,0))
    EGP:egpRoundedBox(4,vec2(256,40),vec2(480,40))
    EGP:egpText(5,"Gang List - Gang Members: " + List:count(),vec2(45,25))
    EGP:egpColor(5,vec(100,100,100))
    EGP:egpFont(5,"ChatFont",28)
    
    # Main Body Boxes
    EGP:egpRoundedBox(6,vec2(256,285),vec2(490,430))
    EGP:egpColor(6,vec(100,0,0))
    EGP:egpRoundedBox(7,vec2(256,285),vec2(480,420))
    EGP:egpColor(7,vec(255,255,255))
    
    # Main Body Titles
    EGP:egpText(8,"Gang Member",vec2(25,80))
    EGP:egpColor(8,vec(100,100,100))
    EGP:egpFont(8,"Coolvetica",20)
    
    # Hints
    print("--- [Gang List] ---")
    print("Usage: -add <playername>")
    print("Usage: -rem <playername>")
    print("Erza")
    
    
    # List the members
    for(I=1,List:count())
    {
        Ply = List[I,entity]
        if (Ply:isPlayer())
        {
            EGP:egpText(I+10,""+Ply:name(),vec2(25,80 + 22 * I))
            EGP:egpColor(I+10,teamColor(Ply:team()))
            EGP:egpFont(I+10,"Coolvetica",18)
        }
        else
        {
            print("--- [Gang List] ---")
            print("Removed Offline Player")
            List:remove(I)            
        }
    }      
}

# If Owner Talks
if (chatClk(owner()))
{ 
    # Chat String
    Str = owner():lastSaid():explode(" ")
    
    # Add Players
    if(Str[1,string]=="-add")
    {
        TP = findPlayerByName(Str[2,string])
        if(TP:isPlayer())
        {
            print("--- [Gang List] ---")
            print("Added: " + TP:name())
            List:pushEntity(TP) 
            soundPlay(2,1,"/hl1/fvox/activated.wav")
        }        
    }
    
    #Remove Players
    if(Str[1,string]=="-rem")
    {
        TP = findPlayerByName(Str[2,string])
        if(TP:isPlayer())
        {
            while(Z < 50)
            {
                if(TP == List[Z,entity])
                {
                    print("--- [Gang List] ---")
                    print("Removed: " + TP:name())
                    List:remove(Z)
                    soundPlay(2,1,"/hl1/fvox/deactivated.wav")
                }
                Z++
            }
        }
        Z = 0
    }
}


