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.