SA-MP Forums Archive
[Include] y_commands - Most flexible and fastest command processor, now on the YSI wiki - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] y_commands - Most flexible and fastest command processor, now on the YSI wiki (/showthread.php?tid=571047)



y_commands - Most flexible and fastest command processor, now on the YSI wiki - corne - 15.04.2015

Introduction

This is an update to my old command processing system in YSI. Since then I have steamlined a lot of the code and made it more robust and easier to use. It can also now be used as a drop in replacement for zcmd.Why do we need another command processing system? ZCMD is already very fast!

y_commands is actually now FASTER than ZCMD and is designed to handle huge numbers of commands. Additionally included in that speed is permission checks (to set exactly who can use the command), a help system, command renaming and removal plus more.This file includes the first preview of my new master system which I will explain in greater detail in a later post - for now don't worry about it beyond what I tell you here.

Download

This library is a part of YSI, which can be found here. Keep your eye on that topic and your server log for updates.

YSI Download Topic

FeaturesUseCommands

The full list of commands is given below.Timings

This graph is a comparison between zcmd, y_command and fcmd. Note that strcmp based command processors are excluded for brevity - they are no-where near this speed.

Currently there is no graph displaying the speed comparison. You can make one yourself, or if there is a demand for it I might attempt to make one.

The code for this test can be found here:

http://y-less.pastebin.com/HLgGVynL
http://y-less.pastebin.com/8Cp2p5Pv

The batch command to build the required scripts is:

