Getting a random ID - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Getting a random ID (
/showthread.php?tid=106765)
Getting a random ID -
Striker_Moe - 05.11.2009
Hi.
Is there any way to get a random ID which is connected?
Thanks.
Re: Getting a random ID -
Kurence - 05.11.2009
Like i was saying:
new playa=random(MAX_PLAYERS);
if(IsPlayerConnected(playa)) Kick(playa);
-This will kick RANDOM CONNECTED playa
Re: Getting a random ID -
Harry_Gaill - 05.11.2009
Quote:
-This will kick RANDOM CONNECTED playa
|
Wrong, it just won't.
Re: Getting a random ID -
Correlli - 05.11.2009
Quote:
Originally Posted by Harry_Gaill [adream-rp.com
]
Quote:
-This will kick RANDOM CONNECTED playa
|
Wrong, it just won't.
|
It will, if player is connected.
Re: Getting a random ID -
DeathOnaStick - 05.11.2009
If you want to be sure, that really somebody is kicked at this time, but you still want it to be randomly, you may try this:
pawn Код:
new playa=random(MAX_PLAYERS);
if(IsPlayerConnected(playa)==0)
{
while(IsPlayerConnected(playa)==0)
{
playa=random(MAX_PLAYERS);
}
}
if(IsPlayerConnected(playa)) Kick(playa);
I used a "If" before, because it makes me better to notice what's going on. I think you actually could just delete it.
This might not be the best sollution, but i guess it does, what you want it to do.
Pls correct me if i'm wrong. Thanks.
Cheers,
DeathOnaStick
Re: Getting a random ID -
Harry_Gaill - 12.11.2009
Quote:
Originally Posted by Don Correlli
Quote:
Originally Posted by Harry_Gaill [adream-rp.com
]
Quote:
-This will kick RANDOM CONNECTED playa
|
Wrong, it just won't.
|
It will, if player is connected.
|
It will because you can't kick someone who's not connected. I bet
if(Kick(id)) { success } would have done the job as well, but that's not my point.
It might have been the topic-starter's fault, he didn't really specify what he really wants to achieve. Kick a random player from the actual list, or randomize a number and take action if that number happens to be a valid ID.