Y_Less

command test part 1c

Jan 25th, 2011
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.58 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. main()
  49. {
  50.     new
  51.         t0,
  52.         t1,
  53.         t2,
  54.         t3,
  55.         t4;
  56.     t0 = GetTickCount();
  57.     for (new i = 0; i != 10000; ++i)
  58.     {
  59.         dkcmd_OnPlayerCommandText(0, "/first");
  60.         dkcmd_OnPlayerCommandText(0, "/last");
  61.         dkcmd_OnPlayerCommandText(0, "/none");
  62.     }
  63.     t1 = GetTickCount();
  64.     for (new i = 0; i != 10000; ++i)
  65.     {
  66.         fcmd_OnPlayerCommandText(0, "/first");
  67.         fcmd_OnPlayerCommandText(0, "/last");
  68.         fcmd_OnPlayerCommandText(0, "/none");
  69.     }
  70.     t2 = GetTickCount();
  71.     for (new i = 0; i != 10000; ++i)
  72.     {
  73.         czcmd_OnPlayerCommandText(0, "/first");
  74.         czcmd_OnPlayerCommandText(0, "/last");
  75.         czcmd_OnPlayerCommandText(0, "/none");
  76.     }
  77.     t3 = GetTickCount();
  78.     for (new i = 0; i != 10000; ++i)
  79.     {
  80.         cycmd_OnPlayerCommandText(0, "/first");
  81.         cycmd_OnPlayerCommandText(0, "/last");
  82.         cycmd_OnPlayerCommandText(0, "/none");
  83.     }
  84.     t4 = GetTickCount();
  85.     printf("%d  %d  %d  %d  %d", CMD_NUM, t1 - t0, t2 - t1, t3 - t2, t4 - t3);
  86.     new
  87.         str[32];
  88.     format(str, sizeof (str), "changemode cmdtest_%d", CMD_NUM + 1);
  89.     SendRconCommand(str);
  90. }
  91.  
  92. // ======
  93. //  fcmd
  94. // ======
  95.  
  96. #define fcmd(%1,%2) \
  97.             forward fcmd_%1(%2);    \
  98.                 public fcmd_%1(%2)
  99.  
  100. #define MaxFrequence (066)
  101. #define MaxParameter (064)
  102. #define MaxFunctions (032)
  103. #define MaxLenString (128)
  104.  
  105. new
  106.     sIndex = 0,
  107.     iLenPart = 0,
  108.     iPosPart = 0,
  109.     iStrMid = 0,
  110.     iLenght = 0,
  111.     cmds[ MaxFunctions ]
  112. ;
  113.  
  114. forward fcmd_OnPlayerCommandText(playerid,cmdtext[]);
  115. public fcmd_OnPlayerCommandText(playerid,cmdtext[])
  116. {
  117.     //Here you can write cmds witout params!
  118.     return DelimiterCommand(playerid,cmdtext);
  119. }
  120. new iParams[ MaxFrequence ][ MaxParameter ],iTotalParams[MaxLenString];
  121.  
  122. stock
  123.     DelimiterCommand(playerid,sStringSource[])
  124. {
  125.     iLenght = strlen(sStringSource);
  126.     sIndex = 0;
  127.     iLenPart = 0;
  128.     iPosPart = 0;
  129.     iStrMid = 0;
  130.     for(new aIndex = 1; aIndex < MaxFrequence; ++aIndex) iParams[aIndex][0] = '\0';
  131.     iTotalParams[0] = '\0';
  132.     while(sIndex <= iLenght)
  133.     {
  134.  
  135.         if(sStringSource[sIndex] == ' ' && sStringSource[sIndex - 1] != ' ' || sIndex == iLenght)
  136.         {
  137.             iStrMid = strmid(iParams[iPosPart], sStringSource, iLenPart, sIndex, 128);
  138.             iParams[iPosPart][iStrMid] = 0,iLenPart = (sIndex + 1), ++iPosPart;
  139.             if(iPosPart == 1)
  140.                 format(iTotalParams,MaxLenString, "%s",sStringSource[sIndex]);
  141.         }
  142.         ++sIndex;
  143.     }
  144.     format(cmds, sizeof cmds,"fcmd_%s",iParams[0][1]);
  145.     return CallLocalFunction(cmds,"i",playerid);
  146. }
  147.  
  148. // fcmd
  149. fcmd(first,playerid){ return 1; }
  150. #define XCMD(%0) fcmd(%0,playerid){ return 1; }
  151. #include "cmd"
  152. #undef XCMD
  153. fcmd(last,playerid){ return 1; }
  154.  
  155. // =======
  156. //  dkcmd
  157. // =======
  158.  
  159. #define dkcmd(%0) params(%0,cmdtext)
  160.  
  161. //#define MaxParameter (064)
  162. //#define MaxLenString (128)
  163.  
  164. forward dkcmd_OnPlayerCommandText(playerid,cmdtext[]);
  165. public dkcmd_OnPlayerCommandText(playerid,cmdtext[])
  166. {
  167.     // dkcmd
  168.     if (Command("/first", cmdtext)) return 1;
  169.     #define XCMD(%0) if (Command("/"#%0, cmdtext)) return 1;
  170.     #include "cmd"
  171.     #undef XCMD
  172.     if (Command("/last", cmdtext)) return 1;
  173.  
  174.     return 0;
  175. }
  176.  
  177. stock Command(cmd[],cmdtext[])
  178. {
  179.     if(!strcmp(cmd,cmdtext,true,strlen(cmd)))
  180.         return true;
  181.     return false;
  182. }
  183.  
  184. stock params(iSpace,cmdtext[])
  185. {
  186.     new iLoop = 0,iSpaces = 0,iStr[MaxParameter];
  187.     while(iSpaces != iSpace) if(cmdtext[++iLoop] == ' ') ++iSpaces;
  188.     ++iLoop,format(iStr,MaxParameter,cmdtext[iLoop]);
  189.     return iStr;
  190. }
Add Comment
Please, Sign In to add comment