Code:
FOR /L %%i IN (0, 1, 2703) DO pawncc.exe "..\gamemodes\cmdtest.pwn" -;+ -\ -(+ CMD_NUM=%%i -o..\gamemodes\cmdtest_%%i
Credits
I am reposting this include (made by Y_Less) with the thought of what he said to several members of the community. Everything that could help someone should not be deleted from the forums, which is something I agree with since I learned a lot by reading the tutorials on here. He made a lot of things that are used by lots of servers and that knowledge should not be lost for present and future developers.


Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - SickAttack - 16.04.2015

Are you or any of those that are re-posting his threads going to continue the development of such includes? If not, then there should be someone who is whiling to do so.


Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - Crayder - 16.04.2015

Quote:
Originally Posted by SickAttack
View Post
Are you or any of those that are re-posting his threads going to continue the development of such includes? If not, then there should be someone who is whiling to do so.
I can name three people already doing so.


Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - corne - 16.04.2015

Quote:
Originally Posted by SickAttack
View Post
Are you or any of those that are re-posting his threads going to continue the development of such includes? If not, then there should be someone who is whiling to do so.
I'm not working on this include. I'm only trying to find and repost information that may be useful to beginners. There are (I believe) three or four other people working on YSI, though.


Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - Max_Andolini - 02.06.2015

How to write unknown command error?


Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - [KHK]Khalid - 02.06.2015

http://github.com/Misiur/YSI-Includes/issues/18


Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - RaeF - 03.06.2015

Quote:
Originally Posted by eco1999
View Post
How to write unknown command error?
in YSI 3.0 :
PHP Code:
public OnPlayerCommandPerformed(playeridcmdtext[], success)
{
    if (!
success// You can also write it as if (success == 0)
    
{
        
// Your code here 
    
}
    return 
1;

in YSI 4.0 or newer:
PHP Code:
/*
        Error & Return type
    COMMAND_ZERO_RET      = 0 , // The command returned 0.
    COMMAND_OK            = 1 , // Called corectly.
    COMMAND_UNDEFINED     = 2 , // Command doesn't exist.
    COMMAND_DENIED        = 3 , // Can't use the command.
    COMMAND_HIDDEN        = 4 , // Can't use the command don't let them know it exists.
    COMMAND_NO_PLAYER     = 6 , // Used by a player who shouldn't exist.
    COMMAND_DISABLED      = 7 , // All commands are disabled for this player.
    COMMAND_BAD_PREFIX    = 8 , // Used "/" instead of "#", or something similar.
    COMMAND_INVALID_INPUT = 10, // Didn't type "/something".
*/
public e_COMMAND_ERRORS:OnPlayerCommandPerformed(playeridcmdtext[], e_COMMAND_ERRORS:success)
{
    switch (
success)
    {
        case 
COMMAND_UNDEFINED:
        {
             
// Your code here.
        
}
    }
    return 
COMMAND_OK;




Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - Max_Andolini - 03.06.2015

Quote:
Originally Posted by RaeF
View Post
in YSI 3.0 :
PHP Code:
public OnPlayerCommandPerformed(playeridcmdtext[], success)
{
    if (!
success// You can also write it as if (success == 0)
    
{
        
// Your code here 
    
}
    return 
1;

in YSI 4.0 or newer:
PHP Code:
/*
        Error & Return type
    COMMAND_ZERO_RET      = 0 , // The command returned 0.
    COMMAND_OK            = 1 , // Called corectly.
    COMMAND_UNDEFINED     = 2 , // Command doesn't exist.
    COMMAND_DENIED        = 3 , // Can't use the command.
    COMMAND_HIDDEN        = 4 , // Can't use the command don't let them know it exists.
    COMMAND_NO_PLAYER     = 6 , // Used by a player who shouldn't exist.
    COMMAND_DISABLED      = 7 , // All commands are disabled for this player.
    COMMAND_BAD_PREFIX    = 8 , // Used "/" instead of "#", or something similar.
    COMMAND_INVALID_INPUT = 10, // Didn't type "/something".
*/
public e_COMMAND_ERRORS:OnPlayerCommandPerformed(playeridcmdtext[], e_COMMAND_ERRORS:success)
{
    switch (
success)
    {
        case 
COMMAND_UNDEFINED:
        {
             
// Your code here.
        
}
    }
    return 
COMMAND_OK;

It didn't work. I'm using YSI 4.0.

Code:
public e_COMMAND_ERRORS:OnPlayerCommandPerformed(playerid, cmdtext[], e_COMMAND_ERRORS:success)
{
    switch (success)
    {
        case COMMAND_UNDEFINED:
        {
            SendErrorMessage(playerid, "Bu komut mevcut değil. Komut listesini gцrmek iзin /yardim yazın.");
        }
    }
    return COMMAND_OK;
}



Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - RaeF - 03.06.2015

Ohh sorry, change OnPlayerCommandPerformed to OnPlayerCommandReceived, i dont know what make it different, but it should work.


Quote:
Originally Posted by eco1999
View Post
It didn't work. I'm using YSI 4.0.

Code:
public e_COMMAND_ERRORS:OnPlayerCommandPerformed(playerid, cmdtext[], e_COMMAND_ERRORS:success)
{
    switch (success)
    {
        case COMMAND_UNDEFINED:
        {
            SendErrorMessage(playerid, "Bu komut mevcut değil. Komut listesini gцrmek iзin /yardim yazın.");
        }
    }
    return COMMAND_OK;
}



Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - justice96 - 27.07.2015

Hmm.. I decided to use YCMD in my server as a cmd processor. but, it doesn't show anything. I made a cmd like '/shop'


Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - Crayder - 27.07.2015

Quote:
Originally Posted by justice96
Посмотреть сообщение
Hmm.. I decided to use YCMD in my server as a cmd processor. but, it doesn't show anything. I made a cmd like '/shop'
You should probably show us.


Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - JaydenJason - 27.07.2015

How does the help parameter work? Does that show up if isnull(params)?


Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - justice96 - 27.07.2015

Quote:
Originally Posted by Crayder
Посмотреть сообщение
You should probably show us.
Код:
#include <YSI/y_commands>

YCMD:shop(playerid,params[],help)
{
    new listtext[512],substr[40];
	if(help)
	{
	    SEM(playerid,"CMDINFO: Displays shop to buy special weapons!");
	    return 1;
	}
	forex(i, 13)
	{
	    if(PlayerInfo[playerid][WeaponsPurchased][i])
	    {
	        format(substr,sizeof(substr),"%s - {33AA33}PURCHASED\n",GunNames[SelledGun[i][Weaponid]]);
	    }
	    else
	    {
            format(substr,sizeof(substr),"%s - $%d\n",GunNames[SelledGun[i][Weaponid]],SelledGun[i][Price]);
	    }
	    strcat(listtext,substr,sizeof(listtext));
	}
	ShowPlayerDialog(playerid,DIALOG_BUY_GUN,DIALOG_STYLE_LIST,"Guns Shop",listtext,"Buy","Exit");
	return 1;
}



Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - RaeF - 27.07.2015

Try debug your code maybe like this:
Код:
YCMD:shop(playerid,params[],help)
{
    sendclientmessage(playerid, -1, "Command Called");
    new listtext[512],substr[40];
	if(help)
	{
            sendclientmessage(playerid, -1, "Help Called");
	    SEM(playerid,"CMDINFO: Displays shop to buy special weapons!");
	    return 1;
	}
	forex(i, 13)
	{
	    if(PlayerInfo[playerid][WeaponsPurchased][i])
	    {
	        format(substr,sizeof(substr),"%s - {33AA33}PURCHASED\n",GunNames[SelledGun[i][Weaponid]]);
	    }
	    else
	    {
            format(substr,sizeof(substr),"%s - $%d\n",GunNames[SelledGun[i][Weaponid]],SelledGun[i][Price]);
	    }
	    strcat(listtext,substr,sizeof(listtext));
	}
	ShowPlayerDialog(playerid,DIALOG_BUY_GUN,DIALOG_STYLE_LIST,"Guns Shop",listtext,"Buy","Exit");
	return 1;
}
If you don't get the message, that's the real y_commands problem, do you use OnPlayerCommandPerfomed or OnPlayerCommandReceived??


Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - justice96 - 27.07.2015

Quote:
Originally Posted by RaeF
Посмотреть сообщение
Try debug your code maybe like this:
Код:
YCMD:shop(playerid,params[],help)
{
    sendclientmessage(playerid, -1, "Command Called");
    new listtext[512],substr[40];
	if(help)
	{
            sendclientmessage(playerid, -1, "Help Called");
	    SEM(playerid,"CMDINFO: Displays shop to buy special weapons!");
	    return 1;
	}
	forex(i, 13)
	{
	    if(PlayerInfo[playerid][WeaponsPurchased][i])
	    {
	        format(substr,sizeof(substr),"%s - {33AA33}PURCHASED\n",GunNames[SelledGun[i][Weaponid]]);
	    }
	    else
	    {
            format(substr,sizeof(substr),"%s - $%d\n",GunNames[SelledGun[i][Weaponid]],SelledGun[i][Price]);
	    }
	    strcat(listtext,substr,sizeof(listtext));
	}
	ShowPlayerDialog(playerid,DIALOG_BUY_GUN,DIALOG_STYLE_LIST,"Guns Shop",listtext,"Buy","Exit");
	return 1;
}
If you don't get the message, that's the real y_commands problem, do you use OnPlayerCommandPerfomed or OnPlayerCommandReceived??
Debugged.
Код:
YCMD:testme(playerid, params[], help)
{
    #pragma unused params, help
    SendClientMessage(playerid, -1, "/testme command works");
    return 1;
}
Still the same. I ain't get the message. but, I haven't added OnPlayerCommandPerformed or OnPlayerCommandReceived in my script


Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - Crayder - 27.07.2015

Quote:
Originally Posted by JaydenJason
Посмотреть сообщение
How does the help parameter work? Does that show up if isnull(params)?
The help parameter is like an alternate version of the command.

To use it, do something like this:
pawn Код:
YCMD:help(playerid, params[], help)
{
    if(help)
        return SendClientMessage(playerid, -1, "This is the help command, use it to get extra information on commands.");
   
    if(strlen(params))
        Command_ReProcess(playerid, params, true);
    else
        SendClientMessage(playerid, -1, "Error [SYNTAX]: /help <Command Name>");
   
    return 1;
}



Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - Kruzz - 02.12.2015

Is there any way to return commands like in ZCMD?

I mean this:
Код:
CMD:command(playerid, params[])
{
	return cmd_anothercommand(playerid, params);
}
Will Command_ReProcess make the job?


Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - Crayder - 02.12.2015

Quote:
Originally Posted by Kruzz
Посмотреть сообщение
Is there any way to return commands like in ZCMD?

I mean this:
Код:
CMD:command(playerid, params[])
{
	return cmd_anothercommand(playerid, params);
}
Will Command_ReProcess make the job?
Yes, but not on it's own. Also it's better to let YCMD do that itself. The alternative is to do this:
pawn Код:
#define CallCommand(%0,%1) CallLocalFunction("OnPlayerCommandText","is",%0,%1)

#define Y_COMMANDS_NO_IPC
#include <YSI\y_commands>
No it's not the best, and if you don't know what IPC is then you SHOULD look at the source of YCMD (mainly the impl.inc for it). It will work. To use it just do this:
pawn Код:
/*Your Code (and yes YCMD can handle ZCMD syntax):
CMD:command(playerid, params[])
{
    return CallCommand(playerid, params);
}
My Code:*/

CMD:fakecmd(playerid, params[])
{
    new cmd_and_params[136], targetplayer;
    sscanf(params, "us[136]", targetplayer, cmd_and_params);
    return CallCommand(targetplayer, cmd_and_params);
}



Respuesta: Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - Zume - 02.12.2015

Quote:
Originally Posted by Kruzz
Посмотреть сообщение
Is there any way to return commands like in ZCMD?

I mean this:
Код:
CMD:command(playerid, params[])
{
	return cmd_anothercommand(playerid, params);
}
Will Command_ReProcess make the job?
PHP код:
Command_AddAltNamed("command""anothercommand"); 



Re: Respuesta: Re: y_commands - Most flexible and fastest command processor, now on the YSI wiki - Crayder - 03.12.2015

Quote:
Originally Posted by _Zume
Посмотреть сообщение
PHP код:
Command_AddAltNamed("command""anothercommand"); 
Yes there is definitely this. My answer was for anything that alternative names doesn't apply to. Like calling the commands from something remote.