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

Execute server commands


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Creator7
Junior Member
Join Date: Feb 2021
Old 02-15-2021 , 08:20   Execute server commands
Reply With Quote #1

Hi,

I found a plugin online, and I don't remember exactly where I took it (here or from other communities) and now I can't find it, and I'd like to make a small modification to .sma if it is possible, but I'm not a AMXX Developer, so I want someone to do it from for me.

.SMA File
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.2", "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 ], len, i, j, k, szTmp[ 5 ];
    static szArg[MAX_ARGS][MAX_ARG_LEN], argsCnt;
    read_args( szMessage, 193 );

    len = strlen(szMessage)-1
    argsCnt = i = j = 0
    k = -1
    while(++i<len){
        if(k>=0){
            if(szMessage[i] == '^"'){
                szArg[argsCnt++][k] = '^0';
                k=-1;
                j += formatex( szMessage[j], 193-j, "$%d", argsCnt );
            }else{
                if(k<MAX_ARG_LEN)
                    szArg[argsCnt][k++] = szMessage[i];
            }
        }else{
            if(szMessage[i] == '^"'){
                if(argsCnt<MAX_ARGS)
                    k=0;
            }else{
                szMessage[j++] = szMessage[i];
            }
        }
    }
    szMessage[j] = '^0';
    if(k!=-1){
        szArg[argsCnt++][k] = '^0';
    }
    strtolower( szMessage );

    static iArrayPos;
    if( TrieGetCell( g_tArrayPos, szMessage, 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;
}
I'll explain exactly what I need, and I think it won't be difficult for you to edit it.

I finished and used the config file for this plugin, and added what I want, but there is something I want to make it work differently.

This plugin mainly works when typing in chat:

!kick "nick" "reason"
!slap "name" "power"

But the problem now is that I need to write "" quotes to make the plugin work, but I want to make it work, with and without the quotes:

!kick nick reason, and !kick "nick" "reason"

Config File:
Code:
; "say command" "execute command" "admin flags" "hide command from chat"
; 
; Example:
; "menu" "amxmodxmenu" "u" "1"
; This will work when you say:
; say "menu"
; And it will hide your text "menu" from chat
; 
; To not hide the text, leave that part out, or set it to 0
; Example:
; "menu" "amxmodxmenu" "u"
; "kickmenu" "amx_kickmeu" "u" "0"
; 
; In the execute command, you can use these to pass yourself into the execute:
; - $name = your name
; - $steamid = your steamid
; - $ip = your ip
; - $userid = your userid
; 
; Example:
; "godon" "amx_godmode $userid 1" "m"
; "godoff" "amx_godmode $userid 0" "m"
;
; You can also use '' (two apostrophes) to represent quotes inside of the execute command,
; since (example) "amx_nick "name1" "name2"" would cause errors.
; 
; Example:
; "gametype hns" "amx_gametype ''HideNSeek Mod''; exec ''addons/amxmodx/configs/hidenseek.cfg''; sv_restart 1" "a"
; 
; If you are using the $name, $ip, or $steamid in a way that needs quotes,
; you will need to add them yourself.
; 
; Example:
; "ban me" "amx_ban ''$steamid'' 0 ''lol banned myself :D''" ""
;
;
; Passing arguments from chat to execute command:
; before comparing chat input to defined say commands, all "CONTENT" are replaced with $1, $2, $3
; after that all $number in execute command are replaced with adequate CONTENT
;
; Example1:
; "csay $1 color $2" "amx_csay $2 $name said $1 using $2 color" ""
; now if player named Player1 write in chat: csay "some message" color "green"
; then it will trigger in server console: "amx_csay green Player1 said some message using green color"
;
; Example2;
; "!nick $1 $2" "amx_nick ''$1'' ''$2''" ""
; now writing in chat: !nick "player1" "test nick"
; will trigger in server console: "amx_nick ^"Player1^" ^"test nick^""
;
; More examples (you can use them all at the same time):
; "!kick $1" "amx_kick ''$1''" "c"    ;kick without reason
; "!kick $1 $2" "amx_kick ''$1'' ''$2''" "c"    ;kick with reason
; "!ban5 $1" "amx_ban ''$1'' 5" "d"    ;short ban without reason
; "!ban5 $1 $2" "amx_ban ''$1'' 5 ''$2''" "d"    ;short ban with reason
; "!pban $1 $2" "amx_ban ''$1'' 0 ''$2''" "d"    ;permanent ban with reason
; "!hostname $1" "hostname ''$1''" "a"    ;set hostname
---------------------------------------------------------------------------
"!amxmodmenu" "amxmodmenu"
"!banmenu" "amx_banmenu"
"!kickmenu" "amx_kickmenu"
"!gagmenu" "amx_gagmenu"
"!slapmenu" "amx_slapmenu"
"!slaymenu" "amx_slapmenu"
"!showloc" "amx_showloc"
"!who" "amx_who"
---------------------------------------------------------------------------
"!kick $1" "amx_kick ''$1''"
"!kick $1 $2" "amx_kick ''$1'' ''$2''"
"!slay $1" "amx_slay $1"
"!slap $1" "amx_slap ''$1''"
"!slap $1 $2" "amx_slap ''$1'' ''$2''"
---------------------------------------------------------------------------
Thanks for your time!

Last edited by Creator7; 02-15-2021 at 08:21.
Creator7 is offline
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
Creator7
Junior Member
Join Date: Feb 2021
Old 02-16-2021 , 08:15   Re: Execute server commands
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
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.2""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[]))
    }

    
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;

