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 → Test to see if a player is still in game?
Test to see if a player is still in game?
2001-09-18, 4:36 PM #1
I need to test to see if each player in my aforementioned mod are still in the game.

Basically, I've got a "catch-all" resetGame function that will reset the game from scratch if something breaks. So I have an array of all the players in the game, and I need to test each of those values to test for sure whether they're actually still IN the game. Is this possible?
2001-09-19, 5:02 PM #2
With the "put in line" method I showed you before, it will take the players that left the game from the array. So whoever in the array is sure to be in the game.

------------------
http://millennium.massassi.net/ - Millennium
2001-09-19, 6:37 PM #3
Yeah... I just wanted a way to reset the game in a catch-all situation, rather than repeating code for every event. Oh well.
2001-09-19, 6:40 PM #4
Okay, have a problem...
Code:
		if(players[x] == left_player) {
			for(y = x; y < numPlayer; y = y + 1) players[y] = players[y + 1];
		}
If players[x] leaves and he is the LAST player in line, it will try to get players[y + 1]. So say he is player 8 of 8... when he leaves, it will try to assign the value of players[8 + 1] or players[9] - since there is no players[9] what will happen!?
2001-09-19, 9:59 PM #5
I have set it so that kind of problem won't happen.

Look in the for loop and see that the "y" can only get 1 below the value of "numPlayer". So it can only go up to "numPlayer" for "players[y+1]" value, no problem here.

As for to see if the player exists in game or not, how about getting his health, weapon, etc parameters and see if it's valid value or not?

Btw you got posted just 3000 times [http://forums.massassi.net/html/wink.gif]

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

[This message has been edited by Hideki (edited September 20, 2001).]
2001-09-20, 12:05 AM #6
Look I must be missing something :( Because to me, if the max number of players is '8' then the last number 'x' will be '7' (because 0 - 7 players = 8 total players).

So if the LAST person leaves (players[7] which is actually the 8th player), the loop can never GET to assign a new value. And if you can't assign a new value (-1), the rest of the cog will think the player is still in the game!

For instance, players[7] leaves... so it says:

for(y = 7; y < 7; y = y+1 ;)

That will NEVER be true, so players[7] will STILL KEEP the player ID of the player that left! So later on in the cog, it will think there is a valid value there!

What I WANT to happen is this... if player[7] leaves, the array should look like this:

players[0] = Brian
players[1] = Hideki
players[2] = oSiRiS
players[3] = Raynar
players[4] = Kedri
players[5] = Sared
players[6] = Hideki's Mom
players[7] = -1

BUT - the way your loop works, it will actually look like this:

players[0] = Brian
players[1] = Hideki
players[2] = oSiRiS
players[3] = Raynar
players[4] = Kedri
players[5] = Sared
players[6] = Hideki's Mom
players[7] = Hideki's Mom

See, your mom will be in the loop twice :(

(Oh, wow 3000, not bad :))

[This message has been edited by Brian (edited September 20, 2001).]
2001-09-20, 12:08 AM #7
So I changed it to this, I think it will work but I can't test unless I have the max number of people in there. Really there is a 16 player max.
Code:
	# Loop through the queue, and when a match is found, move behind him up in line
	for(x = 0; x < num; x = x + 1) {
		if(players[x] == left_player) {
			for(y = x; y <= num; y = y + 1) {
				# If it's the last player on the list, assign it -1
				if(y == 15) {
					players[y] = -1;
				}
				else {
					players[y] = players[y + 1];
				}
			}
		}
	}
2001-09-20, 4:42 AM #8
Now if you'd look at my code in the other post, in the startup, the "numPlayer" starts from 1 as the host enters the game, so the first player gets "players[1]" assigned and not "players[0]". I knew what I was doing.

But in your code since you're giving "-1" as "y" gets to "15" (which you probably mean the same as var "num"), that just looks fine too.

------------------
http://millennium.massassi.net/ - Millennium
2001-09-20, 11:37 AM #9
Hideki, even if you start at one, it won't work correctly. Because if the last person in line leaves (in your case, say players[8] is last), it's not going to have a value to assign. Because it will get to players[7], and then test to see if 8 < 8 which is FALSE so players[8] will STILL keep the playerID of the player that left.
2001-09-20, 3:17 PM #10
With THAT code you just posted above, for the first "for" loop, get "<" into "<=" and will have no problem!

Right, what you said.

or you can just do this instead.

if(left_player == players[num]) players[num] = -1;
else
{
//do the for loop stuff
}

if it won't mess your code.

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

↑ Up to the top!