PKTournament

02/10/2010 03:39 Arcо#1
Well I'm tweaking around with my released pktournament and here's the problem I'm coming across.
My problem is I don't think its counting the people in the map cause when two people enter the map and PKTournamentStage.Fighting everyone in the arena gets tele'd to tc and gets rewarded. Anyone know whats wrong?
02/10/2010 04:01 CIRASH#2
Not so sure but it seems to me like InMapAlive isnt defined correctly. simply because its teleporting you back to tc and giing you rewards
02/10/2010 05:35 spare2#3
You can't do it this way.
Code:
                    if (Char.Alive)
                    {
                        if (Char.Loc.Map == 1005)
                        {
                            InMapAlive++;
                        }
                        else if (Char.Loc.Map == 1039)
                        {
                            InMapAlive--;
                        }
                    }
Since it is
Code:
foreach (Character Char in World.H_Chars.Values)
It selects EVERYONE in the server. So if there were people in map 1039, the value InMapAlive of would minus 1. It doesn't check if the player was in the tournament or not. What I suggest you to do is do a player count in map 1005 before the fighting happens, then count the players inside 1005 every 5 seconds after the fighting starts.

Edit:
Code:
                            {
                                Char.Teleport(1002, 438, 382);
                                AwardClass(Winner);
                                Stage = PKTournamentStage.Over;
                            }
Why are there extra brackets?
02/10/2010 06:07 Nullable#4
As spare2 said you should not be searching for everyone in the server, and the best solution is to create another Hashtable or Dictionary to keep the players who joined the tournament enumerated, and search that table instead
02/10/2010 07:18 spare2#5
Quote:
My problem is I don't think its counting the people in the map cause when two people enter the map and PKTournamentStage.Fighting everyone in the arena gets tele'd to tc and gets rewarded. Anyone know whats wrong?
According to your code, you start counting when Fighting starts. Let's say you have 2 people in 1005. You start counting. You find one person in map 1005, then InMapAlive = 1. Then he is sent out to TC because the next step in the loop is to send the person to TC and award him if InMapAlive = 1. You are not waiting for the count finish before sending people out.
02/11/2010 07:27 Arcо#6
Well thanks spare,this is now what I have and it is still not working.
02/11/2010 08:11 -impulse-#7
Code:
public static void WaitForWinner()
        {
            PKTournament.Stage = PKTournamentStage.Fighting;
            uint Tick = (uint)Environment.TickCount;
            Character Winner = null;
            while (true)
            {
                Winner = null;
                int InMapAlive = World.H_Chars.Values.Count;
                Thread.Sleep(500);
                if (Stage == PKTournamentStage.Fighting)
                {
                    foreach (Character Char in World.H_Chars.Values)
                        if (!Char.Alive || Char.Loc.Map != 1005)
                            InMapAlive--;
                       
                    if (InMapAlive == 1)
                    {
                        foreach (Character Char in World.H_Chars.Values)
                            if (Char.Alive && Char.Loc.Map == 1005)
                                Winner = Char;
                        Winner.Teleport(1002, 438, 382);
                        AwardWinner(Winner, Winner.MyClient);
                        Stage = PKTournamentStage.Over;
                    }
                    else if (InMapAlive != 1)
                    {
                        Broadcast("There are" + InMapAlive + "people left");
                    }
                }
            }
        }
