29.08.2010, 09:45
(
Last edited by MrDeath537; 29/08/2010 at 11:01 AM.
Reason: Editing an error
)
[Include] mcmd - Command processor!
> by MrDeath!
Description:
Then of a lot of tries, and trying to understand dcmd, I made my command processor, it's like dcmd. mcmd is easy to use!
Functions:
Use:
Why use it?
It's easy and faster to script.
Examples:
Download:
Download!
> by MrDeath!
Description:
Then of a lot of tries, and trying to understand dcmd, I made my command processor, it's like dcmd. mcmd is easy to use!
Functions:
Code:
♦ mcmd(function, source, lenght, player) function - Function name source - The source command (cmdtext...) lenght - Lenght of the command (Example: kick = 4) player - The player who used the command. ♦ mcmd2(function, source, player) function - Function name source - The source command (cmdtext...) player - The player who used the command. ♦ mcmd_init(source) source - Prepares mcmd to use commands.
Use:
Code:
♦ mcmd It's used for commands with parameters (Example: /me <action>) ♦ mcmd2 It's used for commands WITHOUT parameters (Example: /help). ♦ mcmd_init It should be the first line in OnPlayerCommandText, it deletes the "/" of cmdtext, without it, mcmd and mcmd2 doesn't works. NOTE: mcmd_init deletes the "/", if you use strcmp (like with strtok, but use mcmd2 it was made for it) it needs to be adapted. ♦ How to define commands Then of define them in OnPlayerCommandText we should make the function: Function WITH parameters: mcmd_command(playerid, params[]) Function WITHOUT parameters: mcmd_command(playerid) (You should change "command" for the command name, lol)
Why use it?
It's easy and faster to script.
Examples:
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
// Init the mcmd
mcmd_init(cmdtext);
// Commands WITH parameters
mcmd(kick, cmdtext, 4, playerid);
mcmd(me, cmdtext, 2, playerid);
// Commands WITHOUT parameters
mcmd2(help, cmdtext, playerid);
return 0;
}
mcmd_kick(playerid, params[])
{
new kickid = strval(params);
if (!IsPlayerConnected(kickid))
{
SendClientMessage(playerid, 0xFFFFFFFF, "The player isn't connected!");
return 0;
}
new String[20];
format(String, sizeof(String), "%i was kicked", kickid);
SendClientMessage(playerid, 0xFFFFFFFF, String);
Kick(kickid);
return 1;
}
mcmd_me(playerid, params[])
{
new String[128];
format(String, sizeof(String), "%i %s", playerid, params);
SendClientMessageToAll(0xFFFFFFFF, String);
return 1;
}
mcmd_help(playerid)
{
SendClientMessage(playerid, 0xFFFFFFFF, "You used /help, congratulations!");
return 1;
}
Download:
Download!