public static void WaitForClass()
{
PKTournament.Stage = PKTournamentStage.Fighting;
uint Tick = (uint)Environment.TickCount;
Character Winner = null;
while (true)
{
Winner = null;
int InMapAlive = 0;
Thread.Sleep(500);
foreach (Character Char in World.H_Chars.Values)
{
if (Char.Alive)
{
if (Char.Loc.Map == 1005)
{
InMapAlive++;
}
else if (Char.Loc.Map == 1039)
{
InMapAlive--;
}
}
if (Stage == PKTournamentStage.Fighting)
{
if (InMapAlive == 1)
{
Winner = Char;
{
Char.Teleport(1002, 438, 382);
AwardClass(Winner);
Stage = PKTournamentStage.Over;
}
}
else
{
Broadcast("Players Alive:" + InMapAlive);
}
}
}
}
}
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?
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.
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
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.
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.
#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.
#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?
[Release]PkTournament 02/23/2011 - CO2 PServer Guides & Releases - 80 Replies Well hunterman01 and Saint coded this, but it didn't work at all
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:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
[Help] PkTournament 02/11/2010 - CO2 Private Server - 1 Replies Ok, I got 2 problems.
I got the command to start the tournament so...
1.) When I start the pktournament and get teleported there, when it starts, me any the players get teleported back and we all win.
2.) After i've done the tournament once and do it again, I type the command to start it, and I get teleported there, and as soon as I get there, it teleports me back.
How can I fix these two problems?
[Help] PKTournament.cs 02/11/2010 - CO2 Private Server - 4 Replies I get this error when I add to PKTournament.cs
How can I fix this:
http://i50.tinypic.com/vqqxqo.jpg
[Help] PkTournament 07/19/2009 - CO2 Private Server - 0 Replies Can someone help me about the PKTournament on PazeCO source. I cant start the PKTournament but when i want to end it by typing the command @PKTournamentEnd its working fine. Is there something about it. Someone can help me pls? Thanks.