Author Topic: Target All clients?  (Read 1264 times)

I am wondering how to target all clients in a script
What is the function?
« Last Edit: October 08, 2009, 01:55:31 PM by Pah1023 »

Target all what? Everything in the server could cause quite a bit of lag...

Oops i forgot to describe what all of
I mean target all clients.

ClientGroup is the group where the GameConnections are stored by default when they connect to the server; findClientByName works by looping through there. You can use the methods .getCount(), which returns the number of objects in the group, and .getObject(int Index), which returns the object at the specified index.

For example:

Code: [Select]
for(%i = 0; %i < ClientGroup.getCount(); %i++)
     ClientGroup.getObject(%i).delete();
// Disconnects all clients from the server (no real use, just showing looping)

Code: [Select]
ClientGroup.getObject(getRandom(0,ClientGroup.getCount() - 1)).delete();
// Disconnects a random client from the server (same as above, just an example)

EDIT: If you're curious of other methods, just call .dump() for ClientGroup while hosting sometime.
« Last Edit: October 08, 2009, 02:01:37 PM by Truce »

ClientGroup is the group where the GameConnections are stored by default when they connect to the server; findClientByName works by looping through there. You can use the methods .getCount(), which returns the number of objects in the group, and .getObject(int Index), which returns the object at the specified index.

For example:

Code: [Select]
for(%i = 0; %i < ClientGroup.getCount(); %i++)
     ClientGroup.getObject(%i).delete();
// Disconnects all clients from the server (no real use, just showing looping)

Code: [Select]
ClientGroup.getObject(getRandom(0,ClientGroup.getCount() - 1)).delete();
// Disconnects a random client from the server (same as above, just an example)

EDIT: If you're curious of other methods, just call .dump() for ClientGroup while hosting sometime.
How about listing all there names with MessageAll function?

How about listing all there names with MessageAll function?

See if you can figure it out by using the two methods I provided.

Code: [Select]
function serverCmdTest()
{
 for(%i = 0; %i < ClientGroup.getCount(); %i++)
 {
  MessgeAll('',"\c3"@%i);
 }
}
Is that it?

Code: [Select]
function serverCmdTest()
{
 for(%i = 0; %i < ClientGroup.getCount(); %i++)
 {
  MessgeAll('',"\c3"@%i);
 }
}
Is that it?

Try it out and see what it does; if it doesn't do what you expected, then skim through the code to see if you left out something or accidently made a typo.

Try it out and see what it does; if it doesn't do what you expected, then skim through the code to see if you left out something or accidently made a typo.
i see what you did there
messageAll*
It seemed short...

i see what you did there
messageAll*
It seemed short...

I didn't even pick up on that typo; still, go test it out and see what is displayed. Working through problems instead of just having the answer spoonfed to you helps you learn it much easier. By doing this, once you finish looping through their names, you'd know how to loop through their bl_ids, players, and even loop through a different group's objects.

Heres what i did
Code: [Select]
function serverCmdTest()
{
 for(%i = 0; %i < ClientGroup.getCount(); %i++)
 {
  messageAll('',"\c3"@%i.name@"\c2's Ping is \c3"@%a@"\c2.");
  %a=%i.getPing();
 }
}
All i did is show, 's ping is .

%i is a number. You're looking for "1.name", "3.getPing()", etc. You're also setting the ping after the message which means it'll be one behind. (You won't see the last person's ping and the first will be "'s ping is".

Heres what i did
Code: [Select]
function serverCmdTest()
{
 for(%i = 0; %i < ClientGroup.getCount(); %i++)
 {
  messageAll('',"\c3"@%i.name@"\c2's Ping is \c3"@%a@"\c2.");
  %a=%i.getPing();
 }
}
All i did is show, 's ping is .

ClientGroup.getCount() returns an integer. The loop you're using is setting %i to 0, and incrementing %i each time it completes the code within the loop as long as it's still less than the interger ClientGroup.getCount() is returning. So currently that code is trying to access:

Code: [Select]
0.name
0.getPing()
1.name
1.getPing()
2.name
...

How can you use those integers to retrieve a client object? (Hint: look at my earlier posts)

Warning - while you were typing a new reply has been posted. You may wish to review your post.

Don't beat me :(

I found out what was wrong, thanks truce
Instead of doing %i in the messageAll command i needed to do clientGroup.GetObject(%i).Whatever
It was hard to find out but you showed me.
Thanks again.

ClientGroup.getCount() returns an integer. The loop you're using is setting %i to 0, and incrementing %i each time it completes the code within the loop as long as it's still less than the integer ClientGroup.getCount() is returning. So currently that code is trying to access:

Code: [Select]
0.name
0.getPing()
1.name
1.getPing()
2.name
...

How can you use those integers to retrieve a client object? (Hint: look at my earlier posts)

Warning - while you were typing a new reply has been posted. You may wish to review your post.

Don't beat me :(
this doesn't work because ure a failure