/pvp

/pvp

Postby qpqpqp123 » 24 Oct 2013, 20:07

player vs player game

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 .");
        }
    }
}
qpqpqp123
 
Posts: 59
Joined: 29 Apr 2013, 12:51

Re: /pvp fix

Postby qpqpqp123 » 24 Oct 2013, 20:53

Spoiler:
qpqpqp123
 
Posts: 59
Joined: 29 Apr 2013, 12:51

Re: /pvp

Postby qpqpqp123 » 25 Oct 2013, 16:09

update
    fix bugs
Spoiler:
qpqpqp123
 
Posts: 59
Joined: 29 Apr 2013, 12:51

Re: /pvp

Postby qpqpqp123 » 25 Oct 2013, 17:13

fix bug
Spoiler:
qpqpqp123
 
Posts: 59
Joined: 29 Apr 2013, 12:51

Re: /pvp

Postby joppiesaus » 25 Oct 2013, 17:54

This looks awsome! But what does it do?
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: /pvp

Postby qpqpqp123 » 26 Oct 2013, 10:06

have little bugs but I will fix it it make pvp game player Vs player it check if you on game and if you on it you will hit by someone else that also play in start you have 16 life if you lost all 16 life you dead
qpqpqp123
 
Posts: 59
Joined: 29 Apr 2013, 12:51

Re: /pvp

Postby dzienny » 26 Oct 2013, 21:47

It's a nice piece of code there. It's fairly complex and it puts the ExtraData feature to a very good use <ok>
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: /pvp

Postby toystory_justin » 26 Oct 2013, 22:24

Does this do like what the pvp does? Would be fun if it was :D
toystory_justin
 
Posts: 224
Joined: 11 Nov 2012, 07:12
Location: On a dark place


Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 7 guests

cron