02/11/2010 08:25 kamote#8
Quote:
Originally Posted by -impulse- View Post
Code:
public static void WaitForWinner()
        {
            PKTournament.Stage = PKTournamentStage.Fighting;
            uint Tick = (uint)Environment.TickCount;
            Character Winner = null;
            while (true)
            {
                Winner = null;
                int InMapAlive = World.H_Chars.Values.Count;
                Thread.Sleep(500);
                if (Stage == PKTournamentStage.Fighting)
                {
                    foreach (Character Char in World.H_Chars.Values)
                       [COLOR="Red"] if (!Char.Alive || Char.Loc.Map != 1005)[/COLOR]
                            InMapAlive--;
                       
                    if (InMapAlive == 1)
                    {
                        foreach (Character Char in World.H_Chars.Values)
                            if (Char.Alive && Char.Loc.Map == 1005)
                                Winner = Char;
                        Winner.Teleport(1002, 438, 382);
                        AwardWinner(Winner, Winner.MyClient);
                        Stage = PKTournamentStage.Over;
                    }
                    else if (InMapAlive != 1)
                    {
                        Broadcast("There are" + InMapAlive + "people left");
                    }
                }
            }
        }
color in red is counting a dead player outside the pk map. Why not just count the Alive player inside the Map...
02/11/2010 10:16 -impulse-#9
Quote:
Originally Posted by kamote View Post
color in red is counting a dead player outside the pk map. Why not just count the Alive player inside the Map...
LOL! -.-

If you would read the whole code, you wouldn't post that.

Above that there is:
int InMapAlive = World.H_Chars.Values.Count;

Now, it will check for all players that are dead OR they are not in map 1005, once one is found InMapAlive will be with 1 less than before. When the while is finished, if there are more players alive in that map it will send that message, otherwise, it will search for the only alive who is on that map and award him.
02/11/2010 12:04 Korvacs#10
Here you go, this should fix all of your issues:

Code:
                            #region JoinPKTDialog
                            case 666111:
                                if (Control == 0)
                                {
                                    GC.AddSend(Packets.NPCSay("Would you like to join the PK tournament in the PKArena? You have 20 seconds to join."));
                                    GC.AddSend(Packets.NPCLink("Sure, I'm a beast anyways.", 1));
                                    GC.AddSend(Packets.NPCLink("What're the rules?", 2));
                                    GC.AddSend(Packets.NPCSetFace(30));
                                    GC.AddSend(Packets.NPCFinish());
                                }
                                else if (Control == 1)
                                {
                                    if (Features.PKTournament.Stage == Features.PKTournamentStage.Inviting)
                                    {
                                        GC.AddSend(Packets.NPCSay("Goodluck, " + GC.MyChar.Name + "."));
                                        GC.AddSend(Packets.NPCLink("Thanks", 255));
                                        GC.AddSend(Packets.NPCSetFace(30));
                                        GC.AddSend(Packets.NPCFinish());
                                        GC.MyChar.Teleport(1005, 51, 71);
                                        GC.MyChar.InPKT = true;
                                        GC.MyChar.CurHP = 1;
                                        Features.PKTournament.PKTHash.Add(GC.MyChar.EntityID, GC);
                                    }
                                    else if (Features.PKTournament.Stage == Features.PKTournamentStage.Fighting)
                                    {
                                        GC.AddSend(Packets.NPCSay("You're too late, " + GC.MyChar.Name + "!"));
                                        GC.AddSend(Packets.NPCLink("Darn", 255));
                                        GC.AddSend(Packets.NPCSetFace(30));
                                        GC.AddSend(Packets.NPCFinish());
                                    }
                                    else
                                    {
                                        GC.AddSend(Packets.NPCSay("No PK tournament is going on at this time."));
                                        GC.AddSend(Packets.NPCLink("Darn", 255));
                                        GC.AddSend(Packets.NPCSetFace(30));
                                        GC.AddSend(Packets.NPCFinish());
                                    }
                                }
                                else if (Control == 2)
                                {

                                    GC.AddSend(Packets.NPCSay("The PK tournament is started by a GM, on any map he wants."));
                                    GC.AddSend(Packets.NPCSay("Everyone fights with only 1 HP."));
                                    GC.AddSend(Packets.NPCSay("The last man that isn't a GM standing will 'win' the tournament."));
                                    GC.AddSend(Packets.NPCLink("I want to join!", 1));
                                    GC.AddSend(Packets.NPCLink("No thanks.", 255));
                                    GC.AddSend(Packets.NPCSetFace(30));
                                    GC.AddSend(Packets.NPCFinish());
                                }
                                return;
                            #endregion
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using NewestCOServer.Game;

namespace NewestCOServer.Features
{
    public enum PKTournamentStage
    {
        None,
        Inviting,
        Countdown,
        Fighting,
        Over
    }
    public enum BroadCastLoc
    {
        World,
        Map
    }
    public static class PKTournament
    {
        public static ushort Map;
        public static ushort X, Y;
        public static PKTournamentStage Stage = PKTournamentStage.None;
        public static Dictionary<uint, Main.GameClient> PKTHash;

        public static void StartTournament(Character Started)
        {
            if (Started.MyClient.GM)
            {
                PKTHash = new Dictionary<uint, Main.GameClient>();
                Stage = PKTournamentStage.Inviting;
                Map = 1005;
                X = 51;
                Y = 71;
                BeginTournament();
            }
        }
        private static void Broadcast(string msg, BroadCastLoc loc)
        {
            if (loc == BroadCastLoc.World)
            {
                foreach (Main.GameClient Char in World.H_Chars.Values)
                {
                    Char.AddSend(Packets.ChatMessage(0, "[GM]", "All", msg, 2011, 0));
                    Char.EndSend();
                }
            }
            else if (loc == BroadCastLoc.Map)
            {
                foreach (Main.GameClient Char in PKTHash.Values)
                {
                    Char.AddSend(Packets.ChatMessage(0, "[GM]", "All", msg, 2011, 0));
                    Char.EndSend();
                }
            }
        }
        private static void AwardWinner(Character Winner)
        {
            Broadcast(Winner.Name + " has won the tournament!", BroadCastLoc.World);

            Winner.StatEff.Add(StatusEffectEn.WeeklyPKChampion);
            Winner.Top = 10;
            Winner.CPs += 2000;
            // Edit the prize here
            return;
        }
        public static void WaitForWinner()
        {
            PKTournament.Stage = PKTournamentStage.Fighting;
            uint Tick = (uint)Environment.TickCount;
            int InMapAlive = PKTHash.Count;
            while (true)
            {
                foreach (Main.GameClient _GC in PKTHash.Values)
                {
                    if (_GC.MyChar.InPKT)
                        if (!_GC.MyChar.Alive)
                        {
                            InMapAlive--;
                            _GC.MyChar.InPKT = false;
                        }
                }

                foreach (Main.GameClient _GC in PKTHash.Values)
                {
                    if (_GC.MyChar.InPKT)
                        if (_GC.MyChar.Alive && InMapAlive == 1)
                        {
                            _GC.MyChar.Teleport(1002, 438, 382);
                            AwardWinner(_GC.MyChar);
                            Stage = PKTournamentStage.Over;
                            return;
                        }
                }

                if (InMapAlive != 1)
                {
                    Broadcast("There are" + InMapAlive + "people left", BroadCastLoc.Map);

                }
                Thread.Sleep(1000);
            }
        }


        public static void BeginTournament()
        {
            new Thread(delegate()
            {
                foreach (Main.GameClient Char in World.H_Chars.Values)
                {
                    Char.DialogNPC = 666111;
                    PacketHandling.NPCDialog.Handle(Char, null, 666111, 0);
                    Char.EndSend();
                }
                Stage = PKTournamentStage.Inviting;
                Thread.Sleep(5 * 1000);
                Broadcast("10 seconds until fight.", BroadCastLoc.World);
                Stage = PKTournamentStage.Countdown;
                Thread.Sleep(4 * 1000);
                Broadcast("5 seconds until fight.", BroadCastLoc.World);
                Thread.Sleep(3 * 1000);
                for (int i = 3; i >= 1; i--)
                {
                    Broadcast(i.ToString(), BroadCastLoc.World);
                    Thread.Sleep(1000);
                }
                Stage = PKTournamentStage.Fighting;
                Broadcast("Fight!", BroadCastLoc.World);
                WaitForWinner();
            }).Start();
        }
    }
}
Add this to the Character object:

