[Tutorial] "Server:Unknown Command" using ZCMD
#1

I'm gonna show you guys a tutorial on how to turn off or change the "Server Unknown Command" text when using ZCMD

First of all if you're not sure on which command processor is ZCMD then this is ZCMD https://sampforum.blast.hk/showthread.php?tid=91354 thats the processor i'm going to explain

some usage of ZCMD and this feature can work for all of them

Example of some usage:
PHP Code:
COMMAND:mycommand(playeridparams[]) // or CMD:mycommand(playerid, params[]) 
{
  
// Do something
  
return 1

or
PHP Code:
command(mycommandplayeridparams[]) // or cmd(mycommand, playerid, params[])
{
  
// Do something
  
return 1

or
PHP Code:
CMD:mycommand(playeridparams[])
{
//Do something 
   
return 1;

normally to change the "Server:Unknown Command" text is using
PHP Code:
public OnPlayerCommandText(playeridcmdtext[])
{
    if (
strcmp("/mycommand"cmdtexttrue10) == 0)
    {
        
// Do something here
        
return 1;
    }
    return 
0;

however thats not needed when using ZCMD this is much faster and easier.
To change the message we have to use a callback called
PHP Code:
 public OnPlayerCommandPerformedplayeridcmdtext[ ], success 
we will add these lines to our callback

PHP Code:

 
if (!success)
    {
       
//----- your invalid command text to show would go here 
    

so now it would look like this
PHP Code:
public OnPlayerCommandPerformed(playeridcmdtext[], success)
{
    if (!
success)
    {
       /<---- 
your invalid command text to show would go here
    
}
    return 
0;

now we add our invalid command text to the callback
PHP Code:
public OnPlayerCommandPerformed(playeridcmdtext[], success)
{
    if (!
success)
    {
       
SendClientMessage(playerid,COLOR_RED,"Hey you enterred a wrong command");
    }
    return 
0;

now if you don't to have "Server:Unknown Command" being spammed everytime you succesfully did a command? we simple locate the return value in the callback and instead of having 0 we change it to 1 and voila!
PHP Code:
public OnPlayerCommandPerformed(playeridcmdtext[], success)
{
    if (!
success)
    {
       
SendClientMessage(playerid,COLOR_RED,"Hey you enterred a wrong command");
    }
    return 
1;

and thats it your "Server:Unknown Command" is changed


COMMON ERRORS:
i've seen a few statements like this

1.
PHP Code:
public OnPlayerCommandPerformed(playeridcmdtext[], success)
{
    return 
SendClientMessage(playerid,COLOR_RED,"Hey you typed a wrong command"); // you can change the text to whatever you want to suit your server 
However this would work but the invalid command text would be spammed everytime you do a command.

2.
PHP Code:
public OnPlayerCommandPerformedplayeridcmdtext[ ], success )
{
    if( 
success == )
        return 
SendClientMessageplayeridCOLOR"Your new unknown command text" );

that won't work as the pawno compiler will give you a warning like this
PHP Code:
warning 209: function "OnPlayerCommandPerformed" should return a value 
and if you try correcting this warning by creating a return value like this it would give you an unreachable code warning
PHP Code:
public OnPlayerCommandPerformedplayeridcmdtext[ ], success )
{
    if( 
success == )
    {
       
     }
     return 
SendClientMessageplayeridCOLOR"Your new unknown command text" );
     return 
0;

and if you have something like this it won't work either
3.
PHP Code:
public OnPlayerCommandPerformedplayeridcmdtext[ ], success )
{
    if( 
success == )
    {
        
     }
     return 
SendClientMessageplayeridCOLOR"Your new unknown command text" );

cause your just basically telling the server to spam "your new unknown command text" every time a command is performed


now if you want to get rid of this text completely without displaying any message? we simply go back to the return value and instead of displaying a message we simply change the "0" to a "1"

like this
PHP Code:
public OnPlayerCommandPerformed(playeridcmdtext[], success)
{
    return 
1;//If player writes command wrong this will still return it as a true and the message will not be displayed

so now the no text will be displayed if a player types an invalid command

I hoped you understood the tutorial and i hoped it helped someone out there cause i haven't found any tutorials with this so i just thought i should create one
Reply


Messages In This Thread
"Server:Unknown Command" using ZCMD - by Timeless - 04.07.2014, 01:26
Re: "Server:Unknown Command" using ZCMD - by KayJ - 04.07.2014, 08:09
Re: "Server:Unknown Command" using ZCMD - by Timeless - 04.07.2014, 09:51
Re: "Server:Unknown Command" using ZCMD - by sammp - 04.07.2014, 12:25
Re: "Server:Unknown Command" using ZCMD - by rockhopper - 04.07.2014, 14:42
Re: "Server:Unknown Command" using ZCMD - by greentarch - 04.07.2014, 14:49
Re : "Server:Unknown Command" using ZCMD - by S4t3K - 04.07.2014, 14:57
Re: Re : "Server:Unknown Command" using ZCMD - by Timeless - 04.07.2014, 19:16
Re : "Server:Unknown Command" using ZCMD - by S4t3K - 04.07.2014, 20:07
Re: Re : "Server:Unknown Command" using ZCMD - by Timeless - 04.07.2014, 21:50

Forum Jump:


Users browsing this thread: 2 Guest(s)