here is the code:
Spoiler:
- Code: Select all
using System;
using System.Windows.Forms;
namespace MCDzienny.Plugins
{
public class Plgn2 : Plugin
{
int loop = 1;
versionInfoPlugin info = new versionInfoPlugin("bot creator", "Adds a bot on a specific place.", "joppiesaus", "1.0", 1);
defGUI gui = new defGUI();
public override string Description
{
get { return info.descr; }
}
public override string Author
{
get { return info.auth; }
}
public override string Name
{
get { return info.name; }
}
public override System.Windows.Forms.UserControl MainInterface
{
get { return gui; }
}
public override string Version
{
get { return info.ver; }
}
public override int VersionNumber
{
get { return info.verNumber; }
}
public override void Initialize()
{
try
{
checkEvents();
}
catch (Exception ex)
{
MessageBox.Show("Oh snap. Error!" + System.Environment.NewLine + ex, "Error");
}
}
public void checkEvents()
{
EventHandlerExtension.ClickEvent button = new EventHandlerExtension.ClickEvent(gui.button1);
while (loop == 1)
{
if (button.buttonClicked)
{
addBot();
button.buttonClicked = false;
}
}
}
public void addBot()
{
if (gui.botNameTextBox.Text != "")
{
Player who = Player.Find(gui.locationTextBox.Text.ToLower());
if (who == null)
{
MessageBox.Show("Player not found.", "Error");
}
else
{
who.HandleCommand("botadd", gui.botNameTextBox.Text);
gui.botNameTextBox.Clear();
gui.locationTextBox.Clear();
MessageBox.Show("succesfully added a bot to the players position!", "Info");
}
}
else
{
MessageBox.Show("Botname must be a valid name!", "Error");
}
}
public override void Terminate()
{
loop = 0;
}
}
public class versionInfoPlugin
{
public string name { get; set; }
public string descr { get; set; }
public string auth { get; set; }
public string ver { get; set; }
public int verNumber { get; set; }
public versionInfoPlugin(string nameOfAssembly, string description, string author, string version, int versionNumber)
{
name = nameOfAssembly;
descr = description;
auth = author;
ver = version;
verNumber = versionNumber;
}
}
public partial class defGUI
{
public defGUI()
{
InitializeComponent();
}
}
public partial class defGUI : UserControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.botNameTextBox = new System.Windows.Forms.TextBox();
this.locationTextBox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(3, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(52, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Botname:";
//
// botNameTextBox
//
this.botNameTextBox.Location = new System.Drawing.Point(61, 9);
this.botNameTextBox.Name = "botNameTextBox";
this.botNameTextBox.Size = new System.Drawing.Size(232, 20);
this.botNameTextBox.TabIndex = 1;
//
// locationTextBox
//
this.locationTextBox.Location = new System.Drawing.Point(61, 35);
this.locationTextBox.Name = "locationTextBox";
this.locationTextBox.Size = new System.Drawing.Size(232, 20);
this.locationTextBox.TabIndex = 2;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(3, 38);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(51, 13);
this.label2.TabIndex = 3;
this.label2.Text = "Location:";
//
// button1
//
this.button1.Location = new System.Drawing.Point(3, 92);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(290, 23);
this.button1.TabIndex = 4;
this.button1.Text = "Add bot!";
this.button1.UseVisualStyleBackColor = true;
//
// mainGUI
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.locationTextBox);
this.Controls.Add(this.botNameTextBox);
this.Controls.Add(this.label1);
this.Name = "mainGUI";
this.Size = new System.Drawing.Size(296, 120);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
public System.Windows.Forms.TextBox botNameTextBox;
public System.Windows.Forms.TextBox locationTextBox;
private System.Windows.Forms.Label label2;
public System.Windows.Forms.Button button1;
}
}
// \\
// Classes by: joppiesaus \\
// \\
// This was made for easier plugin coding in MCDzienny. All classes are V 1.0;
namespace EventHandlerExtension
{
public class ClickEvent
{
/// <summary>
/// This will return true when the control is clicked. Check this, and if true ALWAYS set it back to false.
/// </summary>
public bool buttonClicked { get; set; }
Button button;
event EventHandler clickedHandler;
/// <summary>
/// New event for clicked button.
/// </summary>
/// <param name="Button">Button</param>
public ClickEvent(Button Button)
{
Button = button;
initialize();
}
private void initialize()
{
button.Click += this.handleClick;
}
private void handleClick(object sender, EventArgs e)
{
this.clicked(EventArgs.Empty);
}
protected virtual void clicked(EventArgs e)
{
EventHandler hand = this.clickedHandler;
if (hand != null)
{
hand(this, e);
}
buttonClicked = true;
}
}
public class TextChangedEvent
{
/// <summary>
/// This will return true when the control text is changed. Check this, and if true ALWAYS set it back to false.
/// </summary>
public bool textChanged { get; set; }
TextBox textbox;
event EventHandler textChangedHandler;
/// <summary>
/// New event for textchanged textbox.
/// </summary>
/// <param name="TextBox">TextBox</param>
public TextChangedEvent(TextBox TextBox)
{
textbox = TextBox;
initialize();
}
private void initialize()
{
textbox.TextChanged += this.handleTextChanged;
}
private void handleTextChanged(object sender, EventArgs e)
{
this.Changed(EventArgs.Empty);
}
protected virtual void Changed(EventArgs e)
{
EventHandler hand = this.textChangedHandler;
if (hand != null)
{
hand(this, e);
}
textChanged = true;
}
}
public class CheckedChangedEvent
{
/// <summary>
/// This will return true when the control checked is changed. Check this, and if true ALWAYS set it back to false.
/// </summary>
public bool checkedChanged { get; set; }
CheckBox checkbox;
event EventHandler checkedChangedHandler;
/// <summary>
/// New event for Checkbox CheckedChanged
/// </summary>
/// <param name="CheckBox">CheckBox</param>
public CheckedChangedEvent(CheckBox CheckBox)
{
checkbox = CheckBox;
initialize();
}
private void initialize()
{
checkbox.CheckedChanged += this.handleCheckedChanged;
}
private void handleCheckedChanged(object sender, EventArgs e)
{
this.Changed(EventArgs.Empty);
}
protected virtual void Changed(EventArgs e)
{
EventHandler hand = this.checkedChangedHandler;
if (hand != null)
{
hand(this, e);
}
checkedChanged = true;
}
}
}
- some extra info about the error
- Knipsel.PNG (6.97 KiB) Viewed 234 times
Thanks for the help!