SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 06/08/2019, 12:55 PM   #1
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,066
Reputation: 50
Default Command Tags, Search, Usages and More

Introduction
This include will help you create command tags, definitions, usages, types and so on..
It's a fully dynamic and changeable.
Include needs BlueG's plugin MySQL R40 version or higher.
It's automatically creates table in database.

What you have to do before start:
• open include file and change database settings (prefix C_MySQL), you can also use your current connection handler, just replace C_Connection with your current handler.
• you can also change table name which is defined as C_Table_Name.


Functions
+ AddCommand(cmdname[],cmddefinition[],cmdusage[],cmdtype[]) adds a command in a base, returns true if added, returns false if command already exists. (prevents from re-posting)
+ AddCommandTag(cmdname[],tag[]) adds tag to a command, returns true if added, returns false if tag already exists. (prevents from re-posting)
- DeleteCommand(cmdname[]) removes command from base, returns nothing.
- DeleteCommandTag(cmdname[],tag[]) removes tag from a command, returns nothing.
→ ChangeCommandName(cmdname[], newname[]) changes command's name, returns nothing.
→ ChangeCommandDefinition(cmdname[], newdef[]) changes command's definition, returns nothing.
→ ChangeCommandType(cmdname[], newtype[]) changes command's type, returns nothing.
→ ChangeCommandUsage(cmdname[], newusage[]) changes commands usage, returns nothing.
• GetCommandDefinition(cmdname[]) gets commands definition, returns always string
• GetCommandType(cmdname[]) gets commands type, returns always string
• GetCommandUsage(cmdname[]) gets commands usage, returns always string.
• GetCommandTags(cmdname[]) gets commands tags, returns string.
• GetCommandsByType(type[]) gets the commands by its type, returns always string.
• GetCommandByTag(tag[]) gets only one command by that tag, returns always string.
• GetCommandsByTag(tag[]) gets commands by that tag, always returns string, separator will be ",".
• GetIndexedCommandByTag(index, tag[]) gets command by index and tag, returns string.
• GetIndexedCommandByType(index, type[]) gets command by index and type, returns string.
► CountCommandsByTag(tag[]) gets a number of rows with that command tag, returns integer (useful with GetIndexedCommandByTag)
► CountCommandsByType(type[]) gets a number of rows with that command type, returns integer (useful with GetIndexedCommandByType)

Example usages
You can create a commands to manually add or remove commands, add or remove tags for commands, change types, usages, definitions or command name itself.

