@name Bouches Gang EGP Forums
@inputs A:wirelink 
@persist Raid [Members Chat]:array Player:entity Chatsize MemberAmount  EGPPlace EGPX EGPY N Colour:vector MemberListCount

interval(500)
runOnChat(1)

function canHasBMD() {
    if(MemberAmount > 4) {
        A:egpText(10,"Yes",vec2(622,245))
        A:egpColor(10,vec(20,200,20))
        A:egpSize(10,60)
    } else {
        A:egpText(10,"No",vec2(640,245))
        A:egpColor(10,vec(200,20,20))
        A:egpSize(10,60)
    }
}

function memberAmount() {
    A:egpText(7,MemberAmount + "/"+ round(numPlayers()*0.30),vec2(625,40))
    A:egpSize(7,60)
    A:egpColor(7,vec(20,200,20))
}

function memberList() {
    if(MemberListCount < Members:count()) {
        MemberListCount = MemberListCount + 1
        A:egpText(EGPPlace,MemberListCount + ") "+ Members[MemberListCount,entity]:name(),vec2(EGPX,EGPY))
        A:egpSize(EGPPlace,50)
        A:egpColor(EGPPlace,vec(20,20,225))
        EGPY = EGPY + 50
        EGPPlace = EGPPlace + 1
        memberList()
    }
}

function toggleRaid() {
}

if(duped() || first() | inputClk() | clk("redraw"))  {
    printColor(vec(50,100,200),"")
    printColor(vec(20,200,20),"Commands:")
    printColor(vec(20,200,20),"    !add [name]         ; !add bouche")
    printColor(vec(20,200,20),"    !remove [name]   ; !remove bouche")
    printColor(vec(20,200,20),"    !name [name]      ; changes the name of the gang")
    printColor(vec(20,200,20),"    !clear                    ; clears list of names")
    printColor(vec(20,200,20),"    !raid                      ; plays sound and background colour changes")
    printColor(vec(20,200,20),"    !raid                      ; stops sound and background returns to normal")
    
    
    A:egpClear()
    A:egpRoundedBox(1,vec2(300,110),vec2(1150,510))
    A:egpColor(1,vec(60,60,60))
    A:egpRoundedBox(2,vec2(125,150),vec2(725,375))
    A:egpColor(2,vec(100,100,100))
    A:egpText(3,"|SniperGang|",vec2(-120, -140))
    A:egpSize(3,88)
    A:egpColor(3,Colour)
    A:egpText(4,"Members:",vec2(-220,-35))
    A:egpSize(4,60)
    A:egpColor(4,vec(20,20,225))
    
    EGPX = -210
    EGPY = 30
    EGPPlace = 11
    timer("start",1)
    
    A:egpRoundedBox(5,vec2(675,50),vec2(300,175))
    A:egpColor(5,vec(100,100,100))
    A:egpText(6,"Members:",vec2(550,-20))
    A:egpSize(6,60)
    A:egpColor(6,vec(20,200,20))
    memberAmount()
    A:egpRoundedBox(8,vec2(675,250),vec2(300,175))
    A:egpColor(8,vec(100,100,100))
    A:egpText(9,"BMD allowed:",vec2(540,188))
    A:egpColor(9,vec(20,200,20))
    A:egpSize(9,48)
    canHasBMD()
    Raid = 0
}

if(clk("start") & N < 360 | clk("restart")) {
    N = N + 5
    Colour=hsv2rgb(N,1,1)
    A:egpColor(3,Colour)
    timer("start",400)
} elseif(N == 360) {
    N = 0
    timer("restart",400)
}

if(chatClk(owner())){
    Chat = owner():lastSaid():explode(" ")
    Chatsize = Chat[2,string]:length()+Chat[3,string]:length()+Chat[4,string]:length()+Chat[5,string]:length()+Chat[6,string]:length()
    Player = findPlayerByName(Chat[2,string])
    if(Chat[1,string]=="!name") {
        A:egpText(3,Chat[2,string]+ " "+Chat[3,string]+ " "+Chat[4,string]+ " "+Chat[5,string]+ " "+Chat[6,string],vec2(250-(Chatsize*23), -140))
    } elseif(Chat[1,string]=="!raid") {
        hideChat(1)
        if(Raid == 0) {
            Raid = 1
            A:egpColor(1,vec(250,20,20))
            soundPlay(1,0,"ambient/alarms/alarm1.wav")
            soundVolume(1,0.3)
        } elseif (Raid == 1) {
            Raid = 0
            A:egpColor(1,vec(60,60,60))
            soundStop(1)
        }
    } elseif(Chat[1,string]=="!clear") {
        hideChat(1)
        printColor(vec(20,200,20),"List cleared!")
        MemberAmount = 0
        for(I = 1, Members:count()) {
            Members:remove(I)
        }
        timer("redraw",1)
    } elseif(Chat[1,string]=="!remove") {
        hideChat(1)
        if(Player:isPlayer()) {
            for(I = 1, Members:count()) {
                if(Members[I,entity]==Player) {
                    printColor(vec(20,200,20),Player:name()+ " removed from list.")
                    A:egpSetText(EGPPlace - 1,"")
                    Members:remove(I)
                    MemberAmount = MemberAmount - 1
                    MemberListCount = 0
                    EGPY = 30
                    EGPPlace = 11
                    memberList()
                    canHasBMD()
                    memberAmount()
                }
            }
        }
    } elseif(MemberAmount > 5) {
        printColor(vec(200,20,20),"Currently this E2 only supports up to 6 members!")
    } elseif(MemberAmount + 1 > round(numPlayers()*0.30)) {
        printColor(vec(200,20,20),"You can't have anymore members!")     
    } elseif(Chat[1,string]=="!add")  {
        hideChat(1)
        if(Player:isPlayer()) {
            printColor(vec(20,200,20),Player:name()+ " added to the list.")
            MemberAmount = MemberAmount + 1
            Members[MemberAmount,entity] = Player
            MemberListCount = 0
            EGPY = 30
            EGPPlace = 11
            memberList()
            canHasBMD()
            memberAmount()
        } elseif(!Player:isPlayer()) {
            printColor(vec(200,20,20),"This player is not on the server! (typo?)")
        }
    }
}

if(clk("start") & N < 360 | clk("restart")) {
    N = N + 5
    Colour=hsv2rgb(N,1,1)
    A:egpColor(3,Colour)
    timer("start",400)
} elseif(N == 360) {
    N = 0
    timer("restart",400)
}
