27.01.2012, 13:41
(
Последний раз редактировалось Drake1994; 09.03.2012 в 13:27.
)
DRCMD 1.3
DescriptionWell i think everyone is know the command process. Their destination is that more faster and the simplest easiest way to deal for the scriers/players the commands.
Because this include don't use any comparative analysis but call the function local thereby is it fast. The usage is very simple, and you can easy slits the params!
Usage
Firstly look for an easier example:
Код:
DRCMD:teszt(playerid, params[]) { SendClientMessage(playerid, 0xFFFFFF, "Ez egy teszt szцveges ьzenet!"); return 1; }
Код:
DRCMD:givemoney(playerid, params[]) { new money, player; if(sscanf(params, "dd", player, money)) return SendClientMessage(playerid, 0xFFFFFF, "USAGE: /givemoney [playerid] [money]"); else if(money <= 0) return SendClientMessage(playerid, 0xFFFFFF, "ERROR: The money ammount is incorrect!"); else if(!IsPlayerConnected(player)) return SendClientMessage(playerid, 0xFFFFFF, "The player isn't online!"); else { format(string, sizeof(string), "You successfully gove %d$ to the following player: %dID", money, player); SendClientMessage(playerid, 0xFFFFFF, string); format(string, sizeof(string), "You get %d$!", money); SendClientMessage(player, 0xFFFFFF, string); } return 1; }
If you want to make a shortcut to your command. Then you can do the following things:
Код:
DRCMD:gm(playerid, params[]) { return drcmd_givemoney(playerid, params[]); }
If you want to replace your currently command process (for example ZCMD), then there is an opportunity to do this. Just take out the ZCMD and you put isntead the DRCMD. Because the DRCMD is contain the ZCMD's macro.
Synonyms:
Код:
DRCMD:command(playerid, params[]) DRCMD_command(playerid, params[]) drcmd(command, playerid, params[]) CMD:command(playerid, params[]) COMMAND:command(playerid, params[])
If you want to get the parameters lenght, don't use the strlen function, instead use the isnull function which is included/implemented in the include
Код:
if(isnull(params))
Код:
#include <a_samp> #define DRCMD:%1(%2,%3) \ forward drcmd_%1(%2,%3); \ public drcmd_%1(%2,%3) #define DRCMD_%1(%2,%3) \ DRCMD:%1(%2,%3) #define drcmd(%1,%2,%3) \ DRCMD:%1(%2,%3) #define CMD:%1(%2,%3) \ DRCMD:%1(%2,%3) #define COMMAND:%1(%2,%3) \ DRCMD:%1(%2,%3) /*public OnFilterScriptInit() { new returned; returned = OnPlayerCommandText(0, "/tesztparancs"); // Itt hнvod meg a parancs feldolgozуt printf("returned: %d", returned); return 1; }*/ main() { } public OnGameModeInit() { #define MAX_TEST (990000) for(new d; d < 10; ++d) print(" "); new dcmdtest = GetTickCount(); for(new a; a < MAX_TEST; ++a) OnPlayerDraCommandText(0, "/drcmd teszt"); printf("# DRCMD in %d",GetTickCount() - dcmdtest); new zcmdtest = GetTickCount(); for(new a; a < MAX_TEST; ++a) OnPlayerCommandText(0, "/drcmd teszt"); printf("# ZCMD in %d",GetTickCount() - zcmdtest); return true; } forward OnPlayerDraCommandText(playerid, cmdtext[]); public OnPlayerDraCommandText(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; } static bool:zcmd_g_HasOPCS = false, bool:zcmd_g_HasOPCE = false; #define MAX_FUNC_NAME (32) public OnPlayerCommandText(playerid, cmdtext[]) { if (zcmd_g_HasOPCS && !CallLocalFunction("OnPlayerCommandReceived", "is", playerid, cmdtext)) { return 1; } new pos, funcname[MAX_FUNC_NAME]; while (cmdtext[++pos] > ' ') { funcname[pos-1] = tolower(cmdtext[pos]); } format(funcname, sizeof(funcname), "cmd_%s", funcname); while (cmdtext[pos] == ' ') pos++; if (!cmdtext[pos]) { if (zcmd_g_HasOPCE) { return CallLocalFunction("OnPlayerCommandPerformed", "isi", playerid, cmdtext, CallLocalFunction(funcname, "is", playerid, "\1")); } return CallLocalFunction(funcname, "is", playerid, "\1"); } if (zcmd_g_HasOPCE) { return CallLocalFunction("OnPlayerCommandPerformed", "isi", playerid, cmdtext, CallLocalFunction(funcname, "is", playerid, cmdtext[pos])); } return CallLocalFunction(funcname, "is", playerid, cmdtext[pos]); }
1.3: