Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- // ======
- // zcmd
- // ======
- #define OnPlayerCommandText czcmd_OnPlayerCommandText
- forward czcmd_OnPlayerCommandText(playerid, cmdtext[]);
- #define _ALS_OnPlayerCommandText
- #include <zcmd>
- // Set by the compiler:
- //
- // FOR /L %%i IN (0, 1, 2703) DO pawncc.exe "..\gamemodes\cmdtest.pwn" -;+ -\ -(+ CMD_NUM=%%i -o..\gamemodes\cmdtest_%%i
- //
- // zcmd
- CMD:first(playerid, params[]){ return 1; }
- #define XCMD(%0) CMD:%0(playerid, params[]){ return 1; }
- #include "cmd"
- #undef XCMD
- CMD:last(playerid, params[]){ return 1; }
- #undef CMD
- #undef COMMAND
- // ===========
- // y_command
- // ===========
- #undef OnPlayerCommandText
- #define OnPlayerCommandText cycmd_OnPlayerCommandText
- forward cycmd_OnPlayerCommandText(playerid, cmdtext[]);
- // So we can do it with no players connected.
- #define YSI_NO_MASTER
- #define _YSI_SPECIAL_DEBUG
- // Disable y_version
- #define _inc_y_version
- #include <YSI\y_commands>
- // ycmd
- YCMD:first(playerid, params[], help){ return 1; }
- #define XCMD(%0) YCMD:%0(playerid, params[], help){ return 1; }
- #include "cmd"
- #undef XCMD
- YCMD:last(playerid, params[], help){ return 1; }
- #undef OnPlayerCommandText
- #define OnPlayerCommandText drcmd_OnPlayerCommandText
- forward drcmd_OnPlayerCommandText(playerid, cmdtext[]);
- // drcmd
- DRCMD:first(playerid, params[], help){ return 1; }
- #define XCMD(%0) DRCMD:%0(playerid, params[]){ return 1; }
- #include "cmd"
- #undef XCMD
- DRCMD:last(playerid, params[], help){ return 1; }
- main()
- {
- new
- t0,
- t1,
- t2,
- t3,
- t4,
- t5;
- t0 = GetTickCount();
- for (new i = 0; i != 10000; ++i)
- {
- dkcmd_OnPlayerCommandText(0, "/first");
- dkcmd_OnPlayerCommandText(0, "/last");
- dkcmd_OnPlayerCommandText(0, "/none");
- }
- t1 = GetTickCount();
- for (new i = 0; i != 10000; ++i)
- {
- fcmd_OnPlayerCommandText(0, "/first");
- fcmd_OnPlayerCommandText(0, "/last");
- fcmd_OnPlayerCommandText(0, "/none");
- }
- t2 = GetTickCount();
- for (new i = 0; i != 10000; ++i)
- {
- czcmd_OnPlayerCommandText(0, "/first");
- czcmd_OnPlayerCommandText(0, "/last");
- czcmd_OnPlayerCommandText(0, "/none");
- }
- t3 = GetTickCount();
- for (new i = 0; i != 10000; ++i)
- {
- cycmd_OnPlayerCommandText(0, "/first");
- cycmd_OnPlayerCommandText(0, "/last");
- cycmd_OnPlayerCommandText(0, "/none");
- }
- t4 = GetTickCount();
- for (new i = 0; i != 10000; ++i)
- {
- drcmd_OnPlayerCommandText(0, "/first");
- drcmd_OnPlayerCommandText(0, "/last");
- drcmd_OnPlayerCommandText(0, "/none");
- }
- printf("%d %d %d %d %d", CMD_NUM, t1 - t0, t2 - t1, t3 - t2, t4 - t3, t5 - t4);
- new
- str[32];
- format(str, sizeof (str), "changemode cmdtest_%d", CMD_NUM + 1);
- SendRconCommand(str);
- }
- // ======
- // drcmd
- // ======
- #define DRCMD:%1(%2,%3) \
- forward drcmd_%1(%2,%3); \
- public drcmd_%1(%2,%3)
- public drcmd_OnPlayerCommandText(playerid, cmdtext[])
- {
- new
- function[32],
- szokozmeddig = -1;
- while(++szokozmeddig < strlen(cmdtext)) if((cmdtext[szokozmeddig] == ' ')) break;
- strmid(function, cmdtext, 1, szokozmeddig);
- format(function, sizeof(function), "drcmd_%s", function);
- while(cmdtext[szokozmeddig] == ' ') szokozmeddig++;
- if(funcidx(function) != -1)
- {
- if(szokozmeddig == strlen(cmdtext))
- {
- return CallLocalFunction(function, "is", playerid, "\1");
- }
- return CallLocalFunction(function, "is", playerid, cmdtext[szokozmeddig]);
- }
- return 0;
- }
- // ======
- // fcmd
- // ======
- #define fcmd(%1,%2) \
- forward fcmd_%1(%2); \
- public fcmd_%1(%2)
- #define MaxFrequence (066)
- #define MaxParameter (064)
- #define MaxFunctions (032)
- #define MaxLenString (128)
- new
- sIndex = 0,
- iLenPart = 0,
- iPosPart = 0,
- iStrMid = 0,
- iLenght = 0,
- cmds[ MaxFunctions ]
- ;
- forward fcmd_OnPlayerCommandText(playerid,cmdtext[]);
- public fcmd_OnPlayerCommandText(playerid,cmdtext[])
- {
- //Here you can write cmds witout params!
- return DelimiterCommand(playerid,cmdtext);
- }
- new iParams[ MaxFrequence ][ MaxParameter ],iTotalParams[MaxLenString];
- stock
- DelimiterCommand(playerid,sStringSource[])
- {
- iLenght = strlen(sStringSource);
- sIndex = 0;
- iLenPart = 0;
- iPosPart = 0;
- iStrMid = 0;
- for(new aIndex = 1; aIndex < MaxFrequence; ++aIndex) iParams[aIndex][0] = '\0';
- iTotalParams[0] = '\0';
- while(sIndex <= iLenght)
- {
- if(sStringSource[sIndex] == ' ' && sStringSource[sIndex - 1] != ' ' || sIndex == iLenght)
- {
- iStrMid = strmid(iParams[iPosPart], sStringSource, iLenPart, sIndex, 128);
- iParams[iPosPart][iStrMid] = 0,iLenPart = (sIndex + 1), ++iPosPart;
- if(iPosPart == 1)
- format(iTotalParams,MaxLenString, "%s",sStringSource[sIndex]);
- }
- ++sIndex;
- }
- format(cmds, sizeof cmds,"fcmd_%s",iParams[0][1]);
- return CallLocalFunction(cmds,"i",playerid);
- }
- // fcmd
- fcmd(first,playerid){ return 1; }
- #define XCMD(%0) fcmd(%0,playerid){ return 1; }
- #include "cmd"
- #undef XCMD
- fcmd(last,playerid){ return 1; }
- // =======
- // dkcmd
- // =======
- #define dkcmd(%0) params(%0,cmdtext)
- //#define MaxParameter (064)
- //#define MaxLenString (128)
- forward dkcmd_OnPlayerCommandText(playerid,cmdtext[]);
- public dkcmd_OnPlayerCommandText(playerid,cmdtext[])
- {
- // dkcmd
- if (Command("/first", cmdtext)) return 1;
- #define XCMD(%0) if (Command("/"#%0, cmdtext)) return 1;
- #include "cmd"
- #undef XCMD
- if (Command("/last", cmdtext)) return 1;
- return 0;
- }
- stock Command(cmd[],cmdtext[])
- {
- if(!strcmp(cmd,cmdtext,true,strlen(cmd)))
- return true;
- return false;
- }
- stock params(iSpace,cmdtext[])
- {
- new iLoop = 0,iSpaces = 0,iStr[MaxParameter];
- while(iSpaces != iSpace) if(cmdtext[++iLoop] == ' ') ++iSpaces;
- ++iLoop,format(iStr,MaxParameter,cmdtext[iLoop]);
- return iStr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement