@name Robotboy655's Console Operating System
@inputs CS:wirelink KB
@outputs LastCmd:array LastCmdNum LastCmdNum2
@persist Line Cmd:string Args:array Pause Pitch Mute Volume 
@trigger 

#Made by robotboy655
#OLD, USE CONTENT, DELETE

#First launch
if(first())
{
    CS[2041] = 1
    CS[2046] = 1 #Enable
    CS[2044] = 0.2 #Size
    CS[2043] = 0.75 #Blinrate SECONDS
    Cmd = ""
    CS:writeString("robotboy655's Operating System",0,0,9)
    Line = 1
    Pause = 0
    Pitch = 100
    Mute = 0
    Volume = 1
    LastCmdNum = 1
    LastCmdNum2 = LastCmdNum
}
#First launch

if(KB & KB != 127 & KB != 154 & KB != 13 & KB != 17)
{
    Cmd += toChar(KB)
}
elseif(KB == 17)
{
    if(LastCmdNum2 == 1){LastCmdNum2 = LastCmdNum}
    CS:writeString("                        ",1,Line)
    LastCmdNum2--
    Cmd = LastCmd[LastCmdNum2,string]
}
elseif(KB == 127)
{
    Cmd = Cmd:left(Cmd:length()-1)
    CS:writeString(Cmd+" ",1,Line)
}
elseif(KB == 13)
{
    LastCmd[LastCmdNum,string] = Cmd
    LastCmdNum++
    LastCmdNum2 = LastCmdNum
    Args = Cmd:explode(" ")
    if(Args:string(1):lower() == "help")
    {
        Line += floor(Cmd:length()/30)+1
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("Avaible Commands:",0,Line,90)
        
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("HELP",0,Line,90)
        CS:writeString("Show help",5,Line)
        
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("CLEAR",0,Line,90)
        CS:writeString("Clear screen",6,Line)
        
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("ECHO <str>",0,Line,90)
        CS:writeString("Print message",11,Line)
        
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("CONCMD <str>",0,Line,90)
        CS:writeString("Run console cmd",13,Line)
        
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("PLAY <str>",0,Line,90)
        CS:writeString("Play sound",11,Line)
        
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("PLAYVOLUME <int>",0,Line,90)
        CS:writeString("Change volume",17,Line)
        
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("PLAYPITCH <int>",0,Line,90)
        CS:writeString("Change pitch",16,Line)
        
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("PLAYPAUSE",0,Line,90)
        CS:writeString("Pause sound",10,Line)
        
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("PLAYSTOP",0,Line,90)
        CS:writeString("Stop sound",9,Line)
        
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("Up Arrow",0,Line,90)
        CS:writeString("Prevorious Command",9,Line)
        
        Cmd = ""
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
    }
    elseif(Args:string(1):lower() == "clear")
    {
        Cmd = ""
        Line = 0
        CS[2041] = 1
    }
    elseif(Args:string(1):lower() == "echo")
    {
        String = Cmd:right(Cmd:length()-5)
        
        Line += floor(Cmd:length()/30)+1
        CS:writeString(String,0,Line)
        
        Cmd = ""
        Line += floor(String:length()/30)+1
        if(Line >= 18){CS[2041] = 1 Line = 0}
    }
    elseif(Args:string(1):lower() == "concmd")
    {
        String = Cmd:right(Cmd:length()-7)
        
        Sucess = concmd(String)
        
        Line += floor(Cmd:length()/30)+1
        CS:writeString(Sucess ? "Command sucessfully ran!" : "Failed to run command!",0,Line,Sucess ? 90 : 900)
        
        Cmd = ""
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
    }
    elseif(Args:string(1):lower() == "play")
    {
        String = Cmd:right(Cmd:length()-5)
        
        soundPlay("rOS_play",0,String)
        soundVolume("rOS_play",Volume)
        soundPitch("rOS_play",Pitch)
        
        Line += floor(Cmd:length()/30)+1
        if(Line >= 18){CS[2041] = 1 Line = 0}
        Cmd = ""
    }
    elseif(Args:string(1):lower() == "playvolume")
    {
        Volume = Args:string(2):toNumber()
        soundVolume("rOS_play",Volume)
        
        Line += floor(Cmd:length()/30)+1
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("Volume set to: "+Volume,0,Line)
        
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
        Cmd = ""
    }
    elseif(Args:string(1):lower() == "playpitch")
    {
        Pitch = Args:string(2):toNumber()
        if(Pause == 0)
        {
            soundPitch("rOS_play",Pitch)
        }
        
        Line += floor(Cmd:length()/30)+1
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("Pitch set to: "+Pitch,0,Line)
        
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
        Cmd = ""
    }
    elseif(Args:string(1):lower() == "playpause")
    {
        if(Pause == 0)
        {
            soundPitch("rOS_play",0)
            Pause = 1
            
            Line += floor(Cmd:length()/30)+1
            if(Line >= 18){CS[2041] = 1 Line = 0}
            CS:writeString("Paused",0,Line)
        }
        elseif(Pause == 1)
        {
            soundPitch("rOS_play",Pitch)
            Pause = 0
            
            Line += floor(Cmd:length()/30)+1
            if(Line >= 18){CS[2041] = 1 Line = 0}
            CS:writeString("Unpaused",0,Line)
        }
        
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
        Cmd = ""
    }
    elseif(Args:string(1):lower() == "playstop")
    {
        soundStop("rOS_play")
        Pause = 0
        soundPitch("rOS_play",Pitch)
        
        Line += floor(Cmd:length()/30)+1
        if(Line >= 18){CS[2041] = 1 Line = 0}
        Cmd = ""
    }
    else
    {
        Line += floor(Cmd:length()/30)+1
        if(Line >= 18){CS[2041] = 1 Line = 0}
        CS:writeString("Unknown Command",0,Line,900)
        Cmd = ""
        Line++
        if(Line >= 18){CS[2041] = 1 Line = 0}
    }
}

CS:writeString(">",0,Line)
CS:writeString(Cmd,1,Line)
CS[2045] = Line * 60 + Cmd:length() * 2 + 2 #Addres
