@name ULX Compact
@inputs 
@outputs 
@persist Selection:string ConfirmAction:string ConfirmUser:string ConfirmResponse:string
interval(1000)

## UPDATE INTERFACE ##
if(clk("interval")) {
    S = time("hour")+":"+time("min")+":"+time("sec"):toString()
    dText("TIME",S)
    S = numPlayers():toString() + " / " + maxPlayers():toString():sub(0,25)
    dText("PLAYERS",S)
    if(isLan()) { S = "True" }else{ S = "False" }
    dText("LAN",S)
    S = gamemode():sub(0,25)
    dText("GAMEMODE",S)
    S = map():sub(0,25)
    dText("MAPNAME",S)
    S = hostname():sub(0,25)
    dText("HOSTNAME",S)
    
    Userlist = array()
    Count = findByClass("player") #Collect players
    for(I=1, Count) {
        Ent = findResult(I)
        if(Ent:isPlayer()) {
            Err = 0
            for(X=1, Count) {
                if (Ent:name() == Userlist[X,string]) { Err = 1 }
            }
            if(Err == 0) { Userlist:pushString(Ent:name()) }
        }
    }
    dArray("Players",Userlist)
}
## END UPDATE INTERFACE ##


Selection = dSval("Players")

## COMMANDS ##
if(Selection:length() > 0 & !(Selection == "Players is a nil name")) {
    if(dClk("God")) { concmd("ulx god "+Selection) }
    if(dClk("Ungod")) { concmd("ulx ungod "+Selection) }
    if(dClk("Slap")) { concmd("ulx slap "+Selection) }
    if(dClk("Whip")) { concmd("ulx whip "+Selection) }
    if(dClk("Blind")) { concmd("ulx blind "+Selection) }
    if(dClk("Unblind")) { concmd("ulx unblind "+Selection) }
    if(dClk("Goto")) { concmd("ulx goto "+Selection) }
    if(dClk("Bring")) { concmd("ulx bring "+Selection) }
    if(dClk("Freeze")) { concmd("ulx freeze "+Selection) }
    if(dClk("Unfreeze")) { concmd("ulx unfreeze "+Selection) }
    if(dClk("Jail")) { concmd("ulx jail "+Selection) }
    if(dClk("Unjail")) { concmd("ulx unjail "+Selection) }
    if(dClk("Ragdoll")) { concmd("ulx ragdoll "+Selection) }
    if(dClk("Unragdoll")) { concmd("ulx unragdoll "+Selection) }
    if(dClk("Ignite")) { concmd("ulx ignite "+Selection) }
    if(dClk("Unignite")) { concmd("ulx unignite "+Selection) }
    
    if(dClk("CONFIRMYES")) { 
        ConfirmResponse = "yes"
        timer("CONFIRMRESPONSE",1) 
    }
    if(dClk("CONFIRMNO")) { 
        ConfirmResponse = "no"
        timer("CONFIRMRESPONSE",1) 
    }
    
    if(dClk("Kick")) { 
        ConfirmAction = "kick"
        ConfirmUser = Selection
        timer("confirm",1) }
    if(dClk("Ban (5m)")) { 
        ConfirmAction = "shortban"
        ConfirmUser = Selection
        timer("confirm",1) }
    if(dClk("Ban (60m)")) { 
        ConfirmAction = "longban"
        ConfirmUser = Selection
        timer("confirm",1) }
    if(dClk("Spectate")) { concmd("ulx spectate "+Selection) }
    #if(dClk("")) { concmd("ulx  "+Selection) }
}

if(clk("confirm")) {
    enableMouse(1)
    if(ConfirmAction == "kick") { S = "Are you sure you want to kick "+ConfirmUser+"?" }
    if(ConfirmAction == "shortban") { S = "Are you sure you want to ban "+ConfirmUser+" for 5 minutes?" }
    if(ConfirmAction == "longban") { S = "Are you sure you want to ban "+ConfirmUser+" for 60 minutes?" }
    dText("CONFIRMNOTE",S)
    dShow("Confirm Action", 1)
}
if(clk("CONFIRMRESPONSE")) {
    if (ConfirmResponse == "yes") {
        if(ConfirmAction == "kick") {
            concmd("ulx kick "+ConfirmUser)
        }
        if(ConfirmAction == "shortban") {
            concmd("ulx ban "+ConfirmUser+" 5")
        }
        if(ConfirmAction == "longban") {
            concmd("ulx kick "+ConfirmUser+" 60")
        }
    }
    enableMouse(0)
    dShow("Confirm Action", 0)
}

## END COMMANDS ##

if(clk("second")) {
    #dArray("Players",Userlist)
}

