How to use OnPlayerCommandText with ZCMD -
MadeMan - 12.08.2011
ZCMD is a good way to process commands, but there is a problem using it with scripts that have many commands defined already, using other methods that require the OnPlayerCommandText callback (such as strcmp or dcmd). If you want to use ZCMD there, you would have to convert ALL the commands into ZCMD. But if you have many commands, it could take a lot of time. Luckily, there is a fix for that problem.
You can put the contents of zcmd.inc inside your gamemode/filterscript.
EDIT: There is an easier way -->
CLICK HERE
Define
First choose how you define your commands.
If you are using COMMAND:mycmd(playerid, params[])
put this into your script
pawn Code:
#define COMMAND:%1(%2) \
forward cmd_%1(%2); \
public cmd_%1(%2)
If you are using CMD:mycmd(playerid, params[])
put this into your script
pawn Code:
#define CMD:%1(%2) \
forward cmd_%1(%2); \
public cmd_%1(%2)
If you are using command(mycmd, playerid, params[])
put this into your script
pawn Code:
#define command(%1,%2) \
forward cmd_%1(%2); \
public cmd_%1(%2)
If you are using cmd(mycmd, playerid, params[])
put this into your script
pawn Code:
#define cmd(%1,%2) \
forward cmd_%1(%2); \
public cmd_%1(%2)
OnPlayerCommandText
Now to the OnPlayerCommandText callback.
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
new
pos,
funcname[32];
while (cmdtext[++pos] > ' ')
{
funcname[pos-1] = tolower(cmdtext[pos]);
}
format(funcname, sizeof(funcname), "cmd_%s", funcname);
while (cmdtext[pos] == ' ') pos++;
if (!cmdtext[pos])
{
return CallLocalFunction(funcname, "is", playerid, "\1");
}
return CallLocalFunction(funcname, "is", playerid, cmdtext[pos]);
}
If you want to send your own message when command was not found instead of default "SERVER: Unknown command."
NOTE: Use it ONLY in the GAMEMODE script, because returning 1 in a filterscript will disable commands in other scripts.
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
new
pos,
funcname[32];
while (cmdtext[++pos] > ' ')
{
funcname[pos-1] = tolower(cmdtext[pos]);
}
format(funcname, sizeof(funcname), "cmd_%s", funcname);
while (cmdtext[pos] == ' ') pos++;
if (!cmdtext[pos]) cmdtext[pos] = '\1';
if(!CallLocalFunction(funcname, "is", playerid, cmdtext[pos]))
{
SendClientMessage(playerid, -1, "Invalid command. Use /help");
}
return 1;
}
And you are done.
Example
Now you can use ZCMD with strcmp for example
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/help", true) == 0)
{
SendClientMessage(playerid, -1, "Available commands: ");
return 1;
}
if(strcmp(cmdtext, "/kill", true) == 0)
{
SetPlayerHealth(playerid, 0);
return 1;
}
new
pos,
funcname[32];
while (cmdtext[++pos] > ' ')
{
funcname[pos-1] = tolower(cmdtext[pos]);
}
format(funcname, sizeof(funcname), "cmd_%s", funcname);
while (cmdtext[pos] == ' ') pos++;
if (!cmdtext[pos])
{
return CallLocalFunction(funcname, "is", playerid, "\1");
}
return CallLocalFunction(funcname, "is", playerid, cmdtext[pos]);
}
NOTE: You don't need the #include <zcmd> line anymore.
Credits to ZeeX for the original
ZCMD include.
Re: How to use OnPlayerCommandText with ZCMD -
Darnell - 12.08.2011
I'd rather zCMD lol.
Re: How to use OnPlayerCommandText with ZCMD -
Antonio [G-RP] - 12.08.2011
Quote:
Originally Posted by Darnell
I'd rather zCMD lol.
|
Yes, we all would, but the point of his tutorial is to make it easy for you to change your script (ones that use strcmp, with hundreds of commands) in to using zCMD.
Re: How to use OnPlayerCommandText with ZCMD -
HyperZ - 12.08.2011
Nice Tutorial..
Re: How to use OnPlayerCommandText with ZCMD -
emokidx - 12.08.2011
wow,, nice tut!
Re: How to use OnPlayerCommandText with ZCMD -
AztreX - 29.08.2011
Thanks.
Re: How to use OnPlayerCommandText with ZCMD -
SantarioLeone - 06.10.2011
pawn Code:
#define CMD:%1(%2) \ //line 88
forward cmd_%1(%2); \ //line 89
public cmd_%1(%2) //line 90
pawn Code:
C:\Users\Tab\Desktop\True Roleplay [0.3c]\True Roleplay [0.3c]\gamemodes\TRP.pwn(90) : warning 201: redefinition of constant/macro (symbol "CMD:%1(%2)")
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
1 Warning.
the only redefinition i see is in the code i used from here, but if i delete any of the code or comment it out, pawn crashes, whats the problem with it or what did i do wrong?
Re: How to use OnPlayerCommandText with ZCMD -
Tigerkiller - 06.10.2011
Useful Tutorial
Thanks
Re: How to use OnPlayerCommandText with ZCMD -
Mr. Random - 07.10.2011
Excellent information & tutorial, Thank you.
Respuesta: How to use OnPlayerCommandText with ZCMD -
SuperMarioRol - 01.11.2011
That's very great
Re: How to use OnPlayerCommandText with ZCMD -
JordanMaddox - 09.12.2011
Loving this tutorial thanks!
Re: How to use OnPlayerCommandText with ZCMD -
BoyDenker - 31.01.2012
Quote:
Originally Posted by JordanMaddox
Loving this tutorial thanks!
|
same
Re: How to use OnPlayerCommandText with ZCMD -
thedark222 - 31.01.2012
Awesome thanks alot .
Re : Re: How to use OnPlayerCommandText with ZCMD -
Stefano.R - 10.03.2012
Quote:
Originally Posted by MadeMan
There is actually an easier way of doing this.
All you have to do is change your OnPlayerCommandText to
pawn Code:
public OnPlayerCommandPerformed(playerid, cmdtext[], success) { if(success) { return 1; } if(strcmp(cmdtext, "/help", true) == 0) { SendClientMessage(playerid, -1, "Available commands: "); return 1; } if(strcmp(cmdtext, "/kill", true) == 0) { SetPlayerHealth(playerid, 0); return 1; } return 0; }
You also need the #include line
|
I got thoose errors:
Quote:
C:\Users\Antoine\Desktop\SAMP\Serveur 0.3d\filterscripts\voed.pwn(670 : error 004: function "zcmd_OnPlayerCommandText" is not implemented
C:\Users\Antoine\Desktop\SAMP\Serveur 0.3d\filterscripts\voed.pwn(677 : error 004: function "zcmd_OnPlayerCommandText" is not implemented
C:\Users\Antoine\Desktop\SAMP\Serveur 0.3d\filterscripts\voed.pwn(6785) : error 004: function "zcmd_OnPlayerCommandText" is not implemented
C:\Users\Antoine\Desktop\SAMP\Serveur 0.3d\filterscripts\voed.pwn(6792) : error 004: function "zcmd_OnPlayerCommandText" is not implemented
C:\Users\Antoine\Desktop\SAMP\Serveur 0.3d\filterscripts\voed.pwn(6799) : error 004: function "zcmd_OnPlayerCommandText" is not implemented
C:\Users\Antoine\Desktop\SAMP\Serveur 0.3d\filterscripts\voed.pwn(6806) : error 004: function "zcmd_OnPlayerCommandText" is not implemented
C:\Users\Antoine\Desktop\SAMP\Serveur 0.3d\filterscripts\voed.pwn(6816) : error 004: function "zcmd_OnPlayerCommandText" is not implemented
C:\Users\Antoine\Desktop\SAMP\Serveur 0.3d\filterscripts\voed.pwn(6820) : error 004: function "zcmd_OnPlayerCommandText" is not implemented
C:\Users\Antoine\Desktop\SAMP\Serveur 0.3d\filterscripts\voed.pwn(6846) : error 004: function "zcmd_OnPlayerCommandText" is not implemented
C:\Users\Antoine\Desktop\SAMP\Serveur 0.3d\filterscripts\voed.pwn(6855) : error 004: function "zcmd_OnPlayerCommandText" is not implemented
C:\Users\Antoine\Desktop\SAMP\Serveur 0.3d\filterscripts\voed.pwn(7306) : error 004: function "zcmd_OnPlayerCommandText" is not implemented
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
11 Errors.
|
Re: How to use OnPlayerCommandText with ZCMD -
VIPAwesome - 10.03.2012
Nice Tutorial But Why We Type Extra Just Use #include <ZCMD> :P
Re: How to use OnPlayerCommandText with ZCMD -
Tom Kingston - 08.06.2012
Lol,I'd say this tutorial is useless since strcmp is a fucking scripting way and the slowest one when you can make a command with ZCMD for twice faster.
Example:
pawn Code:
#include <zcmd>
#define COLOR WHITE 0xFFFFFFAA
CMD:help(playerid,params[])
{
SendClientMessage(playerid,COLOR_WHITE,"/enter /exit /order /buy /buyhouse /sellhouse");
SendClientMessage(playerid,COLOR_WHITE,"/gedit /gnext /gstatus /ddnext /ddedit /ddname");
return 1;
}
See? It's twice faster than strcmp...
Re: How to use OnPlayerCommandText with ZCMD -
AliHaider - 17.06.2012
its better then we use zcmd xD
Re: How to use OnPlayerCommandText with ZCMD -
Rudy_ - 19.06.2012
nice work
Re: How to use OnPlayerCommandText with ZCMD -
[CwS]TonyFortebracci - 19.10.2012
Nice Tutorial man
Re: How to use OnPlayerCommandText with ZCMD -
M3mPHi$_S3 - 19.10.2012
That's what a need friends thansk alot .