Code:
public bool InPKT = false;
I havent tested it, so if someone could try it out that would be great.
02/11/2010 13:09 Nullable#11
Quote:
Originally Posted by Korvacs View Post
...
Exactly the same as i did it for him 9 hours ago on tv, i don't know why he's still asking..
.Arco: get on msn and tell me what is wrong? :p
02/11/2010 14:47 Decker_#12
Quote:
Originally Posted by Korvacs View Post
Here you go, this should fix all of your issues:

Code:
                            #region JoinPKTDialog
                            case 666111:
                                if (Control == 0)
                                {
                                    GC.AddSend(Packets.NPCSay("Would you like to join the PK tournament in the PKArena? You have 20 seconds to join."));
                                    GC.AddSend(Packets.NPCLink("Sure, I'm a beast anyways.", 1));
                                    GC.AddSend(Packets.NPCLink("What're the rules?", 2));
                                    GC.AddSend(Packets.NPCSetFace(30));
                                    GC.AddSend(Packets.NPCFinish());
                                }
                                else if (Control == 1)
                                {
                                    if (Features.PKTournament.Stage == Features.PKTournamentStage.Inviting)
                                    {
                                        GC.AddSend(Packets.NPCSay("Goodluck, " + GC.MyChar.Name + "."));
                                        GC.AddSend(Packets.NPCLink("Thanks", 255));
                                        GC.AddSend(Packets.NPCSetFace(30));
                                        GC.AddSend(Packets.NPCFinish());
                                        GC.MyChar.Teleport(1005, 51, 71);
                                        GC.MyChar.InPKT = true;
                                        GC.MyChar.CurHP = 1;
                                        Features.PKTournament.PKTHash.Add(GC.MyChar.EntityID, GC);
                                    }
                                    else if (Features.PKTournament.Stage == Features.PKTournamentStage.Fighting)
                                    {
                                        GC.AddSend(Packets.NPCSay("You're too late, " + GC.MyChar.Name + "!"));
                                        GC.AddSend(Packets.NPCLink("Darn", 255));
                                        GC.AddSend(Packets.NPCSetFace(30));
                                        GC.AddSend(Packets.NPCFinish());
                                    }
                                    else
                                    {
                                        GC.AddSend(Packets.NPCSay("No PK tournament is going on at this time."));
                                        GC.AddSend(Packets.NPCLink("Darn", 255));
                                        GC.AddSend(Packets.NPCSetFace(30));
                                        GC.AddSend(Packets.NPCFinish());
                                    }
                                }
                                else if (Control == 2)
                                {

                                    GC.AddSend(Packets.NPCSay("The PK tournament is started by a GM, on any map he wants."));
                                    GC.AddSend(Packets.NPCSay("Everyone fights with only 1 HP."));
                                    GC.AddSend(Packets.NPCSay("The last man that isn't a GM standing will 'win' the tournament."));
                                    GC.AddSend(Packets.NPCLink("I want to join!", 1));
                                    GC.AddSend(Packets.NPCLink("No thanks.", 255));
                                    GC.AddSend(Packets.NPCSetFace(30));
                                    GC.AddSend(Packets.NPCFinish());
                                }
                                return;
                            #endregion
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using NewestCOServer.Game;

namespace NewestCOServer.Features
{
    public enum PKTournamentStage
    {
        None,
        Inviting,
        Countdown,
        Fighting,
        Over
    }
    public enum BroadCastLoc
    {
        World,
        Map
    }
    public static class PKTournament
    {
        public static ushort Map;
        public static ushort X, Y;
        public static PKTournamentStage Stage = PKTournamentStage.None;
        public static Dictionary<uint, Main.GameClient> PKTHash = new Dictionary<uint, Main.GameClient>();

