SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 04/07/2014, 02:26 AM   #1
Timeless
Big Clucker
 
Timeless's Avatar
 
Join Date: Jan 2013
Posts: 61
Reputation: 3
Default "Server:Unknown Command" using ZCMD

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 http://forum.sa-mp.com/showthread.php?t=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
__________________
HostName: ||>>••Timeless's™••Unlimited••Gaming••<<||
Address: 5.153.62.193:7778
Mode: Stunt|DM|FreeRoam| V3.6
Map: San Andreas

Last edited by Timeless; 04/07/2014 at 10:48 AM.
Timeless is offline   Reply With Quote
Old 04/07/2014, 09:09 AM   #2
KayJ
Gangsta
 
Join Date: Apr 2014
Posts: 703
Reputation: 64
Default Re: "Server:Unknown Command" using ZCMD

Nice
__________________
SA:MP Wikipedia Profile

[Filterscript] Wallet + Robbery [Y_INI] [ZCMD] [BETA v0.1]
[Filterscript] Position - Save, Load & Delete [Y_INI] [ZCMD]
[Include] InfoText TextDraw
KayJ is offline   Reply With Quote
Old 04/07/2014, 10:51 AM   #3
Timeless
Big Clucker
 
Timeless's Avatar
 
Join Date: Jan 2013
Posts: 61
Reputation: 3
Default Re: "Server:Unknown Command" using ZCMD

Quote:
Originally Posted by SturtIndia View Post
Nice
Thank you hope it helped
__________________
HostName: ||>>••Timeless's™••Unlimited••Gaming••<<||
Address: 5.153.62.193:7778
Mode: Stunt|DM|FreeRoam| V3.6
Map: San Andreas
Timeless is offline   Reply With Quote
Old 04/07/2014, 01:25 PM   #4
sammp
Gangsta
 
sammp's Avatar
 
Join Date: Jan 2014
Posts: 622
Reputation: 49
Default Re: "Server:Unknown Command" using ZCMD

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
__________________
SA-MP must become open-source to maximise longetivity of the project.
sammp is offline   Reply With Quote
Old 04/07/2014, 03:42 PM   #5
rockhopper
Gangsta
 
rockhopper's Avatar
 
Join Date: Apr 2014
Location: In A Black Hole Under You !
Posts: 609
Reputation: 33
Default Re: "Server:Unknown Command" using ZCMD

Simple and EasY
__________________
I love it <3 <3 <3
rockhopper is offline   Reply With Quote
Old 04/07/2014, 03:49 PM   #6
greentarch
Big Clucker
 
Join Date: Feb 2013
Posts: 169
Reputation: 39
Default Re: "Server:Unknown Command" using ZCMD

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.
greentarch is offline   Reply With Quote
Old 04/07/2014, 03:57 PM   #7
S4t3K
High-roller
 
S4t3K's Avatar
 
Join Date: Jan 2013
Posts: 4,470
Reputation: 165
Default Re : "Server:Unknown Command" using ZCMD

@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.
__________________
S4t3K is offline   Reply With Quote
Old 04/07/2014, 08:16 PM   #8
Timeless
Big Clucker
 
Timeless's Avatar
 
Join Date: Jan 2013
Posts: 61
Reputation: 3
Default Re: Re : "Server:Unknown Command" using ZCMD

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.
__________________
HostName: ||>>••Timeless's™••Unlimited••Gaming••<<||
Address: 5.153.62.193:7778
Mode: Stunt|DM|FreeRoam| V3.6
Map: San Andreas
Timeless is offline   Reply With Quote
Old 04/07/2014, 09:07 PM   #9
S4t3K
High-roller
 
S4t3K's Avatar
 
Join Date: Jan 2013
Posts: 4,470
Reputation: 165
Default Re : "Server:Unknown Command" using ZCMD

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

__________________
S4t3K is offline   Reply With Quote
Old 04/07/2014, 10:50 PM   #10
Timeless
Big Clucker
 
Timeless's Avatar
 
Join Date: Jan 2013
Posts: 61
Reputation: 3
Default Re: Re : "Server:Unknown Command" using ZCMD

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?
__________________
HostName: ||>>••Timeless's™••Unlimited••Gaming••<<||
Address: 5.153.62.193:7778
Mode: Stunt|DM|FreeRoam| V3.6
Map: San Andreas
Timeless is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ZCMD command returns some of the string and "Unknown command message". total3clipse Scripting Help 15 05/04/2013 10:44 PM
"Unknown Command" when server reaches close to 20 players? Outbreak Help Archive 51 02/03/2011 08:20 PM
dcmd command not working, puts out "SERVER: Unknown Command" willsuckformoney Help Archive 10 22/08/2010 05:26 PM


All times are GMT. The time now is 03:27 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.