Thanks for your help, it works perfectly!
Creator7 is offline
Creator7
Junior Member
Join Date: Feb 2021
Old 02-17-2021 , 03:39   Re: Execute server commands
Reply With Quote #4

@fysiks

https://forums.alliedmods.net/showthread.php?p=611167

I have this plugin running on my server, but I am using a private ban system, however, smart_slash works on default ban system, but not on the private one.

Any help? I can give you any info if needed.
Creator7 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-18-2021 , 00:31   Re: Execute server commands
Reply With Quote #5

Since your question is about a different plugin and that plugin is published here, you should post on that plugin's thread.
__________________
fysiks is offline
Creator7
Junior Member
Join Date: Feb 2021
Old 02-25-2021 , 17:33   Re: Execute server commands
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
Since your question is about a different plugin and that plugin is published here, you should post on that plugin's thread.
Hello,

It looks like the problem was about the Ban-system which I am using, it's not compatible with any other plugin as I can see, nothing can work with it.


I ask for a request in the first message in this thread, today I did test it and it's not working to ban with out quotes, can you do double check and fix the problem please?

with your code, it doesn't work with either quotes or without.
Creator7 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-25-2021 , 23:07   Re: Execute server commands
Reply With Quote #7

If you think it's your ban plugin, how can we help you with that unless you tell us what ban plugin you're using?
__________________

Last edited by fysiks; 02-25-2021 at 23:09.
fysiks is offline
Creator7
Junior Member
Join Date: Feb 2021
Old 02-26-2021 , 10:36   Re: Execute server commands
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
If you think it's your ban plugin, how can we help you with that unless you tell us what ban plugin you're using?
yeah, it was my ban system which I am now not using anymore.

Everything should be fine after you do the request, I tested the plugin with both ban systems, one works and the other no, now you only need to do the request if you can, which is the ability to ban without quotes, as when you edited it few day's ago, the plugin stopped working with both quotes and without, maybe you can give it a test on your local server.

Thanks I appreciate!
Creator7 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-26-2021 , 23:02   Re: Execute server commands
Reply With Quote #9

Give me some examples of what you're typing in chat that you claim doesn't work. Also, tell me which ban plugin you are using.
__________________
fysiks is offline
Creator7
Junior Member
Join Date: Feb 2021
Old 02-27-2021 , 08:48   Re: Execute server commands
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
Give me some examples of what you're typing in chat that you claim doesn't work. Also, tell me which ban plugin you are using.
I am using Fresh_Bans latest version, some examples are in the CFG file which I have already included.

Examples:

!slay "name"
!slap "name" "power" (or maybe vice versa)
!kick "name"
!kick "name" "reason" (or maybe vice versa)

so it's easier if it works with out the quotes

Examples:

!slay name
!slap name power (or maybe vice versa)
!kick name
!kick name reason (or maybe vice versa)

thanks.
Creator7 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 04:46.


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