        public static void StartTournament(Character Started)
        {
            if (Started.MyClient.GM)
            {
                Stage = PKTournamentStage.Inviting;
                Map = 1005;
                X = 51;
                Y = 71;
                BeginTournament();
            }
        }
        private static void Broadcast(string msg, BroadCastLoc loc)
        {
            if (loc == BroadCastLoc.World)
            {
                foreach (Character Char in World.H_Chars.Values)
                {
                    Char.MyClient.AddSend(Packets.ChatMessage(0, "[GM]", "All", msg, 2011, 0));
                    Char.MyClient.EndSend();
                }
            }
            else if (loc == BroadCastLoc.Map)
            {
                foreach (Character Char in PKTHash.Values)
                {
                    Char.MyClient.AddSend(Packets.ChatMessage(0, "[GM]", "All", msg, 2011, 0));
                    Char.MyClient.EndSend();
                }
            }
        }
        private static void AwardWinner(Character Winner)
        {
            Broadcast(Winner.Name + " has won the tournament!", BroadCastLoc.World);

            Winner.StatEff.Add(StatusEffectEn.WeeklyPKChampion);
            Winner.Top = 10;
            Winner.CPs += 2000;
            // Edit the prize here
            return;
        }
        public static void WaitForWinner()
        {
            PKTournament.Stage = PKTournamentStage.Fighting;
            uint Tick = (uint)Environment.TickCount;
            uint InMapAlive = PKTHash.Count;
            while (true)
            {
                foreach (Main.GameClient _GC in PKTHash.Values)
                {
                    if (_GC.MyChar.InPKT)
                        if (!_GC.MyChar.Alive)
                        {
                            InMapAlive--;
                            _GC.MyChar.InPKT = false;
                        }
                }

                foreach (Main.GameClient _GC in PKTHash.Values)
                {
                    if (_GC.MyChar.InPKT)
                        if (_GC.MyChar.Alive && InMapAlive == 1)
                        {
                            _GC.MyChar.Teleport(1002, 438, 382);
                            AwardWinner(_GC);
                            Stage = PKTournamentStage.Over;
                            return;
                        }
                }

                if (InMapAlive != 1)
                {
                    Broadcast("There are" + InMapAlive + "people left", BroadCastLoc.Map);

                }
            }
            Thread.Sleep(1000);
        }
        

        public static void BeginTournament()
        {
            new Thread(delegate()
            {
                foreach (Character Char in World.H_Chars.Values)
                {
                    Char.MyClient.DialogNPC = 666111;
                    PacketHandling.NPCDialog.Handle(Char.MyClient, null, 666111, 0);
                    Char.MyClient.EndSend();
                }
                Stage = PKTournamentStage.Inviting;
                Thread.Sleep(5 * 1000);
                Broadcast("10 seconds until fight.", BroadCastLoc.World);
                Stage = PKTournamentStage.Countdown;
                Thread.Sleep(4 * 1000);
                Broadcast("5 seconds until fight.", BroadCastLoc.World);
                Thread.Sleep(3 * 1000);
                for (int i = 3; i >= 1; i--)
                {
                    Broadcast(i.ToString());
                    Thread.Sleep(1000);
                }
                Stage = PKTournamentStage.Fighting;
                Broadcast("Fight!", BroadCastLoc.World);
                WaitForWinner();
            }).Start();
        }
    }
}
Add this to the Character object:

Code:
public bool InPKT = false;
I havent tested it, so if someone could try it out that would be great.
What is character object, where do I add this code?
02/11/2010 17:59 spare2#13
Quote:
Originally Posted by _Decker View Post
What is character object, where do I add this code?
Character.cs
02/11/2010 18:49 Decker_#14
I get these errors in PKTournament.cs:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using NewestCOServer.Game;