if(first()) {
    print("Please ensure that wire_expression2_concmd is set to 1 for this chip to function")
    W = 408
    H = 150
    
    dPanel("Confirm Action", vec2(640-(250/2),480-(80/2)), vec2(250,80))
    dLabel("CONFIRMNOTE","Confirm Action", vec2(5,25))
    dText("CONFIRMNOTE","XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
    dButton("CONFIRMYES","Confirm Action", vec2(35,50), vec2(50,20))
    dText("CONFIRMYES","Yes")
    dButton("CONFIRMNO","Confirm Action", vec2(165,50), vec2(50,20))
    dText("CONFIRMNO","No")
    dShow("Confirm Action", 0)
    
    dPanel("ULX", vec2(440,800), vec2(W,H))
    dColor("ULX", 64, 64, 64, 1)
    dTabHolder("Tab","ULX",vec2(78,0),vec2(W + 14 - 85,H + 7))
    dTab("Administration","Tab")
    #dTab("Map","Tab")
    dTab("Manage Users","Tab")
    
    #Users Panel#
    dListBox("Players","ULX",vec2(0,0),vec2(85,150))  ### Userlist:pushString(owner():name())
    Ox2 = 80
    
    Ox = 0
    Oy = 30*0
    dButton("Slap","Manage Users",vec2(5,5+Oy),vec2(75,24))
    dButton("Whip","Manage Users",vec2(5+Ox+Ox2,5+Oy),vec2(75,24))
    Ox = 0
    Oy = 30*1
    dButton("Blind","Manage Users",vec2(5,5+Oy),vec2(75,24))
    dButton("Unblind","Manage Users",vec2(5+Ox+Ox2,5+Oy),vec2(75,24))
    Ox = 0
    Oy = 30*2
    dButton("Bring","Manage Users",vec2(5,5+Oy),vec2(75,24))
    dButton("Goto","Manage Users",vec2(5+Ox+Ox2,5+Oy),vec2(75,24))
    Ox = 0
    Oy = 30*3
    dButton("Freeze","Manage Users",vec2(5,5+Oy),vec2(75,24))
    dButton("Unfreeze","Manage Users",vec2(5+Ox+Ox2,5+Oy),vec2(75,24))
    ##
    Ox = 160
    Oy = 30*0
    dButton("God","Manage Users",vec2(5+Ox,5+Oy),vec2(75,24))
    dButton("Ungod","Manage Users",vec2(5+Ox+Ox2,5+Oy),vec2(75,24))
    Ox = 160
    Oy = 30*1
    dButton("Jail","Manage Users",vec2(5+Ox,5+Oy),vec2(75,24))
    dButton("Unjail","Manage Users",vec2(5+Ox+Ox2,5+Oy),vec2(75,24))
    Ox = 160
    Oy = 30*2
    dButton("Ragdoll","Manage Users",vec2(5+Ox,5+Oy),vec2(75,24))
    dButton("Unragdoll","Manage Users",vec2(5+Ox+Ox2,5+Oy),vec2(75,24))
    Ox = 160
    Oy = 30*3
    dButton("Ignite","Manage Users",vec2(5+Ox,5+Oy),vec2(75,24))
    dButton("Unignite","Manage Users",vec2(5+Ox+Ox2,5+Oy),vec2(75,24))

    Userlist = array()
    Count = findByClass("player") #Collect players
    for(I=1, Count) {
        Ent = findResult(I)
        if(Ent:isPlayer()) {
            Err = 0
            for(X=1, Count) {
                if (Ent:name() == Userlist[X,string]) { Err = 1 }
            }
            if(Err == 0) { Userlist:pushString(Ent:name()) }
        }
    }
    
    #Admin Panel#
    Opacity = 75
    
    Ox = 70*0+85
    Oy = 20*0
    
    dLabel("Server","Administration",vec2(7+Ox,5+Oy))
    
    S = "Users"
    dLabel(S,"Administration",vec2(7+Ox,5+20+Oy))
    dColor(S,255,255,255,Opacity)
    dLabel("Map","Administration",vec2(7+Ox,5+40+Oy))
    
    S = "Gamemode"
    dLabel(S,"Administration",vec2(7+Ox,5+60+Oy))
    dColor(S,255,255,255,Opacity)
    
    dLabel("Local","Administration",vec2(7+Ox,5+80+Oy))
    
    S = "Server Time"
    dLabel(S,"Administration",vec2(7+Ox,5+100+Oy))
    dColor(S,255,255,255,Opacity)
   
 
    Ox = 70*1+85
    Oy = 20*0
    
    dLabel("HOSTNAME","Administration",vec2(7+Ox,5+Oy))
    dText("HOSTNAME","ZZZZZZZZZZZZZZZZZZ")
    
    S = numPlayers():toString() + " / " + maxPlayers():toString():sub(0,25)
    dLabel("PLAYERS","Administration",vec2(7+Ox,5+20+Oy))
    dText("PLAYERS","ZZZZZZZZZZZZZZZZZZ")
    dColor("PLAYERS",255,255,255,Opacity)
    
    dLabel("MAPNAME","Administration",vec2(7+Ox,5+40+Oy))
    dText("MAPNAME","ZZZZZZZZZZZZZZZZZZ")
    
    dLabel("GAMEMODE","Administration",vec2(7+Ox,5+60+Oy))
    dColor("GAMEMODE",255,255,255,Opacity)
    dText("GAMEMODE","ZZZZZZZZZZZZZZZZZZ")
    
    dLabel("LAN","Administration",vec2(7+Ox,5+80+Oy))
    dText("LAN","ZZZZZZZZZZZZZZZZZZ")
    
    S = time("hour")+":"+time("min")+":"+time("sec"):toString()
    dLabel("TIME","Administration",vec2(7+Ox,5+100+Oy))
    dText("TIME","ZZZZZZZZZZZZZZZZZZ")
    dColor("TIME",255,255,255,Opacity)
    
    Ox2 = 80
    
    dButton("Kick","Administration",vec2(5,5),vec2(75,24))
    dButton("Ban (5m)","Administration",vec2(5,35),vec2(75,24))
    dButton("Ban (60m)","Administration",vec2(5,65),vec2(75,24))
    dButton("Spectate","Administration",vec2(5,95),vec2(75,24))
    
    
    #Map Panel#
    
    timer("second",20)
}
