- Code: Select all
/*
Auto-generated command skeleton class.
Use this as a basis for custom commands implemented via the MCDzienny scripting framework.
File and class should be named a specific way. For example, /update is named 'CmdUpdate.cs' for
the file, and 'CmdUpdate' for the class.
*/
// Add any other using statements you need up here, of course.
// As a note, MCDzienny is designed for .NET 3.5.
using System;
using System.Collections.Generic;
using System.Threading;
namespace MCDzienny
{
public class CmdPvp : Command
{
public override string name { get { return "pvp"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return "other"; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message)
{
if (!p.ExtraData.ContainsKey("onpvp"))
{
p.ExtraData.Add("onpvp", 1);
}
else
{
if ((int)p.ExtraData["onpvp"] == 1)
{
p.ExtraData["onpvp"] = 0;
}
else
{
p.ExtraData["onpvp"] = 1;
}
}
if (!p.ExtraData.ContainsKey("life"))
{
p.ExtraData.Add("life", 16);
}
else
{
if ((int)p.ExtraData["life"] == 0)
p.ExtraData["life"] = 16;
}
if ((int)p.ExtraData["onpvp"] == 1)
{
Player.GlobalMessage(p.name + " has join Pvp");
while ((int)p.ExtraData["onpvp"] == 1)
{
double aVal = Math.Sin(((double)(128 - p.rot[0]) / 256) * 2 * Math.PI);
double bVal = Math.Cos(((double)(128 - p.rot[0]) / 256) * 2 * Math.PI);
double cVal = Math.Cos(((double)(p.rot[1] + 64) / 256) * 2 * Math.PI);
double maxOut = 3; // Because I can't be bothered with pythagoras
List<CatchPos> added = new List<CatchPos>();
Thread webThread = new Thread(new ThreadStart(delegate
{
ushort posX = (ushort)(p.pos[0] / 32);
ushort posY = (ushort)(p.pos[1] / 32);
ushort posZ = (ushort)(p.pos[2] / 32);
CatchPos pos;
for (double d = 3; d < maxOut; d++)
{
pos.x = (ushort)Math.Round((double)(aVal * d) + posX);
pos.y = (ushort)Math.Round((double)(cVal * d) + posY);
pos.z = (ushort)Math.Round((double)(bVal * d) + posZ);
if (p.level.GetTile(pos.x, pos.y, pos.z) != Block.air && !added.Contains(pos))
{
break;
}
Thread.Sleep(33);
added.Add(pos);
foreach (Player pl in Player.players)
{
if (pl.level == p.level)
{
if ((ushort)(pl.pos[0] / 32) == pos.x || (ushort)(pl.pos[0] / 32 + 1) == pos.x || (ushort)(pl.pos[0]
/ 32 - 1) == pos.x)
{
if ((ushort)(pl.pos[1] / 32) == pos.y || (ushort)(pl.pos[1] / 32 + 1) == pos.y || (ushort)
(pl.pos[1] / 32 - 1) == pos.y)
{
if ((ushort)(pl.pos[2] / 32) == pos.z || (ushort)(pl.pos[2] / 32 + 1) == pos.z || (ushort)
(pl.pos[2] / 32 - 1) == pos.z)
{
if ((int)pl.ExtraData["onpvp"] == 1)
{
p.ExtraData["life"] = (int)p.ExtraData["life"] - 1;
Player.GlobalMessage(pl.color + pl.name + " %ehave been hit by " + p.color +
p.name);
if ((int)p.ExtraData["life"] != 0)
{
Player.GlobalMessage("%enow " + pl.color + pl.name + " %eleft %4" +
p.ExtraData["life"] + " lifes");
}
else
{
Command.all.Find("kill").Use(pl, pl.name + " kill in Pvp by " + p.name);
pl.ExtraData["life"] = 16;
}
}
}
}
}
}
}
//p.frozen = false;
return;
}
}));
webThread.Start();
}
}
else
{
Player.GlobalMessage(p.name + " has leave Pvp");
}
}
public struct CatchPos { public ushort x, y, z; }
// This one controls what happens when you use /help [commandname].
public override void Help(Player p)
{
Player.SendMessage(p, "/pvp - join or leave pvp .");
}
}
}