|
|
#1 |
|
Gangsta
![]() ![]() ![]() ![]() Join Date: Apr 2006
Posts: 815
Reputation: 43
|
Hello!
jtp10181 showed in a topic that there are still person which use strtok to get a nice looking command processor. But it is slow and it won't work like it should if you have more commands behind each other. Thatswhy I decided to show a way (dcmd) which also looks gentle but is much faster then strtok only and in my opinion better organized. How To: [iurl=http://forum.sa-mp.com/index.php?topic=70925.msg461044#msg461044]Add Multiple Parameters[/iurl] This way, is often used (I am not using params now, because that would decrease strtok-method again) (Remember it hasn't even protection if somebody uses commands like /meso or something like this!) pawn Code:
Our implementation will look like this (it has protection like /meso is not allowed, but /me hello is.): pawn Code:
I tested (calling 1000000 times) the implementations above, without print-stuff (this would make lag, which isn't called by the function itself!) and had this results: 63 Seconds for first implementation. 18 Seconds for my implementation. Here is my testcase: pawn Code:
If I add two more /commands (for example /give and /me in both implementation) the results where: 19 seconds for mine, and already 70 seconds for the first implementation. You can see that it is much faster without extra vars and stuff. Why is it so much faster, even in this small example? The magic thing is using procedures and good organized if-statement, instead of lots of strtok's. Our macro: pawn Code:
pawn Code:
#1 (strcmp(cmdtext, "/me", true, 2+1) == 0) #2.1 ((cmdtext[2+1]==0)&&(dcmd_me(playerid,"")) #2.2 ((cmdtext[2+1]==32)&&(dcmd_me(playerid,cmdtext[2+2])) If #1 is true, the beginning is /me, but this doesn't filter stuff like /meso yet. Now #2.1 or #2.2 must be true. The #2.1 is true, if "/me" is the whole string, and dcmd_me returns true. The #2.2 returns true, if "/me " has a space after /me, so its for example "/me hello." and transfers the array beginning from the "hello" (therefor we have cmdtext[2+2]). The cool thing is, that dcmd_me won't be executed if already #1 isn't true, so it doesn't take extra space/speed. Regards, Jan (DracoBlue) [Hint] This topic got lost, when updating/converting the forums, so you may find an archive at webarchive.org |
|
|
|
|
#2 |
|
Gangsta
![]() ![]() ![]() ![]() Join Date: Apr 2006
Posts: 815
Reputation: 43
|
Example with multiple parameters:
pawn Code:
You can additionall also use sscanf to properly parse the params. - Draco PS: Sorry for doublepost, but the topic was lost, so this response, so the possibility to link it. |
|
|
|
|
#3 |
|
Huge Clucker
![]() ![]() ![]() Join Date: Nov 2008
Posts: 415
Reputation: 0
|
Sorry for the bump, but since this question is regarding DCMD, I didn't want to create a new topic.
Well I was wondering if DCMD would be any different than strcmp when doing a command that doesn't involve a variable, like /help? |
|
|
|
|
#4 | |
|
Gangsta
![]() ![]() ![]() ![]() Join Date: Apr 2006
Posts: 815
Reputation: 43
|
Quote:
.- Draco |
|
|
|
|
|
#5 |
|
Gangsta
![]() ![]() ![]() ![]() Join Date: Jul 2007
Posts: 739
Reputation: 1
|
Draco's Fan forever
![]() Thanks for helping me find this topic
|
|
|
|
|
#6 |
|
Huge Clucker
![]() ![]() ![]() Join Date: May 2009
Posts: 236
Reputation: 0
|
thanks
|
|
|
|
|
#7 |
|
Guest
Posts: n/a
|
OMG YOURE AWESUME DRACO
thanks for letting me use the dini , dcmd , dutils and dudb for a release ( I WONT FORGET TO MENTION SPECIAL THANKS TO DRACOBLUE ) thank you for shareing this freely !
|
|
|
#8 |
|
Guest
Posts: n/a
|
It helped for this :
i had secret cmds that anyone can use for fun i used strcmp like this : [pawno] if (strcmp("/secretadmin.teleport",cmdtext,true, 10) == 0) // or however it goes XD { // my code here } if (strcmp("/secretadmin.weapons",cmdtext,true, 10) == 0) // or however it goes XD { // my code here } [/pawno] however that was when i started and i begon to realize that when i typed : /secretadmin it did one of the commands when i did : /secretadmin.weapons i think it did both
|
|
|
#9 |
|
Beta Tester
![]() ![]() ![]() ![]() ![]() Join Date: Jun 2008
Location: 629
Posts: 13,338
Reputation: 1911
|
|
|
|
|
|
#10 |
|
Banned
![]() Join Date: Oct 2010
Location: Behind you
Posts: 278
Reputation: 10
|
nice job draco
|
|
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Include] [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) | Zeex | Includes | 500 | 15/04/2013 09:05 AM |
| [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) | DracoBlue | Help Archive | 748 | 17/09/2010 10:14 AM |
| [HR/SR:FS] Fast rcon command processor: RCMD (modified DCMD) | Correlli | Archive | 0 | 16/11/2009 09:20 PM |
| fast command processor | [mad]MLK | Help Archive | 1 | 22/08/2009 01:32 AM |
| Fast rcon command processor: RCMD (modified DCMD) | Correlli | Filterscripts | 7 | 01/08/2009 12:02 PM |