Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
|
02-15-2021
, 23:29
Re: Execute server commands
|
#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 = ArrayCreate( 128 ); g_aFlags = ArrayCreate( 1 ); g_aHideCmd = ArrayCreate( 1 ); LoadCommands( ); }
public plugin_end( ) { TrieDestroy( g_tArrayPos ); ArrayDestroy( g_aCommands ); ArrayDestroy( g_aFlags ); ArrayDestroy( g_aHideCmd ); }
LoadCommands( ) { new szFilename[ 128 ]; get_configsdir( szFilename, 127 ); add( szFilename, 127, "/say_macros.ini" ); if( !file_exists( szFilename) ) { new iFile = fopen( szFilename, "wt" ); if( iFile ) { fclose( iFile ); } return; } new iFile = fopen( szFilename, "rt" ); if( !iFile ) { return; } new szData[ 512 ], szCommand[ 32 ], szExecute[ 128 ], szFlags[ 27 ], szHide[ 2 ], iPos; while( !feof( iFile ) ) { fgets( iFile, szData, 511 ); trim( szData ); if( !szData[ 0 ] || szData[ 0 ] == ';' || szData[ 0 ] == '/' && szData[ 1 ] == '/' ) { continue; } parse( szData, szCommand, 31, szExecute, 127, szFlags, 26, szHide, 1 ); strtolower( szCommand ); TrieSetCell( g_tArrayPos, szCommand, iPos ); ArrayPushString( g_aCommands, szExecute ); ArrayPushCell( g_aFlags, read_flags( szFlags ) ); ArrayPushCell( g_aHideCmd, str_to_num( szHide ) ); iPos++; } fclose( iFile ); }
public CmdSay( client ) { static szMessage[ 194 ], pos, i, szTmp[ 5 ]; static szArg[MAX_ARGS][MAX_ARG_LEN], argsCnt; static szCommand[32]
read_args( szMessage, 193 );
argsCnt = 0; pos = argparse(szMessage, pos, szCommand, charsmax(szCommand)); while( pos > 0 && argsCnt < sizeof(szArg) ) { pos = argparse(szMessage, pos, szArg[argsCnt], charsmax(szArg[])) if( pos > 0 ) { format(szCommand, charsmax(szCommand), "%s $%d", szCommand, ++argsCnt) } }
strtolower( szCommand );
static iArrayPos; if( TrieGetCell( g_tArrayPos, szCommand, iArrayPos ) ) { if( !access( client, ArrayGetCell( g_aFlags, iArrayPos ) ) ) { client_print( client, print_chat, "* You have no access to that command!" ); } else { static szExecute[ 128 ]; ArrayGetString( g_aCommands, iArrayPos, szExecute, 127 ); static szName[ 32 ]; get_user_name( client, szName, 31 ); replace_all( szName, 31, "'", "" ); replace_all( szName, 31, "^"", "" ); 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_all( szExecute, 127, "''", "^"" ); 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
|
|