Author Topic: Best way to get all clients in a minigame  (Read 627 times)

So, I need a list of all clients in a minigame to use often. The following code works well for me:
Code: [Select]
%clientCount = clientGroup.getCount();
for(%i=0;%i<%clientCount;%i++)
{
    %clObj = clientGroup.getObject(%i);
    if(%minigame == getMinigameFromObject(%clObj))
        //Do stuff
}
However, I always strive for optomization in my scripts. I'm using this in a loop to update a bottomprint for individual clients in a minigame. I know I could package the function when clients leave or join a minigame, but I was wondering if there was already something default that handled a dynamic minigame client list, possibly named minigameClientGroup

In the minigame object there's fields labeled as 'member0', 'member1' etc. Use those instead of looping through all of the clients on the server.
So if you wanted to loop all the members in the minigame:
Code: [Select]
for(%i=0;%i<%mini.numMembers;%i++)
{
   %client = %mini.member[%i];
   //Do stuff
}
Or similar.

In the minigame object there's fields labeled as 'member0', 'member1' etc. Use those instead of looping through all of the clients on the server.
So if you wanted to loop all the members in the minigame:
Code: [Select]
for(%i=0;%i<%mini.numMembers;%i++)
{
   %client = %mini.member[%i];
   //Do stuff
}
Or similar.

You never defined %mini, but I'm guessing it's a minigame. What if there are multiple minigames?

You never defined %mini, but I'm guessing it's a minigame. What if there are multiple minigames?
Considering Treynolds doesn't show where he defined %minigame, I'm sure it will be taken care of.

You never defined %mini, but I'm guessing it's a minigame. What if there are multiple minigames?
You would define it earlier in the script, depending on where you need the code? %mini wouldn't magically imply a minigame on the server.

An example with the minigame defined.

Code: [Select]
function serverCmdKillEveryoneInMyMinigame(%client)
{
%mini = getMinigameFromObject(%client);
if(!isObject(%mini))
return;

for(%i = 0; %i < %mini.numMembers; %i++)
{
%cl = %mini.member[%i];
if(isObject(%cl.player))
{
%cl.player.kill();
}
}
}

Considering Treynolds doesn't show where he defined %minigame, I'm sure it will be taken care of.
Kalph wins the "plucked the exact words out of my brain, dammit" award
Anyway, I forgot that I could have dumped a minigame to see it's member properties, thanks hell