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 , 06:27   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, Sorry if posting in wrong section!
Creator7 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-15-2021 , 07:46   Re: Execute server commands
Reply With Quote #2

Quote:
I'm not a AMXX Developer, so I want someone to do it from for me
Quote:
AMX Mod X > Scripting > Scripting Help
??

The "do it for me section" is this one - https://forums.alliedmods.net/forumdisplay.php?f=12

Quote:
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:
That's not possible. How do you expect the plugin to know what is name and what is reason when they have spaces inside them?... Mind reading technology hasn't yet been developed, especially in AMXX.
__________________

Last edited by OciXCrom; 02-15-2021 at 07:48.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Creator7
Junior Member
Join Date: Feb 2021
Old 02-15-2021 , 08:16   Re: Execute server commands
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
??

The "do it for me section" is this one - https://forums.alliedmods.net/forumdisplay.php?f=12



That's not possible. How do you expect the plugin to know what is name and what is reason when they have spaces inside them?... Mind reading technology hasn't yet been developed, especially in AMXX.
Thanks for giving the correct section.

About "This is not possible" this is possible as I have already seen it in a few communities, you can write some letters of his name and it should work.

Player with name 'Pro Player', he can be banned if you type amx_ban 5 pro, and you can do the same with chat, as I have already seen.

Posted in correct section.

Last edited by Creator7; 02-15-2021 at 08:20.
Creator7 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-15-2021 , 15:04   Re: Execute server commands
Reply With Quote #4

That's default behavior. Nobody is forcing you to use quotes if you're going to write just a part of the name. That's how all AMXX commands work. Quotes must be used only when there are spaces in the name/string you're writing.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-15-2021 , 22:30   Re: Execute server commands
Reply With Quote #5

Quote:
Originally Posted by OciXCrom View Post
That's default behavior. Nobody is forcing you to use quotes if you're going to write just a part of the name. That's how all AMXX commands work. Quotes must be used only when there are spaces in the name/string you're writing.
That's not true when the plugin is manually parsing the string using the quote character to find where the arguments are located.
__________________
fysiks is offline
Creator7
Junior Member
Join Date: Feb 2021
Old 02-16-2021 , 08:15   Re: Execute server commands
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
That's not true when the plugin is manually parsing the string using the quote character to find where the arguments are located.
Thanks, it works!
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 10:39.


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