mcmd - Command processor! -
MrDeath537 - 29.08.2010
[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:
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!
Re: mcmd - Command processor! -
Agent Smith - 29.08.2010
Wow this is really good, I like it that you don't always have to have the params part. I'll probably use this
Re: mcmd - Command processor! -
MrDeath537 - 29.08.2010
Quote:
Originally Posted by Agent Smith
Wow this is really good, I like it that you don't always have to have the params part. I'll probably use this
|
Thanks you
Re: mcmd - Command processor! -
MrDeath537 - 29.08.2010
Quote:
Originally Posted by [HLF]Southclaw
Looks good, simple and effective
Want some natives to make the params appear in pawno?
pawn Code:
/* native mcmd(command, source[], lenght, playerid); native mcmd2(command, source[], playerid); native mcmd_init(source[]); */
Good Script
|
Thanks you
!. I didn't know the natives appear when they're a comment.
Re: mcmd - Command processor! -
DiddyBop - 29.08.2010
copy of dcmd? renamed to mcmd? is this any faster then dcmd at least..?
Re: mcmd - Command processor! -
MrDeath537 - 29.08.2010
Quote:
Originally Posted by DiddyBop
copy of dcmd? renamed to mcmd? is this any faster then dcmd at least..?
|
Shut up, you should see the codes:
pawn Code:
#define mcmd(%0,%1,%2,%3) \
if (!strcmp(#%0, %1, true, (%2))) mcmd_%0((%3), %1[(%2) + 1])
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
Edit:
mcmd is like a dcmd. Isn't a copy in scripting, I made it.
dcmd is much longer than mcmd. I don't know if dcmd is best, but I like what I made.
Edit 2:
mcmd_init removes the "/" and then mcmd checks if the command is = to the function, then it calls the function. I don't know what does dcmd, but I think mcmd is too much simple than dcmd.
Re: mcmd - Command processor! -
Grim_ - 29.08.2010
How does this compare to zcmd?
Re: mcmd - Command processor! -
MrDeath537 - 29.08.2010
Quote:
Originally Posted by Grim_
How does this compare to zcmd?
|
Lol, I'm sorry but I didn't know about the zcmd.
I think it's more faster than dcmd and strtok, but not more faster to zcmd because I don't know how is it.
Edit:
I watch zcmd, I think mcmd is more faster too. Because mcmd's only 3 macros, nice and simple.
Re: mcmd - Command processor! -
Calgon - 29.08.2010
Basically it looks just like dcmd, and is probably slower than dcmd, and zcmd is still faster.
Great job!
Re: mcmd - Command processor! -
MrDeath537 - 29.08.2010
Quote:
Originally Posted by Calgon
Basically it looks just like dcmd, and is probably slower than dcmd, and zcmd is still faster.
Great job!
|
Thanks you
.
I tested a command with strtok, dcmd and mcmd. All give me 1 ms -.-
Re: mcmd - Command processor! -
Y_Less - 29.08.2010
No, zcmd is VASTLY faster than strcmp, which your system is based on, and it's simpler as you don't need anything in OnPlayerCommandText at all. The number of macros involved doesn't make any difference. In fact I really don't see the point in this, if you change your mind about parameters you need to go and find the original definition and change it.
I really suggest you run some speed tests on this - I think you will be VERY disappointed with the results, especially using format just to remove the first character, which every other command processor handles very nicely.
Re: mcmd - Command processor! -
MrDeath537 - 29.08.2010
Quote:
Originally Posted by Y_Less
No, zcmd is VASTLY faster than strcmp, which your system is based on, and it's simpler as you don't need anything in OnPlayerCommandText at all. The number of macros involved doesn't make any difference. In fact I really don't see the point in this, if you change your mind about parameters you need to go and find the original definition and change it.
I really suggest you run some speed tests on this - I think you will be VERY disappointed with the results, especially using format just to remove the first character, which every other command processor handles very nicely.
|
Oh, I didn't know. But I tested and all give me 1 ms. Can you give me YOUR results?
Thanks
Re: mcmd - Command processor! -
playbox12 - 29.08.2010
Quote:
Originally Posted by MrDeath
Oh, I didn't know. But I tested and all give me 1 ms. Can you give me YOUR results?
Thanks
|
Loop it x1000 maybe, it wil give you a more detailed result dunno.
Respuesta: mcmd - Command processor! -
Jesus^ - 29.08.2010
Nice! Great job man!
Re: mcmd - Command processor! -
MrDeath537 - 29.08.2010
Current results with a x2000 loop
:
dcmd: 48
mcmd: 11
Re: mcmd - Command processor! -
ziomal432 - 29.08.2010
Then more commands, then it's slower.
Re: mcmd - Command processor! -
MrDeath537 - 29.08.2010
zcmd pwned dcmd and mcmd:
dcmd: 64
mcmd: 39
zcmd: 3
Re: mcmd - Command processor! -
Y_Less - 29.08.2010
http://forum.sa-mp.com/showthread.ph...452#post815452
Re: mcmd - Command processor! -
MrDeath537 - 29.08.2010
Thanks you for speed test Y_Less. But do you used mcmd_init in the command? mcmd should be in OnPlayerCommandText.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
mcmd_init(cmdtext);
mcmd(test, cmdtext, 4, playerid;
}
mcmd_test(playerid, command[])
{
// Stuff
}
Re: mcmd - Command processor! -
Y_Less - 29.08.2010
I didn't use OnPlayerCommandText as there were multiple command processors.