or, you can simply register all of the commands by using them, just like Example 1.
Example 1:
PHP Code:
public OnPlayerCommandText(playeridcmdtext[])
{
    if(!
strcmp(cmdtext"/help"true))
    {
        
//AddCommand("cmdname","cmddefinition","cmdusage","cmdtype");
        
AddCommand("/help","shows help message.","/help","General");
        
//AddCommandTag("cmdname","cmdtag");
        
AddCommandTag("/help","General");
        
SendClientMessage(playerid, -1"SERVER: This is the /help command!");
        return 
1;
    }
    if(!
strcmp(cmdtext"/showgeneral"true))
    {
        
SendClientMessage(playerid,-1,GetCommandByTag("General")); //this will show "/help"
    
}
    return 
0;

Example 2:
PHP Code:
public OnPlayerCommandText(playeridcmdtext[])
{
    if(!
strcmp(cmdtext"/allcommands"true))
    {
        
SendClientMessage(playerid, -1GetCommandsByTag("all")); //by default, when adding a command by AddCommand, its automatically adds tag "all", so by this function, you'll get all of the commands which is added in a base.
        
return 1;
    }
    if(!
strcmp(cmdtext"/leadercommands"true))
    {
        
SendClientMessage(playerid, -1GetCommandsByTag("leader")); //this will show all commands which have a tag "leader"
        
return 1;
    }
    if(!
strcmp(cmdtext"/factioncommands"true))
    {
        
SendClientMessage(playerid,-1,GetCommandsByType("Faction")); //this will show all commands which have type "Faction"
    
}
    return 
0;

if you're using strcmp,sscanf and etc.. you can simply create message function which shows usage of that command.
Example 3:
PHP Code:
stock SendUsageMessage(playeridcommand[])
{
    new 
str[256];
    
format(str,sizeof(str),"USAGE:{33CCFF} %s"GetCommandUsage(command));
    
SendClientMessage(playerid,-1,str);

Using Indexed functions.
Example 4:
PHP Code:
new list[512],tag[18];
tag "all";
for(new 
iCountCommandsByTag(tag); i++)
{
    new 
command[32];
    
format(command,sizeof(command),"%s",GetIndexedCommandByTag(i,tag));
    
format(list,sizeof(list),"%s\nCommand: %s | Definition: %s | Usage: %s | Type: %s | Tags: %s",list,command,GetCommandDefinition(command),GetCommandUsage(command),GetCommandType(command),GetCommandTags(command));
}
new 
caption[64];
format(caption,sizeof(caption),"Commands by tag:{33CCFF} %s",tag);
ShowPlayerDialog(playerid1DIALOG_STYLE_LISTcaption, list, "Close"""); 
Include - commands.inc - https://pastebin.com/HQepzgLJ

EDIT: Updated to v2, changelog here - https://forum.sa-mp.com/showpost.php...82&postcount=8
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.

Last edited by Mugala; 11/08/2019 at 05:46 PM.
Mugala is online now   Reply With Quote
Old 06/08/2019, 02:24 PM   #2
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 662
Reputation: 96
Default Re: Command Tags, Search, Usages and More

Is it not extra work to add commands to both script and database or forget to delete a command from database?

In GetCommandsByTag and GetCommandsByType functions, there is a mistake:
pawn Code:
for(new i = 1; i < rows; i++)
rows start from index 0.

As for the table structure, there are no indexes at all. It will scan full table in every search.

Since there can be multiple tags for a command, another table is necessary so you can get rid of LIKE with wildcard at the beginning and sort tags the way you want.
Calisthenics is offline   Reply With Quote
Old 06/08/2019, 02:31 PM   #3
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,066
Reputation: 50
Default Re: Command Tags, Search, Usages and More

Quote:
Originally Posted by Calisthenics View Post
Is it not extra work to add commands to both script and database or forget to delete a command from database?

In GetCommandsByTag and GetCommandsByType functions, there is a mistake:
pawn Code:
for(new i = 1; i < rows; i++)
rows start from index 0.

As for the table structure, there are no indexes at all. It will scan full table in every search.

Since there can be multiple tags for a command, another table is necessary so you can get rid of LIKE with wildcard at the beginning and sort tags the way you want.
1) Yes, there was a mistake, I know it's starting from 0, was testing some stuff, just forgot to replace it by 0 again.
btw, updated.

2) what you mean? it's not necessary to search by index, it must have to scan full table by one column, I'll add DISTINCT for some functions, so it'll be a better choice for me.

3) I thought that, but than realized that it'll be a less in a size, also does the same.
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is online now   Reply With Quote
Old 06/08/2019, 02:46 PM   #4
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 662
Reputation: 96
Default Re: Command Tags, Search, Usages and More

Quote:
Originally Posted by Mugala View Post
2) what you mean? it's not necessary to search by index, it must have to scan full table by one column, I'll add DISTINCT for some functions, so it'll be a better choice for me.

3) I thought that, but than realized that it'll be a less in a size, also does the same.
MySQL is all about good structure, correct indexes and a good execution plan. It's a rule of thumb to avoid full table scans when possible and that's what indexes are for.

If there are 100 rows and 1 of them is the command "/help", do you want to scan only 1 row (using index) or 100 rows (full table scan)?

You do not group by anything so DISTINCT is meaningless.

Size does not matter and it does not do the same thing. I would prefer alphabetical order than random. Users can separate the tags with any delimiter and if they want to display the tags with different colors? Will they have to use sscanf to split and an array to store when another table will return just a few rows to get the job done.
Calisthenics is offline   Reply With Quote
Old 06/08/2019, 02:49 PM   #5
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,066
Reputation: 50
Default Re: Command Tags, Search, Usages and More

Actually, size matters for some of the users, yes, MySQL is a good structure, grouping in this code is pointless, what you suggest? ordering takes time too, so as checking all rows.
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is online now   Reply With Quote
Old 06/08/2019, 03:07 PM   #6
Variable™
Gangsta
 
Join Date: Jul 2015
Posts: 802
Reputation: 175
Default Re: Command Tags, Search, Usages and More

Pawn.CMD does the same work in a friendlier way.
__________________
Discord | Website
Variable™ is offline   Reply With Quote
Old 06/08/2019, 05:28 PM   #7
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,066
Reputation: 50
Default Re: Command Tags, Search, Usages and More

Quote:
Originally Posted by Variable™ View Post
Pawn.CMD does the same work in a friendlier way.
it's not a command emulator, also
can you show commands in your webpage with only Pawn.CMD?
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is online now   Reply With Quote
Old 08/08/2019, 09:34 AM   #8
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,066
Reputation: 50
Default Update to v2

Okay, updated to v2.

Added functions:
GetCommandTags(cmdname[]) gets commands tags, returns string.
GetIndexedCommandByTag(index, tag[]) gets command by index and tag, returns string.
GetIndexedCommandByType(index, type[]) gets command by index and type, returns string.
CountCommandsByTag(tag[]) gets a number of rows with that command tag, returns integer (useful with GetIndexedCommandByTag)
CountCommandsByType(type[]) gets a number of rows with that command type, returns integer (useful with GetIndexedCommandByType)

Example 4:
PHP Code:
new list[512],tag[18];
tag "all";
for(new 
iCountCommandsByTag(tag); i++)
{
    new 
command[32];
    
format(command,sizeof(command),"%s",GetIndexedCommandByTag(i,tag));
    
format(list,sizeof(list),"%s\nCommand: %s | Definition: %s | Usage: %s | Type: %s | Tags: %s",list,command,GetCommandDefinition(command),GetCommandUsage(command),GetCommandType(command),GetCommandTags(command));
}
new 
caption[64];
format(caption,sizeof(caption),"Commands by tag:{33CCFF} %s",tag);
ShowPlayerDialog(playerid1DIALOG_STYLE_LISTcaption, list, "Close"""); 
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.

Last edited by Mugala; 08/08/2019 at 10:06 AM.
Mugala is online now   Reply With Quote
Old 08/08/2019, 01:46 PM   #9
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 662
Reputation: 96
Default Re: Command Tags, Search, Usages and More

Quote:
Originally Posted by Mugala View Post
Actually, size matters for some of the users, yes
It's not only about size. Repeating groups are against 1NF which means there is no normalization in the database design.

Quote:
Originally Posted by Mugala View Post
ordering takes time too, so as checking all rows.
Filesort is applied nearly at the end so scanning 10 rows and ordering 10 rows is in no way similar to scanning 100+ rows.

I am only trying to give tips for improvement as most of the people that use MySQL for samp servers only know how to use simple DDL/DML/DQL statements. Indexes are one of the most important things and you clearly misunderstood my post according to update v2.

https://dev.mysql.com/doc/refman/8.0...l-indexes.html
Calisthenics is offline   Reply With Quote
Old 08/08/2019, 02:12 PM   #10
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,066
Reputation: 50
Default Re: Command Tags, Search, Usages and More

But in this case I need a full table scan to retrieve every command which have a given tag.
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is online now   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
Please, how to make one command with two usages? Using ycmd sscanf2 Riwerry Scripting Help 3 29/12/2013 10:33 AM
How to log command usages Tamer Scripting Help 7 06/01/2013 11:11 AM
[Tutorial] Dialogs Usages Hoss Tutorials 14 09/05/2012 05:37 PM
[Tutorial] Usages for OnPlayerClickPlayer Hiddos Tutorials 10 20/06/2011 03:35 PM
[FilterScript] Sistema de Tags | Proibir Tags Fakes ipsBruno Lançamentos/Releases 10 19/10/2010 10:01 PM


All times are GMT. The time now is 07:55 PM.


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