Quote:
Originally Posted by [uL]Pottus
It's all about your steps.
1) Get all players into a list that are in range of point
2) Was any players found?
No - Return INVALID_PLAYER_ID;
Yes - Proceed to step 3
3) How many players?
One player - return ID
Two players - return random ID
That gives a basic algorithm of steps to perform.
I didn't test pretty sure I got it right based on the above steps
pawn Код:
stock GetRandomPlayerInRange(Float:X,Float:Y,Float:Z,Float:Range) { // List of in range players new InRangeList[MAX_PLAYERS] = { INVALID_PLAYER_ID, ... };
// How many in range players there is new InRangeCount; // Gather in range players (Change this to foreach() for(new i = 0; i < MAX_PLAYERS; i++) { if(IsPlayerConnected(i)) { if(IsPlayerInRangeOfPoint(i, range, X, Y, Z)) InRangeList[InRangeCount++] = i; } }
// There are players in range if(InRangeCount) { // Only one? Return that ID if(InRangeCount == 1) return InRangeList[0]; // More than one return a random ID else { new r = Random(InRangeCount); return InRangeList[r]; } } // No one in range return INVALID_PLAYER_ID return INVALID_PLAYER_ID; }
|
I think my version is much smaller than your but yea i can do like that too
Quote:
Originally Posted by CyNiC
I think that's need to declare 'randPlayer' as 255 or nothing will happen.
|
You're right xD