View Single Post
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-15-2021 , 23:29   Re: Execute server commands
Reply With Quote #2

I think this should work (requires AMX Mod X 1.9.0 or newer):

PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < celltrie >

#define MAX_ARGS 5
#define MAX_ARG_LEN 64

new Trie:g_tArrayPos;
new Array:
g_aCommands;
new Array:
g_aFlags;
new Array:
g_aHideCmd;

public 
plugin_init( ) {
    
register_plugin"Say Command Macro""0.0.2f1""Exolent" );
    
    
register_clcmd"say""CmdSay" );
    
    
g_tArrayPos TrieCreate( );
    
g_aCommands ArrayCreate128 );
    
g_aFlags ArrayCreate);
    
g_aHideCmd ArrayCreate);
    
    
LoadCommands( );
}

public 
plugin_end( ) {
    
TrieDestroyg_tArrayPos );
    
ArrayDestroyg_aCommands );
    
ArrayDestroyg_aFlags );
    
ArrayDestroyg_aHideCmd );
}

LoadCommands( ) {
    new 
szFilename128 ];
    
get_configsdirszFilename127 );
    
addszFilename127"/say_macros.ini" );
    
    if( !
file_existsszFilename) ) {
        new 
iFile fopenszFilename"wt" );
        if( 
iFile ) {
            
fcloseiFile );
        }
        return;
    }
    
    new 
iFile fopenszFilename"rt" );
    if( !
iFile ) {
        return;
    }
    
    new 
szData512 ], szCommand32 ], szExecute128 ], szFlags27 ], szHide], iPos;
    while( !
feofiFile ) ) {
        
fgetsiFileszData511 );
        
trimszData );
        
        if( !
szData]
        || 
szData] == ';'
        
|| szData] == '/' && szData] == '/' ) {
            continue;
        }
        
        
parseszDataszCommand31szExecute127szFlags26szHide);
        
strtolowerszCommand );
        
TrieSetCellg_tArrayPosszCommandiPos );
        
ArrayPushStringg_aCommandsszExecute );
        
ArrayPushCellg_aFlagsread_flagsszFlags ) );
        
ArrayPushCellg_aHideCmdstr_to_numszHide ) );
        
iPos++;
    }
    
    
fcloseiFile );
}


public 
CmdSayclient ) {
    static 
szMessage194 ], posiszTmp];
    static 
szArg[MAX_ARGS][MAX_ARG_LEN], argsCnt;
    static 
szCommand[32]

    
read_argsszMessage193 );

    
argsCnt 0;
    
pos argparse(szMessageposszCommandcharsmax(szCommand));
    while( 
pos && argsCnt sizeof(szArg) )
    {
        
pos argparse(szMessageposszArg[argsCnt], charsmax(szArg[]))
        if( 
pos )
        {
            
format(szCommandcharsmax(szCommand), "%s $%d"szCommand, ++argsCnt)
        }
    }

    
strtolowerszCommand );

    static 
iArrayPos;
    if( 
TrieGetCellg_tArrayPosszCommandiArrayPos ) ) {
        if( !
accessclientArrayGetCellg_aFlagsiArrayPos ) ) ) {
            
client_printclientprint_chat"* You have no access to that command!" );
        } else {
            static 
szExecute128 ];
            
ArrayGetStringg_aCommandsiArrayPosszExecute127 );
            
            static 
szName32 ];
            
get_user_nameclientszName31 );
            
replace_allszName31"'""" );
            
replace_allszName31"^"", "" );
            
            static szAuthid[ 35 ];
            get_user_authid( client, szAuthid, 34 );
            
            static szIP[ 32 ];
            get_user_ip( client, szIP, 31, 1 );
            
            static szUserid[ 6 ];
            formatex( szUserid, 5, "
#%i", get_user_userid( client ) );
            
            
replace_allszExecute127"''""^"" );
            replace_all( szExecute, 127, "
$name", szName );
            replace_all( szExecute, 127, "
$steamid", szAuthid );
            replace_all( szExecute, 127, "
$ip", szIP );
            replace_all( szExecute, 127, "
$userid", szUserid );
            for( i=0; i<argsCnt; i++ ) {
                format( szTmp, 4, "
$%d", i+1);
                replace_all( szExecute, 127, szTmp, szArg[i] );
            }

            server_cmd( "
%s", szExecute );
            
            if( ArrayGetCell( g_aHideCmd, iArrayPos ) ) {
                return PLUGIN_HANDLED;
            }
        }
    }
    
    return PLUGIN_CONTINUE;

__________________

Last edited by fysiks; 02-27-2021 at 19:30. Reason: Fixed plugin
fysiks is offline