Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Multiplayer - order the players joined?
Multiplayer - order the players joined?
2001-09-17, 9:17 PM #1
Basically, I need to put all players into a queue or "line" - basically, the host is at the front of the line, and the next person who joins is 2nd, then 3rd, etc.

I have no idea how to implement this. Not only do I need to keep the order in which they joined, but I need a way to shift the order of the line (basically, move someone to the back of the line).

Any ideas?
2001-09-17, 9:24 PM #2
Let me clarify some more.

A player joins the game. I need the server cog to recognize this and assign the player to a variable for use later. There are join/leave messages, but I'm not sure how to use them. Do they send to the server cog automatically? Do I have to write a client cog to tell the server cog "I joined" - and if so, how? Then, once they join, how do I assign that SPECIFIC player to a variable.

For instance, Jedi_L337_Hacker joins the game. Immediately when he joins, I need to assign him to a variable.

So I'm assuming I use the getsenderref or something, but I'm not quite sure how to go about doing this. Help would be greatly appreciated!
2001-09-18, 1:02 AM #3
There is a tutorial on close to solving this called "Techniques on multiple firing in client cogs".

This tells how to assign players joining into queue and push them out as they leave the game. You can read this but may cause some headache...but still it may help understand the logic. (Around section 4.)

So, some slight coding for you.
Code:
startup:


   if(!IsServer()) return; //If not server guy, don't do anything, only server can control all this.


   numPlayer = 1;  //Server guy is the first
   players[numPlayer] = GetLocalPlayerThing();   //Get the server in the queue of "player[x]" array.


   return;


join:


   if(!IsServer()) return; //If not server, go away (clients may not even process this but just to make sure)


   numPlayer = numPlayer + 1; //As other people joins, increment it.
   players[numPlayer] = GetSenderRef();  //Add the joiner(sender reference) to the array.


   return; //all for joining procedure


leave:


   if(!IsServer()) return; //Only server do it.


   for(x=1; x<numPlayer; x=x+1) //check every players but forget about last entry (no need to move people to fill in the last blank)
   {
      if(players[x] == GetSenderRef()) //if the leaving guy's ID is found
      {
          for(y=x; y<numPlayer; y=y+1) players[y] = players[y+1]; //Move every players in array forward by 1 behind the guy left, to fill in the blank
      }
   }


   numPlayer = numPlayer - 1;  //decrement the total number of players


   return;


So in simple words, the players will be kept in "players[x]" array as in the order of joining, and whenever anyone leaves, that blank spot will be filled with people behind in the array.

And as for the shifting someone to the end of the line should be like this. Assuming the player ID you want to move is defined as "Z". To know what ID the player is, you can use the "for" method just like above in the leave message to check for every players.
Code:
tempKeeper = players[Z];  //Keep the moving guy
for(x=Z; x<numPlayer; x=x+1) players[x] = players[x+1];  //for every guy behind him, move them 1 forward.

players[numPlayer] = tempKeeper;  //Get the guy on the last spot.


And I assume this is for JK arena? Sounds like they will fight on 1 on 1 [http://forums.massassi.net/html/smile.gif]

------------------
http://millennium.massassi.net/ - Millennium

[This message has been edited by Hideki (edited September 18, 2001).]
2001-09-18, 1:14 AM #4
Like Rocket Arena for the Quake series? Awesome.
2001-09-18, 9:50 AM #5
Exactly. I didn't know I could make arrays! That's cool although I'll have to wipe out all the code I made. Thanks a ton! Cogging is actually pretty easy, it's just finding the verbs that's the hard part. I need to make a decent searchable reference.
2001-09-18, 9:52 AM #6
Quick question... how can I get a player's name based on their ID or whatever? Is there a verb for this?
2001-09-18, 10:22 AM #7
Nevermind, got help on that in chat. Here's another one, though.

You have a players[] array - how do you declare a variable as an array in the symbols section?
2001-09-18, 10:46 AM #8
You have to make a list. So have something like this in the symbols:

thing player local
thing player1 local
thing player2 local
thing player3 local

player[0] would refer to the first player in the array.

------------------
Fiction must be more realistic than truth or no one will believe it.

[This message has been edited by SaberMaster (edited September 18, 2001).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2001-09-18, 11:14 AM #9
Better be

thing players0 local
thing players1 local
thing players2 local
.
.
.

In this case fine, but otherwise players[0] becomes invalid. The cog is not good in "defining" arrays as you have to enter the whole elements of the array not just the array name.

------------------
http://millennium.massassi.net/ - Millennium
2001-09-18, 11:21 AM #10
Is the player a thing or an int!? Argh the cogs in ctf and in invasion use int, why make it a thing? Or does it not matter?
2001-09-18, 11:32 AM #11
That's what I meant, Hideki. I edited it so now it's a bit clearer.

But, this won't work:

thing player0 local
thing player1 local

The first in the array doesn't have a zero at the end. If you put a zero there, the array would either not work or crash.

I've always used a thing in symbols for things, but it seems that you can use an int some of the time. I guess a thing is a type of integer.

------------------
Fiction must be more realistic than truth or no one will believe it.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2001-09-18, 12:21 PM #12
Actually you can use either method of declaring arrays.

int player
int player1
int player2
int player3

Each element would be addressed as player[0], player[1], player[2] & player[3]

int player0
int player1
int player2
int player3

Each element would be addressed as player0[0], player0[1], player0[2], player0[3]

The most important thing to remember is try not to mix the addressing modes as the cog will simply crash JK.

Raynar


------------------
... the Jedi I admire the most, met up with Darth Maul, now he's toast ...
Rbots - a project to develop a working Bot for Jedi Knight... download the latest development version here
Pagewizard_YKS: "making your own lightsaber doesn't make you a nerd... "
Raynar - the man with a 10.75" ePenis
2001-09-18, 12:23 PM #13
You may now know it, Bri, but you can loop through the array with a for..next loop.
2001-09-18, 1:52 PM #14
I'm pretty sure there's no difference between thing and int, but it's better to use thing for things and int for ints. It's possible that functions which expect an int won't take a thing.
Capitalization
Commas
Periods
Question Marks
Apostrophes
Confusable Words
Plague Words

↑ Up to the top!