[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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)