Getting a random ID
#1

Hi.

Is there any way to get a random ID which is connected?


Thanks.
Reply
#2

Like i was saying:
new playa=random(MAX_PLAYERS);
if(IsPlayerConnected(playa)) Kick(playa);
-This will kick RANDOM CONNECTED playa
Reply
#3

Quote:

-This will kick RANDOM CONNECTED playa

Wrong, it just won't.
Reply
#4

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.
Reply
#5

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
Reply
#6

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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)