AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Array of ID's + Random (https://forums.alliedmods.net/showthread.php?t=171419)

GalegO 11-05-2011 16:49

Array of ID's + Random
 
Hi guys, is possible to make a array with the Players ID and after read this array and run the random to catch one of them?

Ex: read all CT's ID, storage and after catch just one randomly.

Thanks!

TheArmagedon 11-05-2011 16:57

Re: Array of ID's + Random
 
@BP - Assim deve funcionar...
@US - This code should work...

PHP Code:

new playerss[32], num;
get_players(playerssnum"c""COUNTER-TERRORIST");


if(
num)
{
    new 
playerrandom playerss[random(num)];

    
anything(playerrandom); // exec the command for the random player



Emp` 11-05-2011 16:59

Re: Array of ID's + Random
 
Use get_players but note:
Quote:

Originally Posted by ConnorMcLeod (Post 1589229)
Flags are ok, except for "e" flag when "a" flag is not used.

If you don't want to use the "e" flag, then you can do something along the lines of:

Code:

new iPlayers[32], iPnum;
get_players( iPlayers, iPnum )

for ( new i; i < iPnum; i++ )
{
    if ( cs_get_user_team( iPlayers[i] ) != CS_TEAM_CT )
          iPlayers[ i-- ] = iPlayers[ iPnum-- ];
}

if ( iPnum > 0 )
{
    new iRandomPlayer = iPlayers[ random( iPnum ) ];
}

edit:

Quote:

Originally Posted by TheArmagedon (Post 1590864)
@BP - Assim deve funcionar...
@US - This code should work...

PHP Code:

new playerss[33], num;
get_players(playerssnum"c""CS_TEAM_CT");


if(
num)
{
    new 
playerrandom playerss[random(num)];

    
anything(playerrandom); // exec the command for the random player



You need to use team names for get_players, not the CS_TEAM_* constants.

GalegO 11-05-2011 17:09

Re: Array of ID's + Random
 
Thanks Again Emp`, I tried some logicals, but not make sense or dosen't worked.

I just can't find the correct logical.

EDIT: Sorry, Thanks tou too TheArmageddon :)

TheArmagedon 11-05-2011 17:10

Re: Array of ID's + Random
 
@emp
oh, thank you, fixed!


All times are GMT -4. The time now is 14:27.

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