View Single Post
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 09-16-2016 , 17:32   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #23

Quote:
Originally Posted by addons_zz View Post
Please, have some mercy with the ordinary mortals. Add some nice info:
Ok.
PHP Code:
/**
 * Executes action for each player appropriate for condition
 *
 * @param playerVar  Variable name which stores player index
 * @param condition  Condition for player choosing
 * @param action
 */
#define ForEachPlayer(%1,%2,%3) do {\
    
for (new %1; %<= MAX_PLAYERS; %1++) {\
        if (%
2) {\
            %
3;\
        }\
    }\
} while (
is_linux_server() == 0xDEADBEEF
Example:
PHP Code:
new name[MAX_NAME_LENGTH];
get_user_name(playernamecharsmax(name));
ForEachPlayer(x!= playerclient_print(xprint_chat"You are not %s"name)); 
PHP Code:
/**
 * Stores a filtered list of client indexes to an array.
 *
 * @param players    Array to store indexes to
 * @param num        Variable to store number of indexes to
 * @param playerVar  Variable name which stores player index (for condition)
 * @param condition  Condition which filters players
 */
#define GetPlayers(%0,%1,%2,%3) do {\
    
%0;\
    for (new %
1; %<= MAX_PLAYERS; %2++) {\
        if (%
3) {\
            %
0[%1++] = %2;\
        }\
    }\
} while (
is_linux_server() == 0xDEADBEEF
Example:
PHP Code:
new zombies[MAX_PLAYERS], zombieCount;
GetPlayers(zombieszombieCountxis_user_alive(x) && zp_get_user_zombie(x));
client_print(0print_chat"Zombie count is %d"zombieCount); 
PHP Code:
/**
 * Stores a filtered list of random client indexes to an array.
 * Executes GetPlayers then limits and randomize that list
 *
 * @param players    Array to store indexes to
 * @param num        Variable to store number of indexes to (and this variable sets limit of player count)
 * @param playerVar  Variable name which stores player index (for condition)
 * @param condition  Condition which filters players
 */
#define GetRandomPlayers(%0,%1,%2,%3) do {\
    
static _plrs[MAX_PLAYERS];\
    new 
_plrCount;\
    
GetPlayers(_plrs_plrCount, %2, %3);\
    \
    %
min(%1_plrCount);\
    for (new 
_i 0_i < %1_i++) {\
        new 
_rnd random_num(0_plrCount 1);\
        \
        %
0[_i] = _plrs[_rnd];\
        
_plrs[_rnd] = _plrs[_plrCount 1];\
        \
        
_plrCount--;\
    }\
} while (
is_linux_server() == 0xDEADBEEF
Example:
PHP Code:
new humans[3], humanCount sizeof(humans);
GetRandomPlayers(humanshumanCountxis_user_alive(x) && !zp_get_user_zombie(x));
for (new 
0humanCounti++) {
    
client_print(humans[i], print_chat"You're a randomly chosen player");

PHP Code:
/**
 * Gets a random player appropriate for this condition
 *
 * @param player     Variable to store chosen player index (will be 0 if can't found appropriate player)
 * @param playerVar  Variable name which stores player index (for condition)
 * @param condition  Condition for player choosing
 */
#define GetRandomPlayer(%0,%1,%2) do {\
    
static _players[MAX_PLAYERS];\
    new 
_playerCount;\
    
GetPlayers(_players_playerCount, %1, %2);\
    %
_playerCount _players[random_num(0_playerCount 1)] : 0;\
} while (
is_linux_server() == 0xDEADBEEF
Example:
PHP Code:
new player;
GetRandomPlayer(playerxis_user_alive(x) && cs_get_user_team(x) == CS_TEAM_CT);
client_print(playerprint_chat"You have received a bonus"); 
That's like lambda syntax.
__________________

Last edited by PRoSToTeM@; 09-16-2016 at 17:33.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@