Raised This Month: $18 Target: $400
 4% 

AMX Mod X Stocks (Custom useful stocks)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
happy_2012
Senior Member
Join Date: Aug 2012
Old 09-13-2016 , 16:43   AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #1

Hello,
So I have been coding some private plugins, and I came up with a various set of custom stocks, so I moved them to an include file, and decided to share them, perhaps they can be useful for you and your own plugins!

By including this file, you will not need to include amxmodx module in your plugin as we check it, and if it is not included, it will be automatically included.

Code is available on GitHub @ https://github.com/Chilimax/AMX-Mod-...amx_stocks.inc

I am seriously looking forward some ideas and suggestions to improve this code and make it much more useful
happy_2012 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Location: Muslim and proud!
Old 09-13-2016 , 16:47   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #2

This is lame...

Last edited by Natsheh; 06-19-2017 at 02:24.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 09-13-2016 , 17:47   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #3

Quote:
Originally Posted by happy_2012 View Post
I am seriously looking forward some ideas and suggestions to improve this code and make it much more useful
You may follow the AMXX doc style. It is helpful to see it/have it.
Code:
/* Core functions * * (c) Copyright 1998-2003, ITB CompuPhase * * This file is provided as is (no warranties). */ /**  * Returns the free memory space available to the plugin.  *  * @note This is a debugging function that is not intended for general plugin  *       use.  *  * @return  Free memory space in bytes  */ native heapspace(); /**  * Returns the function index of a public function declared in the plugin.  *  * @param name  Function name  *  * @return      Function index > 0 on success, -1 if function was not found  * @error       If the function name is too long (longer than 63 characters)  *              an error will be thrown.  */ native funcidx(const name[]); /**  * Returns the number of arguments passed into the currently executed function.  *  * @return  Number of arguments passed  */ native numargs(); /**  * Retrieves an argument value passed into the currently executed function.  *  * @param arg       Argument index  * @param index     Index to retrieve from the argument (for arrays and strings)  *  * @return          Argument value at given index  */ native getarg(arg, index = 0); /**  * Sets the value of an argument passed into the currently executed function.  *  * @note This is not equal to assigning a new value to a by-reference argument.  *  * @param arg       Argument index  * @param index     Index to set in the argument (for arrays and strings)  */ native setarg(arg, index = 0, value);
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 09-13-2016 at 17:49. Reason: misspelling
addons_zz is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 09-13-2016 , 18:13   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #4

How can this be helpful mate? What I meant by ideas is new features
happy_2012 is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 09-13-2016 , 18:41   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #5

Quote:
Originally Posted by happy_2012 View Post
How can this be helpful mate? What I meant by ideas is new features
Looks like there is not much code on it for now, so as it is simpler, there is no problem.
But, just gathering bunches of code together without a proper documentation is not helpful.
At least it is my preference, instead of get on that nightmare, I prefer start a clean notion one from zero.
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective
addons_zz is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 09-13-2016 , 19:13   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #6

I will add notes on each stock
happy_2012 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-13-2016 , 21:51   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #7

get_connected_target() makes no sense. What is it supposed to be doing?
__________________
fysiks is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 09-14-2016 , 06:21   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #8

you can use it to choose a random connected player
get_connected_target( random_num( 1, 32 ) ) I see it pretty useful in plugins which choose a random player regardless if they were dead or alive e.g deathrun terrorist choosing

Last edited by happy_2012; 09-14-2016 at 06:22.
happy_2012 is offline
[email protected]
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 09-14-2016 , 11:54   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #9

What about this?:
PHP Code:
#if !defined MAX_PLAYERS
const MAX_PLAYERS 32;
#endif

stock GetPlayers(players[MAX_PLAYERS], const predicateFuncName[]) {
#if !defined MaxClients
    
static MaxClients = -1;
    if (
MaxClients == -1) {
        
MaxClients get_maxplayers();
    }
#endif
    
    
new count 0;
    new 
predFuncId get_func_id(predicateFuncName);
    for (new 
1<= MaxClientsi++) {
        
callfunc_begin_i(predFuncId);
        
callfunc_push_int(i);
        if (
bool:callfunc_end()) {
            
players[count++] = i;
        }
    }
    
    return 
count;
}

stock GetRandomPlayers(randomPlayers[], randomPlayerCount, const predicateFuncName[]) {
    static 
players[MAX_PLAYERS];
    new 
playerCount GetPlayers(playerspredicateFuncName);
    
    new 
realCount min(randomPlayerCountplayerCount);
    for (new 
0realCounti++) {
        new 
rand random_num(0playerCount 1);
        
        
randomPlayers[i] = players[rand];
        
players[rand] = players[playerCount 1];
        
        
playerCount--;
    }
    
    return 
realCount;
}

stock GetRandomPlayer(const predicateFuncName[]) {
    new 
player[1];
    return 
GetRandomPlayers(player1predicateFuncName) ? player[0] : 0;

Example:
PHP Code:
    register_clcmd("say /smth""OnClientCommand_Say_Smth");
}

public 
bool:IsPlayerAliveAdmin(clientEntIndex) {
    return 
is_user_alive(clientEntIndex) && is_user_admin(clientEntIndex);
}

public 
OnClientCommand_Say_Smth(clientEntIndex) {
    
client_print(clientEntIndexprint_chat"RandPl: %d"GetRandomPlayer("IsPlayerAliveAdmin"));
    
    static 
players[MAX_PLAYERS];
    new 
count GetRandomPlayers(playerssizeof(players), "IsPlayerAliveAdmin");
    
client_print(clientEntIndexprint_chat"RandPlCount: %d"count);
    for (new 
0counti++) {
        
client_print(clientEntIndexprint_chat"RandPl#%d: %d"iplayers[i]);
    }
    
    
count GetPlayers(players"IsPlayerAliveAdmin");
    
client_print(clientEntIndexprint_chat"PlCount: %d"count);
    for (new 
0counti++) {
        
client_print(clientEntIndexprint_chat"Pl#%d: %d"iplayers[i]);
    }

__________________

Last edited by [email protected]; 09-14-2016 at 11:54.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-14-2016 , 21:16   Re: AMX Mod X Stocks (Custom useful stocks)
Reply With Quote #10

Quote:
Originally Posted by happy_2012 View Post
you can use it to choose a random connected player
get_connected_target( random_num( 1, 32 ) ) I see it pretty useful in plugins which choose a random player regardless if they were dead or alive e.g deathrun terrorist choosing
Umm . . . no. First, the function name doesn't describe what the function is actually doing (it doesn't do anything logical). Second, the function will fail relatively often (i.e. return -1). Third, if you want a truly random player, you should do this:

PHP Code:
stock get_random_player()
{
    new 
iPlayers[32], iPlayersNum
    get_players
(iPlayersiPlayersNum)
    return 
iPlayers[random(iPlayersNum)]

This will always return a valid player unless there are zero players on the server.
__________________
fysiks 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 13:36.


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