Author Topic: Doing something to all players in a server [Solved]  (Read 2283 times)

Alright.

So I want to loop something that will deduct a variable from every player in the server.

How would I get all players in the server?

Like I want it to look like this:

Code: [Select]
function blabla()
{
%client = howtogettheclientidontknow;
%client.variable - 1;
messageClient(%client,'',%client.variable);
}
« Last Edit: September 08, 2012, 08:51:39 PM by ¥ola »

Code: [Select]
%count = clientGroup.getCount();
for(%i=0;%i<%count;%i++)
{
    %client = clientGroup.getObject(%i);
    %client.doSomething();
}

« Last Edit: September 08, 2012, 05:39:12 PM by Electrk »

Code: [Select]
for(%i=0;%i<ClientGroup.getCount();%i++)
{
%client = ClientGroup.getObject(%i);
//do stuff
}

Something like that

Edit: holy cow didn't notice the other posts :cookieMonster:





My way is better :cookieMonster:
You didn't even include %count = clientGroup.getCount(); though

My way is better :cookieMonster:
Nope
clientgroup.getobject(clientgroup.getcount())
Will return some invalid
Because it no exist


You didn't even include %count = clientGroup.getCount(); though
he directly put it in the loop

he directly put it in the loop
I worded that incorrectly. Meant to say he didn't put it directly in the loop, which is good because .getCount() isn't called every iteration

Mold, I've done it the way I posted before and it works.

Mold, I've done it the way I posted before and it works.
It works, but it will call the loop a last time with an inexistant object.

Mold, I've done it the way I posted before and it works.
I did
Code: [Select]
function testfor()
{
for(%i = 0; %i <= clientGroup.getCount(); %i++)
{
  %client = clientGroup.getObject(%i);
  echo(%i SPC %client);
}
}
Tried it out and guess what? It returns
Code: [Select]
0 8956
1 -1
So therefor you shouldn't be using <=

Guys.
The one in the first post will work the fastest, has correct syntax, and won't cause console spam unless the person using it forgets up, making it the best one in this topic.

Use that one.