Y_Less

command test part 1b

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