@name CLIO
@inputs P KB Sc:wirelink U:entity
@outputs Kick
@persist Btd X Y LnR LRCP SO [IK YN WD M]:array St:string


#[
 ___      ____  __
/    |     |   /  \
|    |     |   |  |
\___ \___ _|__ \__/

Command Line Interface Of Expression 2

Created by Blue_Skies, 2012
With help from SHOOP DA WHOOP

]#

runOnTick(1)

if(first()){     #Key number, always "invalid"         
    IK:setString(0,"invalid")
    IK:setString(1,"invalid")
    IK:setString(2,"invalid")
    IK:setString(3,"invalid")
    IK:setString(4,"invalid")
    IK:setString(5,"invalid")
    IK:setString(6,"invalid")
    IK:setString(7,"invalid")
    IK:setString(9,"invalid")
    IK:setString(10,"invalid")
    IK:setString(11,"invalid")
    IK:setString(12,"invalid")
    IK:setString(13,"invalid")
    IK:setString(14,"invalid")
    IK:setString(15,"invalid")
    IK:setString(16,"invalid")
    IK:setString(17,"invalid")
    IK:setString(18,"invalid")
    IK:setString(19,"invalid")
    IK:setString(20,"invalid")
    IK:setString(21,"invalid")
    IK:setString(22,"invalid")
    IK:setString(23,"invalid")
    IK:setString(24,"invalid")
    IK:setString(25,"invalid")
    IK:setString(26,"invalid")
    IK:setString(27,"invalid")
    IK:setString(28,"invalid")
    IK:setString(29,"invalid")
    IK:setString(30,"invalid")
    IK:setString(31,"invalid")
    IK:setString(127,"invalid")
    IK:setString(128,"invalid")
    IK:setString(129,"invalid")
    IK:setString(130,"invalid")
    IK:setString(131,"invalid")
    IK:setString(132,"invalid")
    IK:setString(133,"invalid")
    IK:setString(134,"invalid")
    IK:setString(135,"invalid")
    IK:setString(136,"invalid")
    IK:setString(137,"invalid")
    IK:setString(138,"invalid")
    IK:setString(144,"invalid")
    IK:setString(145,"invalid")
    IK:setString(146,"invalid")
    IK:setString(147,"invalid")
    IK:setString(148,"invalid")
    IK:setString(149,"invalid")
    IK:setString(150,"invalid")
    IK:setString(151,"invalid")
    IK:setString(152,"invalid")
    IK:setString(153,"invalid")
    IK:setString(154,"invalid")
    IK:setString(158,"invalid")
    IK:setString(161,"invalid")
    IK:setString(162,"invalid")
    IK:setString(163,"invalid")
    IK:setString(164,"invalid")
    IK:setString(165,"invalid")
    IK:setString(166,"invalid")
    IK:setString(167,"invalid")
    IK:setString(168,"invalid")
    IK:setString(169,"invalid")
    IK:setString(170,"invalid")
    IK:setString(171,"invalid")
    IK:setString(172,"invalid")
    IK:setString(173,"invalid")
    IK:setString(174,"invalid")
    IK:setString(175,"invalid")
    IK:setString(176,"invalid")
    IK:setString(177,"invalid")
    IK:setString(178,"invalid")
    
    YN:setString(0,"No")
    YN:setString(1,"Yes")
    
    WD:setString(1,"Sunday")
    WD:setString(2,"Monday")
    WD:setString(3,"Tuesday")
    WD:setString(4,"Wednesday")
    WD:setString(5,"Thursday")
    WD:setString(6,"Friday")
    WD:setString(7,"Saturday")
    
    M:setString(1,"January")
    M:setString(2,"February")
    M:setString(3,"March")
    M:setString(4,"April")
    M:setString(5,"May")
    M:setString(6,"June")
    M:setString(7,"July")
    M:setString(8,"August")
    M:setString(9,"September")
    M:setString(10,"October")
    M:setString(11,"November")
    M:setString(12,"December")
    
    Y = 3
    X = 184
    LnR = 0
    Sc:writeCell(2045,X)
    Sc:writeCell(2044,0.25)
    Sc:writeCell(2043,1)
}
if(~P){
    if(!P){
        LnR = 0
        X = 184
        Btd = 0
        St = ""
        Y = 3
        Kick = 1
        Sc:writeCell(2041,1)
        Sc:writeCell(2046,0)
        Sc:writeCell(2045,X)
        soundPurge()
    }
    elseif(P){
        Kick = 0
        LnR = 0
        Sc:writeCell(2041,0)
        Sc:writeString(":#Booting CLIO...",0,0,999)
        timer("boot",3000)
    }
}
if(changed(Btd) & Btd & P){
    Sc:writeString(":#Boot complete.",0,1,999)
    Sc:writeString(":#Created by ",0,2,999)
    Sc:writeString("Blue_Skies",13,2,9)
    Sc:writeString(", 2012",23,2,999)
    Sc:writeString(":>",0,3,999)
    SO = 1
}
#CLIO's core
if(Btd & P){
    Sc:writeCell(2045,X)
    Sc:writeCell(2043,0.25)
    Sc:writeCell(2046,1)
    #Op counter
    if(SO){
        Sc:writeString("Ops: "+ops():toString(),0,17,999)
    }
    elseif(!SO){
        Sc:writeCell(2039,17)
    }
    if(~KB){
        #Commands & errors
        if(KB == 13){
            #Basic commands
            I = St:lower()
            if(I == "testcmd"){
                Sc:writeString(":#Test successful.",0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "players"){
                Sc:writeString(":#"+players():count()+"/"+maxPlayers()+" players",0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "ping"){
                Sc:writeString(":#"+U:ping():toString()+" ms",0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "cakestatus"){
                Sc:writeString(":#The cake is a lie.",0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "friends"){
                Sc:writeString(":#Friends: "+U:friends():count():toString(),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "gravity"){
                Sc:writeString(":#Gravity: "+gravity(),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "dedicated"){
                Sc:writeString(":#"+YN:string(isDedicated()),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "lan"){
                Sc:writeString(":#"+YN:string(isLan()),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "admins"){
                Sc:writeString(":#"+playersAdmins():count():toString(),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "map"){
                Sc:writeString(":#"+map(),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "opcounter"){
                if(SO){
                    SO = 0
                    Sc:writeString(":#Op counter disabled.",0,Y + 1,999)
                    timer("cmd",0)
                }
                elseif(!SO){
                    SO = 1
                    Sc:writeString(":#Op counter enabled.",0,Y + 1,999)
                    timer("cmd",0)
                }
            }
            elseif(I == "date"){
                Sc:writeString(":#"+WD:string(time("wday"))+", "+M:string(time("month"))+" "+time("day")+", "+time("year"),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "eudate"){
                Sc:writeString(":#"+WD:string(time("wday"))+", "+time("day")+" "+M:string(time("month"))+", "+time("year"),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "time"){
                Sc:writeString(":#"+time("hour")+":"+time("min")+":"+time("sec"),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "steamid"){
                Sc:writeString(":#"+U:steamID(),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "gamemode"){
                Sc:writeString(":#"+gamemode(),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "propgravity"){
                Sc:writeString(":#"+propGravity(),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "airdensity"){
                Sc:writeString(":#"+airDensity(),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "pvp"){
                Sc:writeString(":#"+YN:string(playerDamage()),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "issp"){
                Sc:writeString(":#"+YN:string(isSinglePlayer()),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "help"){
                Sc:writeString(":#Type 'exit' or 'quit' to leave.",0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I == "stop"){
                Sc:writeString(":#Sound stopped.",0,Y + 1,999)
                soundStop("m")
                timer("cmd",0)
            }
            elseif(I == "nope.avi"){
                Sc:writeString(":#NOPE",0,Y + 1,999)
                soundPlay("nope",0,"vo/engineer_no01.wav")
                timer("nope",369)
            }
            elseif(I == "exit" | I == "quit"){
                Sc:writeString(":#You have left.",0,Y + 1,999)
                timer("cmd",0)
                timer("kick",1)
                Kick = 1
            }
            #"Input" commands
            elseif(I:left(5) == "hash "){
                Sc:writeString(":#"+hash(I:right(I:length() - 5)),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I:left(4) == "cmd "){
                if(U != owner()){
                    Sc:writeString(":#Error: invalid user.",0,Y + 1,999)
                    timer("error",0)
                }
                elseif(!concmd(I:right(I:length() - 4))){
                    Sc:writeString(":#Error: invalid argument.",0,Y + 1,999)
                    timer("error",0)
                }
                elseif(U == owner()){
                    Sc:writeString(":#Operation successful.",0,Y + 1,999)
                    timer("cmd",0)
                    concmd(I:right(I:length() - 4))
                }
            }
            elseif(I:left(5) == "sqrt "){
                if(sqrt((I:right(I:length() - 5)):toNumber())){
                    Sc:writeString(":#"+sqrt((I:right(I:length() - 5)):toNumber()),0,Y + 1,999)
                    timer("cmd",0)
                }
                elseif(!sqrt((I:right(I:length() - 5)):toNumber())){
                    Sc:writeString(":#Error: invalid argument.",0,Y + 1,999)
                    timer("error",0)
                }
            }
            elseif(I:left(5) == "cbrt "){
                if(cbrt((I:right(I:length() - 5)):toNumber())){
                    Sc:writeString(":#"+cbrt((I:right(I:length() - 5)):toNumber()),0,Y + 1,999)
                    timer("cmd",0)
                }
                elseif(!cbrt((I:right(I:length() - 5)):toNumber())){
                    Sc:writeString(":#Error: nvalid argument.",0,Y + 1,999)
                    timer("error",0)
                }
            }
            elseif(I:left(9) == "fromchar "){
                Sc:writeString(":#"+toByte(I:right(I:length() - 9)),0,Y + 1,999)
                timer("cmd",0)
            }
            elseif(I:left(7) == "tochar "){
                if(toChar((I:right(I:length() - 7):toNumber()))){
                    if(!IK:exists((I:right(I:length() - 7):toNumber()))){
                        Sc:writeString(":#"+toChar((I:right(I:length() - 7)):toNumber()),0,Y + 1,999)
                        timer("cmd",0)
                    }
                }
                elseif(!toChar((I:right(I:length() - 7):toNumber()))){
                    Sc:writeString(":#Error: invalid argument.",0,Y + 1,999)
                    timer("error",0)
                }
                elseif(IK:exists((I:right(I:length() - 7):toNumber()))){
                    Sc:writeString(":#Error: invalid argument.",0,Y + 1,999)
                    timer("error",0)
                }
            }
            elseif(I:left(5) == "play "){
                Mu = I:right(I:length() - 5)
                if(Mu == "bongo"){
                    soundPlay("m",0,"ambient/music/bongo.wav")
                    Sc:writeString(":#Sound playing...",0,Y + 1,999)
                }
                elseif(Mu == "country"){
                    soundPlay("m",0,"ambient/music/country_rock_am_radio_loop.wav")
                    Sc:writeString(":#Sound playing...",0,Y + 1,999)
                }
                elseif(Mu == "cuban"){
                    soundPlay("m",0,"ambient/music/cubanmusic1.wav")
                    Sc:writeString(":#Sound playing...",0,Y + 1,999)
                }
                elseif(Mu == "dust1"){
                    soundPlay("m",0,"ambient/music/dustmusic1.wav")
                    Sc:writeString(":#Sound playing...",0,Y + 1,999)
                }
                elseif(Mu == "dust2"){
                    soundPlay("m",0,"ambient/music/dustmusic2.wav")
                    Sc:writeString(":#Sound playing...",0,Y + 1,999)
                }
                elseif(Mu == "dust3"){
                    soundPlay("m",0,"ambient/music/dustmusic3.wav")
                    Sc:writeString(":#Sound playing...",0,Y + 1,999)
                }
                elseif(Mu == "flamenco"){
                    soundPlay("m",0,"ambient/music/flamenco.wav")
                    Sc:writeString(":#Sound playing...",0,Y + 1,999)
                }
                elseif(Mu == "latin"){
                    soundPlay("m",0,"ambient/music/latin.wav")
                    Sc:writeString(":#Sound playing...",0,Y + 1,999)
                }
                elseif(Mu == "hellhound"){
                    soundPlay("m",0,"ambient/music/hellhound.wav")
                    Sc:writeString(":#Sound playing...",0,Y + 1,999)
                }
                elseif(Mu == "portal"){
                    soundPlay("m",0,"ambient/music/looping_radio_mix.wav")
                    Sc:writeString(":#Sound playing...",0,Y + 1,999)
                }
                elseif(Mu == "piano1"){
                    soundPlay("m",0,"ambient/music/piano1.wav")
                    Sc:writeString(":#Sound playing...",0,Y + 1,999)
                }
                elseif(Mu == "piano2"){
                    soundPlay("m",0,"ambient/music/piano2.wav")
                    Sc:writeString(":#Sound playing...",0,Y + 1,999)
                }
                elseif(Mu == "standby"){
                    soundPlay("m",0,"ambient/music/standby.wav")
                    Sc:writeString(":#Sound playing...",0,Y + 1,999)
                }
                else{
                    Sc:writeString(":#Error: invalid sound.",0,Y + 1,999)
                    timer("error",0)
                }
            }
            #"Player input" commands
            elseif(I:left(5) == "team "){
                Ply = findPlayerByName(I:right(I:length() - 5))
                if(Ply){
                    Sc:writeString(":#"+Ply:team():teamName(),0,Y + 1,999)
                    timer("cmd",0)
                }
                elseif(!Ply){
                    Sc:writeString(":#Error: no target.",0,Y + 1,999)
                    timer("error",0)
                }
            }
            elseif(I:left(6) == "frags "){
                Ply = findPlayerByName(I:right(I:length() - 6))
                if(Ply){
                    Sc:writeString(":#"+Ply:frags():toString(),0,Y + 1,999)
                    timer("cmd",0)
                }
                elseif(!Ply){
                    Sc:writeString(":#Error: no target.",0,Y + 1,999)
                    timer("error",0)
                }
            }
            elseif(I:left(7) == "deaths "){
                Ply = findPlayerByName(I:right(I:length() - 7))
                if(Ply){
                    Sc:writeString(":#"+Ply:deaths():toString(),0,Y + 1,999)
                    timer("cmd",0)
                }
                elseif(!Ply){
                    Sc:writeString(":#Error: no target.",0,Y + 1,999)
                    timer("error",0)
                }
            }
            elseif(I:left(8) == "isadmin "){
                Ply = findPlayerByName(I:right(I:length() - 8))
                if(Ply){
                    Sc:writeString(":#"+YN:string(Ply:isAdmin()),0,Y + 1,999)
                    timer("cmd",0)
                }
                elseif(!Ply){
                    Sc:writeString(":#Error: no target.",0,Y + 1,999)
                    timer("error",0)
                }
            }
            elseif(I:left(13) == "issuperadmin "){
                Ply = findPlayerByName(I:right(I:length() - 13))
                if(Ply){
                    Sc:writeString(":#"+YN:string(Ply:isSuperAdmin()),0,Y + 1,999)
                    timer("cmd",0)
                }
                elseif(!Ply){
                    Sc:writeString(":#Error: no target.",0,Y + 1,999)
                    timer("error",0)
                }
            }
            elseif(I:left(8) == "steamid "){
                Ply = findPlayerByName(I:right(I:length() - 8))
                if(Ply){
                    Sc:writeString(":#"+Ply:steamID(),0,Y + 1,999)
                    timer("cmd",0)
                }
                elseif(!Ply){
                    Sc:writeString(":#Error: no target.",0,Y + 1,999)
                    timer("error",0)
                }
            }
            elseif(I:left(5) == "ping "){
                Ply = findPlayerByName(I:right(I:length() - 5))
                if(Ply){
                    Sc:writeString(":#"+Ply:ping()+" ms",0,Y + 1,999)
                    timer("cmd",0)
                }
                elseif(!Ply){
                    Sc:writeString(":#Error: no target.",0,Y + 1,999)
                    timer("error",0)
                }
            }
            #Common errors
            elseif(St){
                Sc:writeString(":#Error: invalid input.",0,Y + 1,999)
                timer("error",0)
            }
            elseif(!St){
                Sc:writeString(":#Error: no input.",0,Y + 1,999)
                timer("error",0)
            }
            #Line changing
            if(Y <= 15){
                Y += 2
                St = ""
                Sc:writeString(":>"+St,0,Y,999)
            }
        }
        elseif(KB > 0){
            if(!IK:exists(KB)){
                if(St:length() < 27){
                    if(Y < 15){
                        X += 2
                        St += toChar(KB)
                        Sc:writeString(":>"+St,0,Y,999)
                    }
                }
            }
            elseif(KB == 127){
                if(St:length()){
                    X -= 2
                    St = St:left(St:length() - 1)
                    Sc:writeCell(2039,Y)
                    Sc:writeString(":>"+St,0,Y,999)
                }
            }
        }               
        if(changed(Y)){ 
            if(Y >= 15){
                Sc:writeCell(2038,1)
                Y--
                Sc:writeCell(2039,16)
                Sc:writeCell(2039,15)
                Sc:writeString(":>",0,Y,999)
            }
            elseif(Y == 3){
                X = (Y * 60) + 6
            }
            if(Y != 3){
                X = (Y * 60) + 4
            }
        }
        if(Y >= 14){
            if(changed(St) & St:length() > 0){
                X = (Y * 60) + 4 + (St:length() * 2)
            }
        }
    }
}

if(P){
    #Sound
    if(clk("error")){
        soundPlay("error",0,"buttons/button16.wav") #Error
    }
    elseif(clk("cmd")){
        soundPlay("cmd",0,"buttons/button17.wav") #Command successful
    }
    #Timers
    elseif(clk("boot")){
        Btd = 1
        soundPlay("on",0,"buttons/blip1.wav")
    }
    elseif(clk("nope")){
        soundStop("nope")
    }
    elseif(clk("kick")){
        Kick = 0
    }
}