Advertisement
drakeee

test

Jan 27th, 2012
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.79 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. // ======
  4. //  zcmd
  5. // ======
  6.  
  7. #define OnPlayerCommandText czcmd_OnPlayerCommandText
  8. forward czcmd_OnPlayerCommandText(playerid, cmdtext[]);
  9. #define _ALS_OnPlayerCommandText
  10. #include <zcmd>
  11.  
  12. // Set by the compiler:
  13. //
  14. //  FOR /L %%i IN (0, 1, 2703) DO pawncc.exe "..\gamemodes\cmdtest.pwn" -;+ -\ -(+ CMD_NUM=%%i -o..\gamemodes\cmdtest_%%i
  15. //
  16.  
  17. // zcmd
  18. CMD:first(playerid, params[]){ return 1; }
  19. #define XCMD(%0) CMD:%0(playerid, params[]){ return 1; }
  20. #include "cmd"
  21. #undef XCMD
  22. CMD:last(playerid, params[]){ return 1; }
  23.  
  24. #undef CMD
  25. #undef COMMAND
  26.  
  27. // ===========
  28. //  y_command
  29. // ===========
  30.  
  31. #undef OnPlayerCommandText
  32. #define OnPlayerCommandText cycmd_OnPlayerCommandText
  33. forward cycmd_OnPlayerCommandText(playerid, cmdtext[]);
  34. // So we can do it with no players connected.
  35. #define YSI_NO_MASTER
  36. #define _YSI_SPECIAL_DEBUG
  37. // Disable y_version
  38. #define _inc_y_version
  39. #include <YSI\y_commands>
  40.  
  41. // ycmd
  42. YCMD:first(playerid, params[], help){ return 1; }
  43. #define XCMD(%0) YCMD:%0(playerid, params[], help){ return 1; }
  44. #include "cmd"
  45. #undef XCMD
  46. YCMD:last(playerid, params[], help){ return 1; }
  47.  
  48. #undef OnPlayerCommandText
  49. #define OnPlayerCommandText drcmd_OnPlayerCommandText
  50. forward drcmd_OnPlayerCommandText(playerid, cmdtext[]);
  51. // drcmd
  52. DRCMD:first(playerid, params[], help){ return 1; }
  53. #define XCMD(%0) DRCMD:%0(playerid, params[]){ return 1; }
  54. #include "cmd"
  55. #undef XCMD
  56. DRCMD:last(playerid, params[], help){ return 1; }
  57.  
  58. main()
  59. {
  60.     new
  61.         t0,
  62.         t1,
  63.         t2,
  64.         t3,
  65.         t4,
  66.         t5;
  67.     t0 = GetTickCount();
  68.     for (new i = 0; i != 10000; ++i)
  69.     {
  70.         dkcmd_OnPlayerCommandText(0, "/first");
  71.         dkcmd_OnPlayerCommandText(0, "/last");
  72.         dkcmd_OnPlayerCommandText(0, "/none");
  73.     }
  74.     t1 = GetTickCount();
  75.     for (new i = 0; i != 10000; ++i)
  76.     {
  77.         fcmd_OnPlayerCommandText(0, "/first");
  78.         fcmd_OnPlayerCommandText(0, "/last");
  79.         fcmd_OnPlayerCommandText(0, "/none");
  80.     }
  81.     t2 = GetTickCount();
  82.     for (new i = 0; i != 10000; ++i)
  83.     {
  84.         czcmd_OnPlayerCommandText(0, "/first");
  85.         czcmd_OnPlayerCommandText(0, "/last");
  86.         czcmd_OnPlayerCommandText(0, "/none");
  87.     }
  88.     t3 = GetTickCount();
  89.     for (new i = 0; i != 10000; ++i)
  90.     {
  91.         cycmd_OnPlayerCommandText(0, "/first");
  92.         cycmd_OnPlayerCommandText(0, "/last");
  93.         cycmd_OnPlayerCommandText(0, "/none");
  94.     }
  95.     t4 = GetTickCount();
  96.     for (new i = 0; i != 10000; ++i)
  97.     {
  98.         drcmd_OnPlayerCommandText(0, "/first");
  99.         drcmd_OnPlayerCommandText(0, "/last");
  100.         drcmd_OnPlayerCommandText(0, "/none");
  101.     }
  102.     printf("%d  %d  %d  %d  %d", CMD_NUM, t1 - t0, t2 - t1, t3 - t2, t4 - t3, t5 - t4);
  103.     new
  104.         str[32];
  105.     format(str, sizeof (str), "changemode cmdtest_%d", CMD_NUM + 1);
  106.     SendRconCommand(str);
  107. }
  108.  
  109. // ======
  110. // drcmd
  111. // ======
  112.  
  113. #define DRCMD:%1(%2,%3) \
  114.         forward drcmd_%1(%2,%3); \
  115.         public drcmd_%1(%2,%3)
  116.  
  117. public drcmd_OnPlayerCommandText(playerid, cmdtext[])
  118. {
  119.     new
  120.         function[32],
  121.         szokozmeddig = -1;
  122.     while(++szokozmeddig < strlen(cmdtext)) if((cmdtext[szokozmeddig] == ' ')) break;
  123.     strmid(function, cmdtext, 1, szokozmeddig);
  124.     format(function, sizeof(function), "drcmd_%s", function);
  125.     while(cmdtext[szokozmeddig] == ' ') szokozmeddig++;
  126.     if(funcidx(function) != -1)
  127.     {
  128.         if(szokozmeddig == strlen(cmdtext))
  129.         {
  130.             return CallLocalFunction(function, "is", playerid, "\1");
  131.         }
  132.         return CallLocalFunction(function, "is", playerid, cmdtext[szokozmeddig]);
  133.     }
  134.     return 0;
  135. }
  136.  
  137. // ======
  138. //  fcmd
  139. // ======
  140.  
  141. #define fcmd(%1,%2) \
  142.             forward fcmd_%1(%2);    \
  143.                 public fcmd_%1(%2)
  144.  
  145. #define MaxFrequence (066)
  146. #define MaxParameter (064)
  147. #define MaxFunctions (032)
  148. #define MaxLenString (128)
  149.  
  150. new
  151.     sIndex = 0,
  152.     iLenPart = 0,
  153.     iPosPart = 0,
  154.     iStrMid = 0,
  155.     iLenght = 0,
  156.     cmds[ MaxFunctions ]
  157. ;
  158.  
  159. forward fcmd_OnPlayerCommandText(playerid,cmdtext[]);
  160. public fcmd_OnPlayerCommandText(playerid,cmdtext[])
  161. {
  162.     //Here you can write cmds witout params!
  163.     return DelimiterCommand(playerid,cmdtext);
  164. }
  165. new iParams[ MaxFrequence ][ MaxParameter ],iTotalParams[MaxLenString];
  166.  
  167. stock
  168.     DelimiterCommand(playerid,sStringSource[])
  169. {
  170.     iLenght = strlen(sStringSource);
  171.     sIndex = 0;
  172.     iLenPart = 0;
  173.     iPosPart = 0;
  174.     iStrMid = 0;
  175.     for(new aIndex = 1; aIndex < MaxFrequence; ++aIndex) iParams[aIndex][0] = '\0';
  176.     iTotalParams[0] = '\0';
  177.     while(sIndex <= iLenght)
  178.     {
  179.  
  180.         if(sStringSource[sIndex] == ' ' && sStringSource[sIndex - 1] != ' ' || sIndex == iLenght)
  181.         {
  182.             iStrMid = strmid(iParams[iPosPart], sStringSource, iLenPart, sIndex, 128);
  183.             iParams[iPosPart][iStrMid] = 0,iLenPart = (sIndex + 1), ++iPosPart;
  184.             if(iPosPart == 1)
  185.                 format(iTotalParams,MaxLenString, "%s",sStringSource[sIndex]);
  186.         }
  187.         ++sIndex;
  188.     }
  189.     format(cmds, sizeof cmds,"fcmd_%s",iParams[0][1]);
  190.     return CallLocalFunction(cmds,"i",playerid);
  191. }
  192.  
  193. // fcmd
  194. fcmd(first,playerid){ return 1; }
  195. #define XCMD(%0) fcmd(%0,playerid){ return 1; }
  196. #include "cmd"
  197. #undef XCMD
  198. fcmd(last,playerid){ return 1; }
  199.  
  200. // =======
  201. //  dkcmd
  202. // =======
  203.  
  204. #define dkcmd(%0) params(%0,cmdtext)
  205.  
  206. //#define MaxParameter (064)
  207. //#define MaxLenString (128)
  208.  
  209. forward dkcmd_OnPlayerCommandText(playerid,cmdtext[]);
  210. public dkcmd_OnPlayerCommandText(playerid,cmdtext[])
  211. {
  212.     // dkcmd
  213.     if (Command("/first", cmdtext)) return 1;
  214.     #define XCMD(%0) if (Command("/"#%0, cmdtext)) return 1;
  215.     #include "cmd"
  216.     #undef XCMD
  217.     if (Command("/last", cmdtext)) return 1;
  218.  
  219.     return 0;
  220. }
  221.  
  222. stock Command(cmd[],cmdtext[])
  223. {
  224.     if(!strcmp(cmd,cmdtext,true,strlen(cmd)))
  225.         return true;
  226.     return false;
  227. }
  228.  
  229. stock params(iSpace,cmdtext[])
  230. {
  231.     new iLoop = 0,iSpaces = 0,iStr[MaxParameter];
  232.     while(iSpaces != iSpace) if(cmdtext[++iLoop] == ' ') ++iSpaces;
  233.     ++iLoop,format(iStr,MaxParameter,cmdtext[iLoop]);
  234.     return iStr;
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement