Raised This Month: $32 Target: $400
 8% 

Random player inside the sphere


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thezolotoi
Junior Member
Join Date: Apr 2021
Old 04-16-2021 , 16:14   Random player inside the sphere
Reply With Quote #1

Hello, help me to choose a random player who is inside the sphere.
I create a sphere like this:
PHP Code:
new iVictim 0;
while((
iVictim engfunc(EngFunc_FindEntityInSphereorigin1origin2400.0)))
{
//code

thezolotoi is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-16-2021 , 16:19   Re: Random player inside the sphere
Reply With Quote #2

PHP Code:
#define MAX_PLAYERS    32
#define IsPlayer(%1)    (1<=%1<=MAX_PLAYERS)
    
new iVictim 0;
new 
iPlayersMAX_PLAYERS ] , iNum iRandomPlayer;
    
while( ( 
iVictim engfuncEngFunc_FindEntityInSphere iVictim SphereCenterOrigin 400.0 ) ) )
{
    if ( 
IsPlayeriVictim ) )
        
iPlayersiNum++ ] = iVictim;


iRandomPlayer iPlayersrandomiNum ) ]; 
__________________

Last edited by Bugsy; 04-16-2021 at 16:29.
Bugsy is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 04-18-2021 , 15:50   Re: Random player inside the sphere
Reply With Quote #3

Code:
new iplayers[32], imax = find_sphere_class(0, "player", 400.0, iplayers, 32, origin) if (imax > 0) {    new randomplayer = iplayers[random(imax-1)] }

Last edited by jimaway; 04-18-2021 at 15:52.
jimaway is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode