cMd v0.1a (command processor) -
Meta - 27.11.2011
~~~ cMd v0.1a ~~~
Hello guys!
Today, I release some very small command processor, like almost everyone else did
It's very fast and REALLY SMALL (some test returned a time of 3ms! Please test yourself xD)
Usage (also included to the include
)
- Use "do_cMd;" in "OnPlayerCommandText" to call the command like that:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
// code ...
do_cMd;
// code ...
}
- Define Commands like that (
PLEASE USE LOWERCASE LETTERS):
pawn Код:
cMd:command_name;
{
// code ...
}
... as a standalone function like public or stock.
- playerid and params[] are available in every command, params[] includes the command's parameters you can split with sscanf
(Optional: you can use the variable "cMd" after "do_cMd;" to check if a command was called. It should return 1 then.)
Changelog:
[v0.1a]:
- Made commands non-casesensitive. Please define commands with lowercase names
[v0.1]:
Here you go:
Download.
Pastebin
Greetz
PS: Critics and comments are welcome
Re: cMd (command processor) -
Kar - 27.11.2011
pawn Код:
format(cmdtext, 128, "cMd_%s"
looks good but here ^, your using publics right, the max length of a public is like what.. 39? or something.. so no need for 128
AW: Re: cMd (command processor) -
Meta - 27.11.2011
Quote:
Originally Posted by Kar
pawn Код:
format(cmdtext, 128, "cMd_%s"
looks good but here ^, your using publics right, the max length of a public is like what.. 39? or something.. so no need for 128
|
it's 32, yes
I'll change it
EDIT: Please someone test the speed ... I really got 2-4 milliseconds (GetTickCount)
Respuesta: cMd (command processor) -
[Nikk] - 27.11.2011
Very nice.
Re: cMd (command processor) -
wups - 27.11.2011
change
if(!strlen(cMdtMp[1]))
to
if(isnull(cMdtMp[1]))
or even
if(sscanf(cmdtext[1], "sS(' ')", cMdtMp[0], cMdtMp[1]))
THE CORRECT CODE WOULD BE:
pawn Код:
#define do_cMd; \
new cMdtMp[2][128], cMd; \
sscanf(cmdtext[1], "sS(' ')", cMdtMp[0], cMdtMp[1]) format(cmdtext, 32, "cMd_%s", cMdtMp[0]);\
if(funcidx(cmdtext) != -1) { if(!cMd) { cMd = 1; CallLocalFunction(cmdtext, "ds", playerid, cMdtMp[1]); } }
Not sure how default string is defined in sscanf.
However, if you don't use optional string in sscanf, then cMdtMp[0] will also be empty if there were no params.
Cheers.
Edit: You should make it NON case sensitive.
Re: cMd (command processor) -
Danny - 27.11.2011
It looks very good, but do you have some proof to support your 3ms-story? This sounds amazing!
Re: cMd (command processor) - Max_Coldheart - 27.11.2011
I have been waiting for a command processor from you Meta! Good job
(if it really is 3 ms, I'm gonna use it
)
Re: cMd (command processor) -
Nenad - 27.11.2011
show us your benchmark results ... why would anyone use it if you don't show us your test results ... i recommend you to use this benchmarking
https://sampforum.blast.hk/showthread.php?tid=218491
Re: cMd (command processor) -
TheArcher - 27.11.2011
Quote:
Originally Posted by Nenad
|
That was i wanted to say
Re: cMd (command processor) - [S]trong - 27.11.2011
I see where you get the speed, but where is the case sensitive?