an object reference is required for the nonstatic field method or property
Discussion on an object reference is required for the nonstatic field method or property within the CO2 Private Server forum part of the Conquer Online 2 category.
an object reference is required for the nonstatic field method or property
hello guys , i am getting this error in :
PHP Code:
public static void WaitForWinner()
and here is a pic of the error.
and here is my class which have the 2 error's
PHP Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Conquer_Online_Server.Game;
using Conquer_Online_Server.Network.GamePackets;
using Conquer_Online_Server.Network.Features.ClassPKWar;
namespace Conquer_Online_Server
{
public enum BroadCastLoc
{
World,
Map
}
public enum ElgahedStage
{
None,
Inviting,
Countdown,
Fighting,
Over
}
public static class Elgahed
{
public static ushort Map;
public static ushort X, Y;
public static ElgahedStage Stage = ElgahedStage.None;
public static Dictionary<uint, Client.GameState> PKTHash2;
public static Dictionary<uint, Client.GameState> PKTHash;
public static int CountDown;
private static Thread PkThread;
public Client.GameState pOne, pTwo;
public static Map dynamicMap;
public void RandomSelect()
{
List<Client.GameState> players = new List<Client.GameState>();
foreach (Client.GameState p in ServerBase.Kernel.GamePool.Values)
players.Add(p);
Random rand = new Random();
int selectedIndex = rand.Next(players.Count);
pOne = players[selectedIndex];
players.RemoveAt(selectedIndex);
selectedIndex = rand.Next(players.Count);
pTwo = players[selectedIndex];
players.RemoveAt(selectedIndex);
if (pOne.Map.ID == 1631 && pOne.Map.ID == pTwo.Map.ID)
if (!ServerBase.Kernel.Maps.ContainsKey(700))
new Map(700, Database.DMaps.MapPaths[700]);
Map origMap = ServerBase.Kernel.Maps[700];
dynamicMap = origMap.MakeDynamicMap();
pOne.Entity.Teleport(origMap.ID, dynamicMap.ID, (ushort)ServerBase.Kernel.Random.Next(35, 70), (ushort)ServerBase.Kernel.Random.Next(35, 70));
pTwo.Entity.Teleport(origMap.ID, dynamicMap.ID, (ushort)ServerBase.Kernel.Random.Next(35, 70), (ushort)ServerBase.Kernel.Random.Next(35, 70));
if (pOne.Map.ID == pTwo.Map.ID)
{
pOne.Entity.RemoveFlag(Network.GamePackets.Update.Flags.Ride);
pTwo.Entity.RemoveFlag(Network.GamePackets.Update.Flags.Ride);
pTwo.Entity.PKMode = pOne.Entity.PKMode;
pOne.Entity.PKMode = Conquer_Online_Server.Game.Enums.PKMode.PK;
pOne.Send(new Data(true) { UID = pOne.Entity.UID, ID = Data.ChangePKMode, dwParam = (uint)pOne.Entity.PKMode });
pOne.Entity.PKMode = pTwo.Entity.PKMode;
pTwo.Entity.PKMode = Conquer_Online_Server.Game.Enums.PKMode.PK;
pTwo.Send(new Data(true) { UID = pTwo.Entity.UID, ID = Data.ChangePKMode, dwParam = (uint)pTwo.Entity.PKMode });
Conquer_Online_Server.Network.PacketHandler.WorldMessage("" + pOne.Entity.Name + " Is Meeting " + pTwo.Entity.Name + " in the Elite Pk Tournament");
Client.GameState[] Clients = Conquer_Online_Server.ServerBase.Kernel.GamePool.Values.ToArray();
while (CountDown > 0)
{
if (CountDown == 0)
Broadcast("60 seconds until start", BroadCastLoc.World);
else if (CountDown == 0)
{
Stage = ElgahedStage.Countdown;
//if (PKTHash.Count < 2)
//{
// Broadcast("The tournament requires atleast 2 people to start, Tournament Cancelled.", BroadCastLoc.World);
// Stage = ElgahedStage.None;
// PKTHash = null;
// return;
//}
Broadcast("10 seconds until start", BroadCastLoc.World);
}
else if (CountDown < 0)
Broadcast(CountDown + " seconds until start", BroadCastLoc.World);
CountDown--;
Thread.Sleep(1000);
}
Stage = ElgahedStage.Fighting;
Broadcast("Fight!", BroadCastLoc.World);
WaitForWinner();
}
}
public static void StartTournament(Client.GameState Started)
{
PKTHash = new Dictionary<uint, Client.GameState>();
CountDown = 0;
Stage = ElgahedStage.Inviting;
Map = 1507;
X = 100;
Y = 100;
PkThread = new Thread(new ThreadStart(BeginTournament));
PkThread.IsBackground = true;
PkThread.Start();
}
public static void StartTournament()
{
PKTHash = new Dictionary<uint, Client.GameState>();
CountDown = 0;
Stage = ElgahedStage.Inviting;
Map = 1507;
X = 100;
Y = 100;
PkThread = new Thread(new ThreadStart(BeginTournament));
PkThread.IsBackground = true;
PkThread.Start();
}
private static void Broadcast(string msg, BroadCastLoc loc)
{
//Console.WriteLine(msg);
if (loc == BroadCastLoc.World)
{
foreach (Client.GameState Char in ServerBase.Kernel.GamePool.Values)
{
Char.Send(new Message(msg, System.Drawing.Color.White, 2011));
// Char.MyClient.EndSend();
}
}
else if (loc == BroadCastLoc.Map)
{
foreach (Client.GameState Char in PKTHash.Values)
{
Char.Send(new Message(msg, System.Drawing.Color.White, 2011));
// Char.EndSend();
}
}
}
private static void AwardWinner(Client.GameState Winner)
{
Broadcast(Winner.Entity.Name + " has won the tournament !He WIn 10.000Cps and WeeklyPKChampion Top", BroadCastLoc.World);
Winner.Entity.WeeklyPKChampion += 1;
Winner.Entity.ConquerPoints += 10000;
Elgahed.Stage = ElgahedStage.None;
PkThread.Abort();
return;
}
public static void WaitForWinner()
{
Elgahed.Stage = ElgahedStage.Fighting;
uint Tick = (uint)Environment.TickCount;
int InMapAlive = PKTHash.Count;
while (true)
{
int alive = 0;
foreach (Conquer_Online_Server.Client.GameState players in Conquer_Online_Server.ServerBase.Kernel.GamePool.Values)
if (pOne.Entity.Map.ID == pOne.Entity.Map.ID && (!players.Entity.Dead))
alive++;
foreach (Client.GameState _GC in PKTHash.Values)
{
if (_GC.InPKT)
if (_GC.Entity.Dead == true)
{
}
else if (!ServerBase.Kernel.GamePool.ContainsKey(_GC.Entity.UID))
{
InMapAlive--;
_GC.Entity.Teleport(1002, 438, 382);
_GC.InPKT = false;
}
}
System.Threading.Thread.Sleep(2000);
foreach (Client.GameState _GC in PKTHash.Values)
{
if (_GC.InPKT)
if (alive == 1)
{
_GC.Entity.Teleport(1002, 438, 382);
AwardWinner(_GC);
Stage = ElgahedStage.Over;
return;
}
}
if (InMapAlive != 1)
{
Broadcast("There are " + InMapAlive + " Alive ", BroadCastLoc.Map);
}
Thread.Sleep(1000);
}
}
public static void BeginTournament()
{
Client.GameState[] client = Conquer_Online_Server.ServerBase.Kernel.GamePool.Values.ToArray();
foreach (Client.GameState clientss in client)
{
Network.GamePackets.NpcReply npc = new Network.GamePackets.NpcReply(6, "The WeeklyPK Champion Tournament has Started! You Wana Join?");
npc.OptionID = 248;
clientss.Send(npc.ToArray());
}
Stage = ElgahedStage.Inviting;
while (CountDown > 0)
{
if (CountDown == 0)
Broadcast("60 seconds until start", BroadCastLoc.World);
else if (CountDown == 0)
{
Stage = ElgahedStage.Countdown;
//if (PKTHash.Count < 2)
//{
// Broadcast("The tournament requires atleast 2 people to start, Tournament Cancelled.", BroadCastLoc.World);
// Stage = ElgahedStage.None;
// PKTHash = null;
// return;
//}
Broadcast("10 seconds until start", BroadCastLoc.World);
}
else if (CountDown < 0)
Broadcast(CountDown + " seconds until start", BroadCastLoc.World);
These are never defined when they are used in that method.
look , i added :
PHP Code:
foreach (Conquer_Online_Server.Client.GameState pOne in Conquer_Online_Server.ServerBase.Kernel.GamePool.Values) foreach (Conquer_Online_Server.Client.GameState pTwo in Conquer_Online_Server.ServerBase.Kernel.GamePool.Values)
and its looks like this :
PHP Code:
public static void WaitForWinner() { Elgahed.Stage = ElgahedStage.Fighting; uint Tick = (uint)Environment.TickCount; int InMapAlive = PKTHash.Count; while (true) { int alive = 0; foreach (Conquer_Online_Server.Client.GameState players in Conquer_Online_Server.ServerBase.Kernel.GamePool.Values) foreach (Conquer_Online_Server.Client.GameState pOne in Conquer_Online_Server.ServerBase.Kernel.GamePool.Values) foreach (Conquer_Online_Server.Client.GameState pTwo in Conquer_Online_Server.ServerBase.Kernel.GamePool.Values) if (pTwo.Entity.MapID == pOne.Entity.MapID && (!players.Entity.Dead)) alive++;
foreach (Client.GameState _GC in PKTHash.Values) { if (_GC.InPKT) if (_GC.Entity.Dead == true) { } else if (!ServerBase.Kernel.GamePool.ContainsKey(_GC.Entity.UID)) { InMapAlive--; _GC.Entity.Teleport(1002, 438, 382); _GC.InPKT = false; } }
but i got another 3 errors here at pOne , pTwo and RandomSelect :
PHP Code:
public Client.GameState pOne, pTwo; public void RandomSelect()
I'm not sure if I can accurately describe object oriented programming in a sentence or two but lets just use a possibly less accurate but easier to understand version of it..
When you say something is static then you're saying that there can be only one of it.
Example...
static class FormMember
{
//Class variables/methods/etc
}
This means there can only EVER be one form member... You never need to use the 'new' statement to create a new instance of an object because well... you can't.
You use this when obviously there cannot be two of something. Examples would be methods which let you perform an action on input generally such as something like...
*Note* Doing something like this would be pointless but it should help you understand what I'm talking about.
Now you have to take into account what the reverse of this means... If you do NOT state that something is static then there can be as many objects of that type as you want and each one must be initiated at some point...
Example..
class FormMember
{
//Class variables/methods/etc
}
FormMember Pro4Never = new FormMember();
In this case I'm saying that I want to create a new instance of the class FormMember and assign it to the variable I'm calling Pro4Never.
Often times your classes will take parameters in the constructors you write for them. This doesn't change how we deal with the objects, simply the information they hold and require before they are initialized.
Eg:
class FormMember
{
public string Name;
public FormMember(string _name)
{
Name = _name;
}
}
FormMember Pro4Never = FormMember("Pro4Never");
In your example you're using a loop (which... looks really... really awkward/wrong to me...) to try to check for winners.
HELPFUL ADVICE: Learn how loops work... in your example players, pOne and pTwo are the loop values... you are not assigning them manually, they are just telling you what loop number you are on.
Screw it.. here's some code that will be more accurate and help you understand what you SHOULD be doing here....
public class TournamentMatch
{
public TournamentMatch(Player _one, Player _two)
{
PlayerOne = _one;
PlayerTwo = _two;
PlayerOne.Match = this;
PlayerTwo.Match = this;
}
public Player PlayerOne, PlayerTwo;
//Any extra information such as time the match started and the player's score!
//Any extra methods such as RoundStart, RoundEnd, CheckForWinner
}
In your player class you'd need to allow it to hold a TournamentMatch value. By default it would be null obviously if they are not in a match (null out on round end)
In your thread which is checking for winner (I told you already that's a poor way of doing this in the other 3 threads you made on this topic) you'd simply do something like...
foreach (Conquer_Online_Server.Client.GameState player in Conquer_Online_Server.ServerBase.Kernel.GamePool.V alues)
if(player.Match != null)
{
//Or w/e you want to call it when you check if both people are alive/on same map/etcetc to deal with round end conditions
player.Match.CheckMatchStatus();
}
[D2NT] API Reference [NO QUESTIONS] 03/16/2011 - Diablo 2 Programming - 4 Replies Dear community,
this will be the home of the upcoming D2NT 3.1 API reference.
This reference is supposed to be useful for everyone, therefore the official language in this topic is english.
I would really appreciate if we could share some of the work. That's why I hope for some contributions. :)
In this case, contributing basically means picking some function or object from the list below that has not been dealt with and write a reference for it.
However, to make this really...
My Reference For Cheats 02/23/2011 - Facebook - 0 Replies The Website Which Gives/Shares To Me New,Fresh,100% Working Cheats Is
facebookgamestricks.tk
Visit The Page
And See More Cheats Up
Everyday There Are 5 Cheats Fresh
Please Cooperate
just a reference 11/26/2008 - Dekaron Exploits, Hacks, Bots, Tools & Macros - 0 Replies havnt been on for some time i dont know if its any help at all this is an old sheet i used to use to find things quicker with winhex though id post it :)
If someone else has posted it im sorry in advance :handsdown:
the way i use it is simple just say i wanted to find a Great mana potion all i would do is click the search tab in winhex then find text then enter 3806 then it should be the first item that pops up with a line that looks like
3806,Great Mana...
2nd rb quest quick reference 01/05/2007 - CO2 Guides & Templates - 10 Replies i know there have been a few of these but i see people constantly asking, so here's just a quick referance of where lords and special mobs can be found in 2nd rb quest. hope it helps. (i used shodowHackers guide to help me make this)