MCDzienny Scripter

MCDzienny Scripter

Postby joppiesaus » 30 Sep 2013, 18:49

Hi! I made a brand new fresh simple (but usefull) plugin, where you can execute MCDzienny commands like a script.
You can select a file, and it will read and execute it!
It can execute ANY command of MCDzienny, and some extra commands for usefullness.
Suggestions are welcome! :D


Documentation
Usage of commands: <command> [message] (normal but without "/")
If the command is wrong, it will do like normal, it throws a usage.

These are the custom commands for the script:
  • sleep <interval> - adds a pause in your script in a specific interval in milisecons.

Example:
Code: Select all
say Hi!
sleep 1000
say How are you?

this will say "Hi!", and then waits a second, than says "How are you?".


Here's the code:
Code: Select all
using System;
using System.IO;
using System.Windows.Forms;
using MCDzienny;

namespace MCDzienny.Plugins
{
    public class MCDziennyScripter : Plugin
    {
        UserControl gui = new GUI();//usercontrol hier
        // I know, I know. I am making space okay!
        public override string Description { get { return "Allows you to run commands as a script."; } }public override string Author { get { return "joppiesaus"; } }public override string Name { get { return "MCDzienny Scripter"; } }public override System.Windows.Forms.UserControl MainInterface { get { return gui; } }public override string Version { get { return "1.0"; } }public override int VersionNumber { get { return 1; } }
        public override void Initialize()
        {

        }

        public override void Terminate()
        {

        }
    }

    public partial class GUI : UserControl
    {
        public GUI()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            using (StreamReader read = new StreamReader(openFileDialog1.FileName))
            {
                richTextBox1.Text = read.ReadToEnd();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            runCmds(richTextBox1.Text);
        }

        public void runCmds(string cmds)
        {
            foreach (string cmd in cmds.Split('\n'))
            {
                string[] spaces = cmd.ToLower().Trim().Split(' ');
                if (spaces[0] == "sleep" && spaces.Length > 0)
                {
                    try
                    {
                        System.Threading.Thread.Sleep(Convert.ToInt32(spaces[1]));
                    }
                    catch { }
                }
                else
                {
                    string toDo = cmd.Trim().Split(' ')[0];
                    Command.all.Find(toDo).Use(null, cmd.Replace(toDo, ""));
                }
            }
        }
    }

    partial class GUI
    {
        private System.ComponentModel.IContainer components = null;
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            this.SuspendLayout();
            this.button1.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.button1.Location = new System.Drawing.Point(0, 367);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(425, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "Execute";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            this.button2.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.button2.Location = new System.Drawing.Point(0, 344);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(425, 23);
            this.button2.TabIndex = 1;
            this.button2.Text = "Load";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            this.button3.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.button3.Location = new System.Drawing.Point(0, 321);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(425, 23);
            this.button3.TabIndex = 2;
            this.button3.Text = "Clear";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.richTextBox1.Location = new System.Drawing.Point(0, 0);
            this.richTextBox1.Name = "richTextBox1";
            this.richTextBox1.Size = new System.Drawing.Size(425, 321);
            this.richTextBox1.TabIndex = 3;
            this.richTextBox1.Text = "";
            this.openFileDialog1.FileName = "script.txt";
            this.openFileDialog1.Filter = "All Files | *.*";
            this.openFileDialog1.Title = "Choose MCDzienny Script file...";
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.richTextBox1);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Name = "gui";
            this.Size = new System.Drawing.Size(425, 390);
            this.ResumeLayout(false);

        }
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.RichTextBox richTextBox1;
        private System.Windows.Forms.OpenFileDialog openFileDialog1;
    }
}


Good luck with it! If you don't understand it, just ask! <ok>
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Return to Plugins

Who is online

Users browsing this forum: No registered users and 1 guest

cron