Y_Less

command test part 1

Jan 24th, 2011
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.12 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. // ======
  4. //  zcmd
  5. // ======
  6.  
  7. #include <zcmd>
  8. #undef OnPlayerCommandText
  9.  
  10. // zcmd
  11. #define XCMD(%0) CMD:%0(playerid, params[]){ return 1; }
  12. #include "cmd"
  13.  
  14. main()
  15. {
  16.     new
  17.         t0,
  18.         t1,
  19.         t2,
  20.         t3;
  21.     t0 = GetTickCount();
  22.     for (new i = 0; i != 10000; ++i)
  23.     {
  24.         dkcmd_OnPlayerCommandText(0, "/aaa");
  25.         dkcmd_OnPlayerCommandText(0, "/dzz");
  26.         dkcmd_OnPlayerCommandText(0, "/none");
  27.     }
  28.     t1 = GetTickCount();
  29.     for (new i = 0; i != 10000; ++i)
  30.     {
  31.         fcmd_OnPlayerCommandText(0, "/aaa");
  32.         fcmd_OnPlayerCommandText(0, "/dzz");
  33.         fcmd_OnPlayerCommandText(0, "/none");
  34.     }
  35.     t2 = GetTickCount();
  36.     for (new i = 0; i != 10000; ++i)
  37.     {
  38.         OnPlayerCommandText(0, "/aaa");
  39.         OnPlayerCommandText(0, "/dzz");
  40.         OnPlayerCommandText(0, "/none");
  41.     }
  42.     t3 = GetTickCount();
  43.     printf("dkcmd: %d, fcmd: %d, zcmd: %d", t1 - t0, t2 - t1, t3 - t2);
  44. }
  45.  
  46. // ======
  47. //  fcmd
  48. // ======
  49.  
  50. #define fcmd(%1,%2) \
  51.             forward fcmd_%1(%2);    \
  52.                 public fcmd_%1(%2)
  53.  
  54. #define MaxFrequence (066)
  55. #define MaxParameter (064)
  56. #define MaxFunctions (032)
  57. #define MaxLenString (128)
  58.  
  59. new
  60.     sIndex = 0,
  61.     iLenPart = 0,
  62.     iPosPart = 0,
  63.     iStrMid = 0,
  64.     iLenght = 0,
  65.     cmds[ MaxFunctions ]
  66. ;
  67.  
  68. forward fcmd_OnPlayerCommandText(playerid,cmdtext[]);
  69. public fcmd_OnPlayerCommandText(playerid,cmdtext[])
  70. {
  71.     //Here you can write cmds witout params!
  72.     return DelimiterCommand(playerid,cmdtext);
  73. }
  74. new iParams[ MaxFrequence ][ MaxParameter ],iTotalParams[MaxLenString];
  75.  
  76. stock
  77.     DelimiterCommand(playerid,sStringSource[])
  78. {
  79.     iLenght = strlen(sStringSource);
  80.     sIndex = 0;
  81.     iLenPart = 0;
  82.     iPosPart = 0;
  83.     iStrMid = 0;
  84.     for(new aIndex = 1; aIndex < MaxFrequence; ++aIndex) iParams[aIndex][0] = '\0';
  85.     iTotalParams[0] = '\0';
  86.     while(sIndex <= iLenght)
  87.     {
  88.  
  89.         if(sStringSource[sIndex] == ' ' && sStringSource[sIndex - 1] != ' ' || sIndex == iLenght)
  90.         {
  91.             iStrMid = strmid(iParams[iPosPart], sStringSource, iLenPart, sIndex, 128);
  92.             iParams[iPosPart][iStrMid] = 0,iLenPart = (sIndex + 1), ++iPosPart;
  93.             if(iPosPart == 1)
  94.                 format(iTotalParams,MaxLenString, "%s",sStringSource[sIndex]);
  95.         }
  96.         ++sIndex;
  97.     }
  98.     format(cmds, sizeof cmds,"fcmd_%s",iParams[0][1]);
  99.     return CallLocalFunction(cmds,"i",playerid);
  100. }
  101.  
  102. // fcmd
  103. #define XCMD(%0) fcmd(%0,playerid){ return 1; }
  104. #include "cmd"
  105.  
  106. // =======
  107. //  dkcmd
  108. // =======
  109.  
  110. #define dkcmd(%0) params(%0,cmdtext)
  111.  
  112. //#define MaxParameter (064)
  113. //#define MaxLenString (128)
  114.  
  115. forward dkcmd_OnPlayerCommandText(playerid,cmdtext[]);
  116. public dkcmd_OnPlayerCommandText(playerid,cmdtext[])
  117. {
  118.     // dkcmd
  119.     #define XCMD(%0) if (Command("/"#%0, cmdtext)) return 1;
  120.     #include "cmd"
  121.    
  122.     return 0;
  123. }
  124.  
  125. stock Command(cmd[],cmdtext[])
  126. {
  127.     if(!strcmp(cmd,cmdtext,true,strlen(cmd)))
  128.         return true;
  129.     return false;
  130. }
  131.  
  132. stock params(iSpace,cmdtext[])
  133. {
  134.     new iLoop = 0,iSpaces = 0,iStr[MaxParameter];
  135.     while(iSpaces != iSpace) if(cmdtext[++iLoop] == ' ') ++iSpaces;
  136.     ++iLoop,format(iStr,MaxParameter,cmdtext[iLoop]);
  137.     return iStr;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment