Author Topic: ClientGroups [SOLVED]  (Read 1173 times)

I am trying to get the possibility of checking if EVERYONE is dead in a minigame, I wrote up my code and tested it, but when one person died, it announced the message saying that everyone died, is there any way to prevent this so that it only happens if EVERYONE dies?

Code: [Select]
for (%i = 0; %i < ClientGroup.getCount(); %i++)
{
if(ClientGroup.getObject(%i).RPData.value["dead"] == 1)
{
messageAll('', '\c4Everyone has died. Resetting minigame...');
ClientGroup.getObject(%i).corpse.delete();
ClientGroup.getObject(%i).player.delete();
ClientGroup.getObject(%i).RPData.clear();
%client.resetminigame();
}
}
« Last Edit: January 28, 2013, 06:20:53 PM by Gordo12699 »

when you check for just 1 player to be dead
and you get a true
and you call the function to reset the minigame
you're gonna have a bad time!

Code: [Select]
for (%i = 0; %i < ClientGroup.getCount(); %i++)
if(ClientGroup.getObject(%i).RPData.value["dead"] == 1)
%deathcount++;
if(%deathCount == ClientGroup.getCount())
{
messageAll('', '\c4Everyone has died. Resetting minigame...');
ClientGroup.getObject(%i).corpse.delete();
ClientGroup.getObject(%i).player.delete();
ClientGroup.getObject(%i).RPData.clear();
%client.resetminigame();
}

What you can do for loops like this is break the loop on a false condition, and check to see if the loop reached the maximum possible value to reveal whether or not all conditions were true. For example,

Code: [Select]
%player[0] = "dead";
%player[1] = "dead";
%player[2] = "alive";
%player[3] = "dead";

%playerCount = 4;

for(%i = 0; %i < %playerCount; %i++)
{
if(%player[%i] $= "alive")
break;
}

if(%i == %playerCount)
echo("All players are dead!");

This allows you to be more dynamic with your checks, and add in extra conditions (such as verifying they're in the minnigame).

Does that mean I have to make a bunch of %player[NUMBER]'s to check for the total amount of players?

Edit: Nevermind, using Marble Man's technique works. Thanks for the help anyways!
« Last Edit: January 28, 2013, 06:20:40 PM by Gordo12699 »

Does that mean I have to make a bunch of %player[NUMBER]'s to check for the total amount of players?

No, I was just giving you the clearest example to learn the method so you can apply it to any scenario.

Edit: Nevermind, using Marble Man's technique works. Thanks for the help anyways!

It shouldn't work, since it doesn't account for loading players, players outside minigame, etc.
Make sure to modify it accordingly if you're going to use it - don't just copy paste the code.

It shouldn't work, since it doesn't account for loading players, players outside minigame, etc.
Make sure to modify it accordingly if you're going to use it - don't just copy paste the code.

I did modify it, and there shouldnt be any players outside minigame since its default, and I have a workaround for players loading.

I did modify it, and there shouldnt be any players outside minigame since its default, and I have a workaround for players loading.
That's a horrible excuse for not doing a simple check. Skimping out on checks like that only lead to disasters and headaches.

I did modify it, and there shouldnt be any players outside minigame since its default, and I have a workaround for players loading.

Then use a loop like this:

Code: [Select]
for(%i = 0; %i < $DefaultMini.numMembers; %i ++)
{
%cl = $DefaultMini.member[%i];
//do stuff with %cl
}

This only loops through people actually in the minigame.
« Last Edit: January 29, 2013, 12:51:03 AM by Greek2me »

Code: [Select]
for(%i = 0; %i < $DefaultMini.numMembers; % ++)
{
%cl = $DefaultMini.member[%i];
//do stuff with %cl
}
You're missing an "I" in the third expression.

You're missing an "I" in the third expression.
Whoops, that's what I get for not paying attention. Thanks.