[Include] DRCMD - Fast and easy command process!
#1

DRCMD 1.3
Description
Well 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;
}
Then a "more complicated" givemoney code:
Код:
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;
}
Reference
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[]);
}
Synonym
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[])
Notice
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))
Speed against ZCMD

Код:
#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]);
}
Download

1.3:
Reply


Messages In This Thread
DRCMD - Fast and easy command process! - by Drake1994 - 27.01.2012, 13:41
Re: DRCMD - Fast and easy command process! - by Lorenc_ - 27.01.2012, 13:44
Re: DRCMD - Fast and easy command process! - by Drake1994 - 27.01.2012, 13:46
Re: DRCMD - Fast and easy command process! - by Lorenc_ - 27.01.2012, 13:47
Re: DRCMD - Fast and easy command process! - by Drake1994 - 27.01.2012, 13:48
Re: DRCMD - Fast and easy command process! - by Drake1994 - 27.01.2012, 14:46
Re: DRCMD - Fast and easy command process! - by Drake1994 - 09.03.2012, 13:30
Re: DRCMD - Fast and easy command process! - by System64 - 09.03.2012, 17:30
Re: DRCMD - Fast and easy command process! - by Drake1994 - 09.03.2012, 18:33
Respuesta: DRCMD - Fast and easy command process! - by Kurama - 10.03.2012, 05:21
Re: DRCMD - Fast and easy command process! - by Drake1994 - 10.03.2012, 05:48
Re: DRCMD - Fast and easy command process! - by Reklez - 10.03.2012, 05:56
Re: DRCMD - Fast and easy command process! - by Ballu Miaa - 10.03.2012, 06:17
Re: DRCMD - Fast and easy command process! - by Drake1994 - 10.03.2012, 07:22
Re: DRCMD - Fast and easy command process! - by System64 - 10.03.2012, 08:45
Re: DRCMD - Fast and easy command process! - by Drake1994 - 10.03.2012, 09:13
Re: DRCMD - Fast and easy command process! - by Danee - 10.03.2012, 09:32
Re: DRCMD - Fast and easy command process! - by Chaster - 10.03.2012, 09:46
Re: DRCMD - Fast and easy command process! - by System64 - 10.03.2012, 10:17
Re: DRCMD - Fast and easy command process! - by Drake1994 - 10.03.2012, 10:20
Re: DRCMD - Fast and easy command process! - by System64 - 10.03.2012, 10:32
Re: DRCMD - Fast and easy command process! - by Drake1994 - 10.03.2012, 11:07

Forum Jump:


Users browsing this thread: 2 Guest(s)