AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Random player on a team (https://forums.alliedmods.net/showthread.php?t=45386)

Cheap_Suit 10-01-2006 02:30

Random player on a team
 
I was just wondering if this is the right way to do it and/or a what is a more efficient way to do this.

Code:

get_players(Players, iNum, "ae", "TERRORIST")
while(!is_user_alive(g_var[terrorist]))
{
                              // from 0?
  g_var[terrorist] = random_num(Players[1], Players[iNum])

}

XxAvalanchexX 10-01-2006 02:32

Re: Random player on a team
 
Code:
get_players(Players, iNum, "ae", "TERRORIST") g_var[terrorist] = Players[random_num(0,iNum-1)];

Cheap_Suit 10-01-2006 02:44

Re: Random player on a team
 
lol. Works great! Thanks.

Cheap_Suit 10-02-2006 00:43

Re: Random player on a team
 
This is sorta in the same topic. So what about this one?

PHP Code:

        new Float:tempOrigin[3]
        
tempOrigin[2] = fOrigin[2] + 20.0
        
while(PointContents(tempOrigin) != CONTENTS_EMPTY)
        {
            switch(
random_num(03))
            {
                case 
0tempOrigin[0] = fOrigin[0] - random_float(35.050.0), tempOrigin[1] = fOrigin[1] - random_float(35.050.0)
                case 
1tempOrigin[0] = fOrigin[0] - random_float(35.050.0), tempOrigin[1] = fOrigin[1] + random_float(35.050.0)
                case 
2tempOrigin[0] = fOrigin[0] + random_float(35.050.0), tempOrigin[1] = fOrigin[1] - random_float(35.050.0)
                case 
3tempOrigin[0] = fOrigin[0] + random_float(35.050.0), tempOrigin[1] = fOrigin[1] + random_float(35.050.0)
            }
            
            if(
PointContents(tempOrigin) == CONTENTS_EMPTY)
            {
                
// do stuff

                
break
            } 

trying to check 4 random origins untill one is CONTENTS_EMPTY.

Emp` 10-02-2006 18:24

Re: Random player on a team
 
i would rather do something like this
PHP Code:

        new Float:tempOrigin[3], Float:max 50.0bool:found false
        tempOrigin
[2] = fOrigin[2] + 20.0
        
while(PointContents(tempOrigin) != CONTENTS_EMPTY)
        {
            for(new 
i=0i<3i++)
            {
               switch(
i)
               {
                   case 
0:{
                      
tempOrigin[0] = fOrigin[0] - random_float(max-15max)
                      
tempOrigin[1] = fOrigin[1] - random_float(max-15max)
                   }
                   case 
1:{
                      
tempOrigin[0] = fOrigin[0] - random_float(max-15max)
                      
tempOrigin[1] = fOrigin[1] + random_float(max-15max)
                   }
                   case 
2:{
                      
tempOrigin[0] = fOrigin[0] + random_float(max-15max)
                      
tempOrigin[1] = fOrigin[1] - random_float(max-15max)
                   }
                   case 
3:{
                      
tempOrigin[0] = fOrigin[0] + random_float(max-15max)
                      
tempOrigin[1] = fOrigin[1] + random_float(max-15max)
                   }
               }
               if(
PointContents(tempOrigin) == CONTENTS_EMPTY)
               {
                   
found true
                   
break
               }
            }
            if(
found)
            {
                
// do stuff

                
break
            }
            else
                
max += 15
         



Zenith77 10-02-2006 19:39

Re: Random player on a team
 
This is a good scenrio for a recrusive function. My only fear of using this is that it might hang up the game, even if it's for like a quater of a second.

Cheap_Suit 10-02-2006 22:51

Re: Random player on a team
 
Thanks Emp


All times are GMT -4. The time now is 04:48.

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