Blockland Forums > Modification Help
Randomizing
Ipquarx:
--- Code: ---function getRandomClient()
{
return ClientGroup.getObject(getRandom(0, ClientGroup.getCount() - 1));
}
--- End code ---
Treynolds416:
--- Quote from: Ipquarx on March 04, 2012, 12:04:28 PM ---
--- Code: ---function getRandomClient()
{
return ClientGroup.getObject(getRandom(0, ClientGroup.getCount() - 1));
}
--- End code ---
--- End quote ---
That's the exact same thing as port's, except without the safety check.
Ipquarx:
Any decent script shouldn't try to get a random client if there are no clients.
phflack:
--- Quote from: Ipquarx on March 04, 2012, 12:04:28 PM ---
--- Code: ---function getRandomClient()
{
return ClientGroup.getObject(getRandom(0, ClientGroup.getCount() - 1));
}
--- End code ---
--- End quote ---
--- Quote from: Ipquarx on March 04, 2012, 09:41:13 PM ---Any decent script shouldn't try to get a random client if there are no clients.
--- End quote ---
interesting...
also, would this work?
--- Code: ---function getRandomClient()
{
if(clientGroup.getCount())
return clientGroup.getObject(getRandom(0, clientGroup.getCount() - 1));
return -1;
}
--- End code ---
basicaly, number besides 0 returns true, right?
Chrono:
Yes. Phflack's code is recommended.
Although I cannot think of a case where you would get a random client in an empty server (rationally)