[Include] acmd - Configurable first character [e.g ! or @] with params support.
#1

Yeah, I know there exists something like this already.
But I decided to try my own.

Default first character is '!'.
So, if you haven't configured it, your created commands is written like :
!help,
!me,
!kill


This is the first include I have ever made. Took me ~1 hour to make it work.

The format to create a command :
pawn Код:
ACMD:cmdname(playerid, params[])
An example code :
pawn Код:
#include < a_samp >
#include < acmd >
#include < sscanf2 >

ACMD:me1( playerid, params[ ] )
{
    if ( params[ 0 ] == '\1' )
        return SendClientMessage( playerid, 0xFF0000AA, "Syntax - /me1 <action>" );

    new
        szStr[ 128 ], name[ 24 ];
    GetPlayerName( playerid, name, 24 );

    format( szStr, sizeof szStr, "* %s %s", name, params );
    SendClientMessageToAll( -1, szStr );
    return 1;
}

ACMD:me( playerid, params[ ] )
{
    new
        j[ 100 ];
    if ( sscanf( params, "s[100]", j ) )
        return SendClientMessage( playerid, 0xFF0000AA, "Syntax - /me <action>" );

    new
        szStr[ 128 ], name[ 24 ];
    GetPlayerName( playerid, name, 24 );

    format( szStr, sizeof szStr, "* %s %s", name, j );
    SendClientMessageToAll( -1, szStr );
    return 1;
}

ACMD:money( playerid, params[ ] )
{
    new
        id,
        amount;

    if ( sscanf( params, "ri", id, amount ) )
        return SendClientMessage( playerid, 0xFF0000AA, "Syntax - /money <id> <amount> (gives the target money)" );

    if ( id == INVALID_PLAYER_ID )
        return SendClientMessage( playerid, -1, "player not connected" );

    GivePlayerMoney( id, amount );
    SendClientMessage( id, -1, "money received." );
    SendClientMessage( playerid, -1, "money sent." );
    return 1;
}
Tested at bare gamemode.

Configuring the script <edit it at the include>:
[DEFAULT]:
pawn Код:
#define CMD_CHAR        '!'
#define CMD_ERROR       "SERVER: Unknown command."
[EDITED]:
pawn Код:
#define CMD_CHAR        '@'
#define CMD_ERROR       "Wrong command entered! Please use /cmds to see the list of server commands."
Download link :
acmd.inc
Save the file as "acmd.inc".

Future updates
1) Will add
pawn Код:
OnPlayerACommandPerformed(playerid, cmdtext[], success)
Credits :
****** (for reporting me #define CMD_CHAR '/' will not work)

Bugs :
None yet. !this_is_a_long_bit_of_text_1923194_1421241 thing has been fixed. (Commands longer than 29 characters will be an invalid command.

Have fun with it!
Reply
#2

good job
Reply
#3

What it's #define CMD_CHAR '@' doing?

And this include better then zcmd?
Reply
#4

Good job, another 'unique' command processor.
Reply
#5

I don't know, but I think zcmd is faster. (I've just decided to share mine)

#define CMD_CHAR '@'
will define it's first character for command, e.g
@help,
@me

If you do #define CMD_CHAR '#'
commands will be typed as :
#help,
#me
Reply
#6

Anyway Nice share
Reply
#7

good job.
I was attempting something like this.
But it was turn out to be invented (created) already.
Reply
#8

Nice.
This can be useful if you want to hide some commands from others or to make multiple commands with the same name doing different thigs.
Reply
#9

Quote:
Originally Posted by ******
Посмотреть сообщение
Two bugs. This doesn't work:

pawn Код:
#define CMD_CHAR '/'
This crashes the server:

Код:
!this_is_a_very_long_bit_of_text_0123456789_0123456789_0123456789
About CMD_CHAR thingy, can I do it like this, right?
pawn Код:
#if CMD_CHAR == '/'
    #error CMD_CHAR can't be a slash!
#endif
About this :
Код:
!this_is_a_very_long_bit_of_text_0123456789_0123456789_0123456789
I have no idea, I tested it with bare gamemode. The result I get was not server crash, instead of the command was not processed (!this_is_a_very_long_bit_of_text_0123456789_01234 56789_0123456789 was sent in the chat).

I haven't find any idea why that doesn't work. (!this_is_a_very_long_bit_of_text_0123456789_01234 56789_0123456789)
Reply
#10

crashdetect gave me this :
Код:
[20:01:21] [debug] Run time error 4: "Array index out of bounds"
[20:01:21] [debug]  Accessing element at index 60 past array upper bound 59
[20:01:21] [debug] AMX backtrace:
[20:01:21] [debug] #0 00000550 in public OnPlayerText () from bare.amx
Then, I changed szFunc to 128 :
pawn Код:
new
    szFunc[ 128 ];
After that, now it gave me this :
Код:
[20:03:08] [debug] Run time error 10: "Native function failed"
[20:03:08] [debug]  funcidx
[20:03:08] [debug] AMX backtrace:
[20:03:08] [debug] #0 00000638 in public OnPlayerText () from bare.amx
Any solution for this?
Reply
#11

All i remember.
The callback can only handle 32 lengths callback name.
So you should add a function that will block the scripters from creating commands
with more than 32 lengths. Just like ZCMD did.
Reply
#12

Include has been updated!

Updates :
[1]. Rewritten the script and removed useless lines.
[2]. !this_is_a_very_long_bit_of_text_01234125_123121 or commands longer than 29 characters will say SERVER: Unknown command (or the error message you set).
NOTE: If you create a command more than 29 characters, it will not work!

Also, thank you for the great comments
Reply
#13

The fact that you can configure the first character of the commands is not that important. No one will use acmd for that. No one really needs that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)