Raised This Month: $12 Target: $400
 3% 

AMX Mod X Stocks (Custom useful stocks)


Post New Thread Reply   
 
Thread Tools Display Modes
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-16-2016 , 15:06   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #21

A one-time-execute do-while loop wrapping your code. Also, use functions for what doesn't have to be a macro, much more readable and maintainable.
klippy is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 09-16-2016 , 15:32   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #22

Quote:
Originally Posted by PRoSToTeM@ View Post
PHP Code:
#define GetPlayers(%0,%1,%2,%3) do {\ 
When someone is writhing macros:



Please, have some mercy with the ordinary mortals. Add some nice info:
Code:
/**  * @param the 'gal_srv_..._restart' pointer  * @param the game cvar pointer as 'cvar_mp_timelimit'.  * @param the current game limit as an integer. Example: 'map_getMinutesElapsedInteger(0)'.  * @param the object identification number to be destroyed.  */ #define GetPlayers(%0,%1,%2,%3) do {\
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective
addons_zz is offline
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@
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 09-16-2016 , 23:15   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #24

Quote:
Originally Posted by PRoSToTeM@ View Post
Ok.
Good work. On the beginning I did not understood what means `condition`, but from your examples I got them are boolean values, them we may say they are `boolean condition`.
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective
addons_zz is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 05-28-2017 , 02:44   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #25

Quote:
Originally Posted by addons_zz View Post
Good work. On the beginning I did not understood what means `condition`, but from your examples I got them are boolean values, them we may say they are `boolean condition`.
They are any kind of condition you wanne be, you didn't see here:
PHP Code:
if(%3)\ 

Last edited by Craxor; 05-28-2017 at 02:44.
Craxor is offline
Send a message via ICQ to Craxor
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-28-2017 , 04:29   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #26

Code:
09-16-16
:facepalm:
__________________
HamletEagle is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 05-28-2017 , 05:46   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #27

If i'm bored it doesn't matter if i revive old threads
Craxor is offline
Send a message via ICQ to Craxor
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 05-28-2017 , 15:34   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #28

Look at Prostotem@ post, holy freking shit. He can't be human.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 06-17-2017 , 13:12   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #29

Someone change Prostostem@ title to "Russian AI BOT"
__________________
Depresie is offline
Reply


Thread Tools
Display Modes

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 03:18.


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