So I did a complete recode and it works great.
Here it is.
First make a new class file (cs file) and name it PKTournament.cs and place it in the Features folder.
Copy all this in there:
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 static class PKTournament { public static ushort Map; public static ushort X, Y; public static PKTournamentStage Stage = PKTournamentStage.None; 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) { foreach (Character Char in World.H_Chars.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!"); foreach (Character Char in World.H_Chars.Values) { try { Char.StatEff.Add(StatusEffectEn.WeeklyPKChampion); Char.Top = 10; Char.CPs += 2000; // Edit the prize here } catch (Exception e) { Console.WriteLine(e.Message); } } } public static void WaitForWinner() { PKTournament.Stage = PKTournamentStage.Fighting; uint Tick = (uint)Environment.TickCount; Character Winner = null; while (true) { Winner = null; int InMapDead = 0; int InMapAlive = 0; Thread.Sleep(500); foreach (Character Char in World.H_Chars.Values) { if (Char.Loc.Map == 1005) { InMapAlive++; } else if (Char.CurHP == 0) { InMapDead++; InMapAlive--; } if (InMapAlive == 1) { Winner = Char; { Char.Teleport(1002, 438, 382); AwardWinner(Winner); Stage = PKTournamentStage.Over; } } else { if (Tick + (60 * 1000) < (uint)Environment.TickCount) { Broadcast("30 seconds left until tournament is over."); } else if (Tick + (90 * 1000) < (uint)Environment.TickCount) { Broadcast("Tournament is over, no winner is found because more than one player is left."); if (Char.Loc.Map == Map) { Char.Teleport(1002, 400, 400); } Stage = PKTournamentStage.Over; break; } } } } } 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."); Stage = PKTournamentStage.Countdown; Thread.Sleep(4 * 1000); Broadcast("5 seconds until fight."); Thread.Sleep(3 * 1000); for (int i = 3; i >= 1; i--) { Broadcast(i.ToString()); Thread.Sleep(1000); } Stage = PKTournamentStage.Fighting; Broadcast("Fight!"); WaitForWinner(); }).Start(); } } }
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.CurHP = 1; } 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()); } break; #endregion
Code:
Features.PKTournament.BeginTournament();
So they don't need to talk to the npc themselves.
Well hope you'll like it.