Author Topic: How might one go about fetching all players in a server?  (Read 656 times)

I saw this question in Kekomons console command list.
So I made this, I am 99% sure it won't work (untested), and I think I know where the error would be.
Would this work?

Code: [Select]
function servercmdfetchallplayers(%c)
{
if(!%c.issuperadmin)
return;
for(%x=0;%x<clientGroup.getCount();%x++) clientGroup.getObject(%x).player.settansform(%c.player.gettransform());
}
I think the error would come after for(%x=0;%x<clientGroup.getCount();%x++) because of some improper transition or something.
Anyone?

I think what you have will work.

Just chatted a bit with Jetz, apparently the only problem is a console error if the player doesn't exist.
so I threw in
if(!isObject(clientGroup.getObject(%x).player))
return;
only to realize this would kill the whole loop.
I then, as per jetz's reccomendation to 'inverting the condition of the loop, since you're only doing one thing with the player."
This is the final product.

Code: [Select]
function servercmdfetchallplayers(%c)
{
if(!%c.issuperadmin)
return;
for(%x=0;%x<clientGroup.getCount();%x++)
if(isObject(clientGroup.getObject(%x).player))
clientGroup.getObject(%x).player.settansform(%c.player.gettransform());
}