29.01.2011, 12:59
Introduction
I had launched a system command,but is epic fail
So I decided to create a command like zcmd,without multi params.
So here it is
Include:
Example for Use Ban Using sscanf:
Testing?
Credits
Credits for [iPs]DraKiNs (iPs => FeK)
Thanks,Hugs
I had launched a system command,but is epic fail
So I decided to create a command like zcmd,without multi params.
So here it is
Include:
pawn Код:
#define cmd(%1,%2,%3)\
forward @%1(%2,%3); \
public @%1(%2,%3)
forward OnPlayerReceivedCommand(iPlayer,cmdtext[],sucess);
public OnPlayerReceivedCommand(iPlayer,cmdtext[],sucess)
{
return true;
}
public
OnPlayerCommandText(iPlayer,cmdtext[])
{
if(strfind(cmdtext, " ", true) == -1)
{
cmdtext[0] = '@';
return CallLocalFunction("OnPlayerReceivedCommand","isd",iPlayer,cmdtext,CallLocalFunction(cmdtext,"is",playerid," "));
}
new iLoop = 0,iSpaces = 0,iStr[32];
while(iSpaces != 1) if(cmdtext[++iLoop] == ' ') ++iSpaces;
++iLoop,format(iStr,32,cmdtext[iLoop]),cmdtext[iLoop - 1] = '\0';
printf("Cmd: %s | Param: %s",cmdtext,iStr);
return CallLocalFunction("OnPlayerReceivedCommand","isd",iPlayer,cmdtext,CallLocalFunction(cmdtext,"is",playerid,iStr));
}
pawn Код:
//In Final Command
cmd(ban,iPlayer,params[])
{
if (!IsPlayerAdmin(iPlayer))
return SendClientMessage(iPlayer, VERMELHO, "[ERROR] Not Admin");
new id,message[64];
if (sscanf(params, "us[64]", id,message))
return SendClientMessage(iPlayer,AMARELO, "Use: /ban [id/nick] [reason]");
if (!IsPlayerConnected(id))
return SendClientMessage(iPlayer,VERMELHO, "[ERRO] Player is Offline");
if (id == iPlayer)
return SendClientMessage(iPlayer,VERMELHO, "[ERRO] Not ban your");
BanEx(id,message);
return true;
}
Testing?
pawn Код:
#include "../Includes1/a_samp.inc"
#define icmd(%1,%2,%3)\
forward @%1(%2,%3); \
public @%1(%2,%3)
public OnFilterScriptInit()
{
#define MAX_TEST (990000)
// ICMD TEST
new dcmdtest = GetTickCount();
for(new a; a < MAX_TEST; ++a)
OnPlayeriCmdCommandText(0,"/icmd mans");
printf("# ICMD in %d",GetTickCount() - dcmdtest);
//ZCMD TEST
new zcmdtest = GetTickCount();
for(new a; a < MAX_TEST; ++a)
OnPlayerCommandText(0, "/zcmd test");
printf("# ZCMD in %d",GetTickCount() - zcmdtest);
return true;
}
//Include ICMD
forward OnPlayerReceivedCommandICMD(iPlayer,cmdtext[],sucess);
public OnPlayerReceivedCommandICMD(iPlayer,cmdtext[],sucess)
{
return true;
}
forward OnPlayeriCmdCommandText(iPlayer,cmdtext[]);
public OnPlayeriCmdCommandText(iPlayer,cmdtext[])
{
if(strfind(cmdtext, " ", true) == -1)
{
cmdtext[0] = '@';
return CallLocalFunction("OnPlayerReceivedCommandICMD","isd",iPlayer,cmdtext,CallLocalFunction(cmdtext,"is",iPlayer," "));
}
new iLoop = 0,iSpaces = 0,iStr[32];
while(iSpaces != 1) if(cmdtext[++iLoop] == ' ') ++iSpaces;
++iLoop,format(iStr,32,cmdtext[iLoop]),cmdtext[iLoop - 1] = '\0';
return CallLocalFunction("OnPlayerReceivedCommandICMD","isd",iPlayer,cmdtext,CallLocalFunction(cmdtext,"is",iPlayer,iStr));
}
//INCLUDE ZCMD
#define MAX_FUNC_NAME (32)
#define zCOMMAND:%1(%2) \
forward zcmd_%1(%2); \
public zcmd_%1(%2)
#define zCMD:%1(%2) \
zCOMMAND:%1(%2)
#define zcommand(%1,%2,%3) \
zCOMMAND:%1(%2, %3)
#define zcmd(%1,%2,%3) \
zCOMMAND:%1(%2, %3)
#if !defined isnull
#define isnull(%1) \
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
forward OnPlayerCommandReceived(iPlayer, cmdtext[]);
forward OnPlayerCommandPerformed(iPlayer, cmdtext[], success);
static
bool:zcmd_g_HasOPCS = false,
bool:zcmd_g_HasOPCE = false;
forward zcmd_OnFilterScriptInit();
public OnGameModeInit()
{
zcmd_g_HasOPCS = funcidx("OnPlayerCommandReceived") != -1;
zcmd_g_HasOPCE = funcidx("OnPlayerCommandPerformed") != -1;
if (funcidx("zcmd_OnGameModeInit") != -1)
{
return CallLocalFunction("zcmd_OnGameModeInit", "");
}
return 1;
}
public OnPlayerCommandText(iPlayer, cmdtext[])
{
if (zcmd_g_HasOPCS && !CallLocalFunction("OnPlayerCommandReceived", "is", iPlayer, cmdtext))
{
return 1;
}
new
pos,
funcname[MAX_FUNC_NAME];
while (cmdtext[++pos] > ' ')
{
funcname[pos-1] = tolower(cmdtext[pos]);
}
format(funcname, sizeof(funcname), "zcmd_%s", funcname);
while (cmdtext[pos] == ' ') pos++;
if (!cmdtext[pos])
{
if (zcmd_g_HasOPCE)
{
return CallLocalFunction("OnPlayerCommandPerformed", "isi", iPlayer, cmdtext, CallLocalFunction(funcname, "is", iPlayer, "\1"));
}
return CallLocalFunction(funcname, "is", iPlayer, "\1");
}
if (zcmd_g_HasOPCE)
{
return CallLocalFunction("OnPlayerCommandPerformed", "isi", iPlayer, cmdtext, CallLocalFunction(funcname, "is", iPlayer, cmdtext[pos]));
}
return CallLocalFunction(funcname, "is", iPlayer, cmdtext[pos]);
}
//COMMANDS
zcmd(zcmd,iPlayer,params[])
{
return true;
}
icmd(zcmd,iPlayer,params[])
{
return true;
}
Код:
[12:01:38] # ICMD in 214 [12:01:39] # ZCMD in 221
Credits for [iPs]DraKiNs (iPs => FeK)
Thanks,Hugs