/pvp bug

/pvp bug

Postby qpqpqp123 » 24 Oct 2013, 15:14

It give me error when i use it the error
Code: Select all

----24-10-2013 Thursday 17:10:41 ----
Type: KeyNotFoundException
Source: mscorlib
Message: The given key was not present in the dictionary.
Target: ThrowKeyNotFoundException
Trace:    at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at MCDzienny.CmdPvp.Use(Player p, String message)
   at MCDzienny.Player.<>c__DisplayClass26.<HandleCommand>b__21()

-------------------------


source code that make by me
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("life"))
                {
                    p.ExtraData.Add("life", 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 - Does stuff.  Example command.");
        }
    }
}
qpqpqp123
 
Posts: 59
Joined: 29 Apr 2013, 12:51

Re: /pvp bug

Postby ismellike » 24 Oct 2013, 15:27

From the looks of it, you never declared the p.ExtraData["onpvp"].
Also, you declare if(!p.ExtraData.ContainsKey("life")) twice
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: /pvp bug

Postby joppiesaus » 24 Oct 2013, 15:30

You need to surround
Code: Select all
                    if ((int)p.ExtraData["onpvp"] == 1)
                    {
                        p.ExtraData["onpvp"] = 0;
                    }
                    else
                    {
                        p.ExtraData["onpvp"] = 1;
                    }

with
Code: Select all
if (p.ExtraData.ContainsKey("onpvp")
{
    // Add code here
}
else
{
   p.ExtraData.Add("onpvp",NUMBER HERE );
}
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 bug

Postby qpqpqp123 » 24 Oct 2013, 20:05

thank for help
qpqpqp123
 
Posts: 59
Joined: 29 Apr 2013, 12:51


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 2 guests

cron