Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 19:23

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



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.

Reply
 
Old   #1
 
abdeen's Avatar
 
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
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 XY;
        public static 
ElgahedStage Stage ElgahedStage.None;
        public static 
Dictionary<uintClient.GameStatePKTHash2;
        public static 
Dictionary<uintClient.GameStatePKTHash;
        public static 
int CountDown;
        private static 
Thread PkThread;
        public 
Client.GameState pOnepTwo;
        public static 
Map dynamicMap;
        public 
void RandomSelect()
        {
            List<
Client.GameStateplayers = 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(700Database.DMaps.MapPaths[700]);
            
Map origMap ServerBase.Kernel.Maps[700];
            
dynamicMap origMap.MakeDynamicMap();
            
pOne.Entity.Teleport(origMap.IDdynamicMap.ID, (ushort)ServerBase.Kernel.Random.Next(3570), (ushort)ServerBase.Kernel.Random.Next(3570));
            
pTwo.Entity.Teleport(origMap.IDdynamicMap.ID, (ushort)ServerBase.Kernel.Random.Next(3570), (ushort)ServerBase.Kernel.Random.Next(3570));
            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.UIDID Data.ChangePKModedwParam = (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.UIDID Data.ChangePKModedwParam = (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<uintClient.GameState>();
            
CountDown 0;
            
Stage ElgahedStage.Inviting;
            
Map 1507;
            
100;
            
100;
            
PkThread = new Thread(new ThreadStart(BeginTournament));
            
PkThread.IsBackground true;
            
PkThread.Start();
        }
        public static 
void StartTournament()
        {
            
PKTHash = new Dictionary<uintClient.GameState>();
            
CountDown 0;
            
Stage ElgahedStage.Inviting;
            
Map 1507;
            
100;
            
100;

            
PkThread = new Thread(new ThreadStart(BeginTournament));
            
PkThread.IsBackground true;
            
PkThread.Start();
        }
        private static 
void Broadcast(string msgBroadCastLoc loc)
        {
            
//Console.WriteLine(msg);
            
if (loc == BroadCastLoc.World)
            {
                foreach (
Client.GameState Char in ServerBase.Kernel.GamePool.Values)
                {
                    
Char.Send(new Message(msgSystem.Drawing.Color.White2011));
                    
// Char.MyClient.EndSend();
                
}
            }
            else if (
loc == BroadCastLoc.Map)
            {
                foreach (
Client.GameState Char in PKTHash.Values)
                {
                    
Char.Send(new Message(msgSystem.Drawing.Color.White2011));
                    
// 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(1002438382);
                            
_GC.InPKT false;
                        }
                }
                
System.Threading.Thread.Sleep(2000);
                foreach (
Client.GameState _GC in PKTHash.Values)
                {
                    if (
_GC.InPKT)
                        if (
alive == 1)
                    {
                        
_GC.Entity.Teleport(1002438382);
                        
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);

                
CountDown--;
                
Thread.Sleep(1000);
            }
            
Stage ElgahedStage.Fighting;
            
Broadcast("Fight!"BroadCastLoc.World);
            
WaitForWinner();
        }
    }


and i don't get this error in :

PHP Code:
public void RandomSelect() 
so why i get it in :

PHP Code:
public static void WaitForWinner() 
abdeen is offline  
Old 10/30/2011, 16:16   #2


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
public Client.GameState pOne, pTwo;

These are never defined when they are used in that method.
Korvacs is offline  
Thanks
1 User
Old 10/30/2011, 16:20   #3
 
abdeen's Avatar
 
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
Quote:
Originally Posted by Korvacs View Post
public Client.GameState pOne, pTwo;

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(1002438382);
                            
_GC.InPKT false;
                        }
                } 
but i got another 3 errors here at pOne , pTwo and RandomSelect :

PHP Code:
        public Client.GameState pOnepTwo;
        public 
void RandomSelect() 
the error says :

Code:
cannot declare instance members in a static class
abdeen is offline  
Old 10/30/2011, 18:55   #4
 
Drunk|Guy's Avatar
 
elite*gold: 0
Join Date: Oct 2011
Posts: 2
Received Thanks: 0
Do not declare instance members in a static class .
Drunk|Guy is offline  
Old 10/31/2011, 00:55   #5
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
.... you need to learn what static means.


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...


static void SetName(FormMember user, string name)
{
user.Name = name;
}

*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();
}

DONE
pro4never is offline  
Thanks
1 User
Old 10/31/2011, 06:10   #6
 
Lateralus's Avatar
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 920
@ pro4never - Dude, major kudos to you and Korvacs. You both have mad patience.
Lateralus is offline  
Thanks
2 Users
Old 10/31/2011, 14:34   #7
 
F i n c h i's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 785
Received Thanks: 422
Best & respected moderator is pro4never (Chris).
F i n c h i is offline  
Old 10/31/2011, 17:37   #8
 
abdeen's Avatar
 
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
pro4never , You are the best , Thanks for your help i`ll try it
abdeen is offline  
Reply


Similar Threads Similar Threads
Weird null reference exception.
07/18/2011 - CO2 Private Server - 5 Replies
#Edit I know why it happens and it's fixed.
[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)



All times are GMT +1. The time now is 19:25.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.