[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
#2

Nice
Reply
#3

Quote:
Originally Posted by SturtIndia
View Post
Nice
Thank you hope it helped
Reply
#4

I like to use the cmdtext[] parameter. Format the message in a string, for example:

pawn Code:
format(string, sizeof(string), "Hey! %s isn't a valid command!", cmdtext);
But nice for people who don't know how to do this
Reply
#5

Simple and EasY
Reply
#6

You can do this, too (untested, but compiles):
pawn Code:
public OnPlayerCommandPerformed( playerid, cmdtext[ ], success )
    return ( !success ) ? ( SendClientMessage( playerid, -1, ">> That command doesn't exist! (/cmds)" ), 1 ) : ( 1 );
Anyways, my suggestion is, rename the topic (ask a moderator) to OnPlayerCommandPerformed tutorial, and add everything you know, like:
>> Player must spawn before using any commands
>> Player must be logged in before using any commands
>> etcetera.
Reply
#7

@Greentarch : This one looks clearer :

PHP Code:

public OnPlayerCommandPerformedplayeridcmdtext[ ], success )
{
      return 
success SendClientMessage(playerid, -1">> That command doesn't exist! (/cmds)");

The wiki says that "SendClientMessage" returns 1 if the function executes successful. This way, returning 1 just after that would be a bit useless.

@Author : Some parts of your "COMMON ERRORS" are very bad coded.

I take this code as an example :


pawn Code:
public OnPlayerCommandPerformed( playerid, cmdtext[ ], success )
{
    if( success == 0 )
    {
       
     }
     return SendClientMessage( playerid, COLOR, "Your new unknown command text" );
     return 0;
}
It won't work as a solution ! You'll even get an error during the compilation !

This one would work :

pawn Code:
public OnPlayerCommandPerformed( playerid, cmdtext[ ], success )
{
    if(!success) return SendClientMessage( playerid, COLOR, "Your new unknown command text" );
    return 1;
}

Because as Zeex said :

Quote:
Originally Posted by Zeex
pawn Code:
OnPlayerCommandPerformed(playerid, cmdtext[], success)
And this one gets called after command execution, here if you do "return 0" the player will see standard "Unknown command" message. The "success" parameter is equal to value returned by command function returns (if it doesn't exist success will be 0).
Correct your whole tutorial please.
Reply
#8

Quote:
Originally Posted by S4t3K
View Post
@Author : Some parts of your "COMMON ERRORS" are very bad coded.

I take this code as an example :

pawn Code:
public OnPlayerCommandPerformed( playerid, cmdtext[ ], success )
{
    if( success == 0 )
    {
       
     }
     return SendClientMessage( playerid, COLOR, "Your new unknown command text" );
     return 0;
}
It won't work as a solution ! You'll even get an error during the compilation !

This one would work :

pawn Code:
public OnPlayerCommandPerformed( playerid, cmdtext[ ], success )
{
    if(!success) return SendClientMessage( playerid, COLOR, "Your new unknown command text" );
    return 1;
}

Correct your whole tutorial please.
FYI the errors i have there are common mistakes i picked up from other help request threads not my codes. meaning people make common mistakes duh every code i placed there was tested before placing, its my method of coding that works, i share my work.if u test it the way i said it wud turn out exactly as i said in conclusion everything is placed the way it should be.
Reply
#9

Well, tell me how this is supposed to work and translate it step-to-step for a newbie like me.

PHP Code:

public OnPlayerCommandPerformedplayeridcmdtext[ ], success 

    if( 
success == 
    { 
        
     } 
     return 
SendClientMessageplayeridCOLOR"Your new unknown command text" ); 
     return 
0

Because the way I have understood it is :

PHP Code:

public OnPlayerCommandPerformedplayeridcmdtext[ ], success )  // Entering the callback

    if( 
success == // If the command doesn't exist
    

        
// Do...nothing ?
     

     return 
SendClientMessageplayeridCOLOR"Your new unknown command text" ); // In any case, we have to return a message and to get a "warning : unrecheable code" for the return 0 placed just below.
     
return 0

Reply
#10

Quote:
Originally Posted by S4t3K
View Post
Well, tell me how this is supposed to work and translate it step-to-step for a newbie like me.

PHP Code:

public OnPlayerCommandPerformedplayeridcmdtext[ ], success 

    if( 
success == 
    { 
        
     } 
     return 
SendClientMessageplayeridCOLOR"Your new unknown command text" ); 
     return 
0

Because the way I have understood it is :

PHP Code:

public OnPlayerCommandPerformedplayeridcmdtext[ ], success )  // Entering the callback

    if( 
success == // If the command doesn't exist
    

        
// Do...nothing ?
     

     return 
SendClientMessageplayeridCOLOR"Your new unknown command text" ); // In any case, we have to return a message and to get a "warning : unrecheable code" for the return 0 placed just below.
     
return 0

lol thats one the common erors btw not the working code thats if the person try to correct the warning "onplayercommandperformed should have a return vale" i said so in the tutorial because it wud be expected however wrong.."COMMON ERROS", are you trying to say i didn't explain it good enough?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)