namespace NewestCOServer.Features
{
    public enum PKTournamentStage
    {
        None,
        Inviting,
        Countdown,
        Fighting,
        Over
    }
    public enum BroadCastLoc
    {
        World,
        Map
    }
    public static class PKTournament
    {
        public static ushort Map;
        public static ushort X, Y;
        public static PKTournamentStage Stage = PKTournamentStage.None;
        public static Dictionary<uint, Main.GameClient> PKTHash = new Dictionary<uint, Main.GameClient>();

        public static void StartTournament(Character Started)
        {
            if (Started.MyClient.GM)
            {
                Stage = PKTournamentStage.Inviting;
                Map = 1005;
                X = 51;
                Y = 71;
                BeginTournament();
            }
        }
        private static void Broadcast(string msg, BroadCastLoc loc)
        {
            if (loc == BroadCastLoc.World)
            {
                foreach (Character Char in World.H_Chars.Values)
                {
                    Char.MyClient.AddSend(Packets.ChatMessage(0, "[GM]", "All", msg, 2011, 0));
                    Char.MyClient.EndSend();
                }
            }
            else if (loc == BroadCastLoc.Map)
            {
                [COLOR="Red"]foreach[/COLOR] (Character Char in PKTHash.Values)
                {
                    Char.MyClient.AddSend(Packets.ChatMessage(0, "[GM]", "All", msg, 2011, 0));
                    Char.MyClient.EndSend();
                }
            }
        }
        private static void AwardWinner(Character Winner)
        {
            Broadcast(Winner.Name + " has won the tournament!", BroadCastLoc.World);

            Winner.StatEff.Add(StatusEffectEn.WeeklyPKChampion);
            Winner.Top = 10;
            Winner.CPs += 2000;
            // Edit the prize here
            return;
        }
        public static void WaitForWinner()
        {
            PKTournament.Stage = PKTournamentStage.Fighting;
            uint Tick = (uint)Environment.TickCount;
            uint InMapAlive = [COLOR="Red"]PKTHash.Count[/COLOR];
            while (true)
            {
                foreach (Main.GameClient _GC in PKTHash.Values)
                {
                    if (_GC.MyChar.InPKT)
                        if (!_GC.MyChar.Alive)
                        {
                            InMapAlive--;
                            _GC.MyChar.InPKT = false;
                        }
                }

                foreach (Main.GameClient _GC in PKTHash.Values)
                {
                    if (_GC.MyChar.InPKT)
                        if (_GC.MyChar.Alive && InMapAlive == 1)
                        {
                            _GC.MyChar.Teleport(1002, 438, 382);
                            [COLOR="Red"]AwardWinner(_GC);[/COLOR]
                            Stage = PKTournamentStage.Over;
                            return;
                        }
                }

                if (InMapAlive != 1)
                {
                    Broadcast("There are" + InMapAlive + "people left", BroadCastLoc.Map);

                }
            }
            Thread.Sleep(1000);
        }


        public static void BeginTournament()
        {
            new Thread(delegate()
            {
                foreach (Character Char in World.H_Chars.Values)
                {
                    Char.MyClient.DialogNPC = 666111;
                    PacketHandling.NPCDialog.Handle(Char.MyClient, null, 666111, 0);
                    Char.MyClient.EndSend();
                }
                Stage = PKTournamentStage.Inviting;
                Thread.Sleep(5 * 1000);
                Broadcast("10 seconds until fight.", BroadCastLoc.World);
                Stage = PKTournamentStage.Countdown;
                Thread.Sleep(4 * 1000);
                Broadcast("5 seconds until fight.", BroadCastLoc.World);
                Thread.Sleep(3 * 1000);
                for (int i = 3; i >= 1; i--)
                {
                    [COLOR="Red"]Broadcast(i.ToString());[/COLOR]
                    Thread.Sleep(1000);
                }
                Stage = PKTournamentStage.Fighting;
                Broadcast("Fight!", BroadCastLoc.World);
                WaitForWinner();
            }).Start();
        }
    }
}
Please fix the code and paste it here.
Thanks!
02/11/2010 19:09 w.maatman#15
@ Korvacs

i got 5 errors on that..