23.11.2015, 07:28
(
Последний раз редактировалось HydraHumza; 04.12.2015 в 18:48.
)
Hey Friends,
You Must have basic knowledge of MySQL to understand the code.
I am back with my second tutorial on Official Name Tag checker which is got latest saving system MySQL R39-4.
Introduction to this tutorial
This tutorial is based on Official Name Tag Checker can be also used in Clan Tag Name Checker. This tutorial is using latest version of MySQL , SSCANF2 and I-ZCMD you can find links in include. So, this tutorial will teach you how to create an Name Tag Checker. If that find any your official name or your clan tag check will be kicked if he didn't found that name in database. If you want him permission then you have to allow his/her person to use server Official name by using this command /SetOfficialTag to give him permission. If he/she break any rule then you can take the permission back by using this command /UnsetOfficialTag.
How you gonna use that?
First: You have to edit MySQL login to your host server
Second: You Must edit few of the script by your server Official TAG name [Your OFFICIAL SERVER TAG] edit that to your server tag.
So let's start to code.
Ok now let's move to variable side.
So this is our MySQL part which you have to edit that to your database config.
Some colors which we gonna need
We are done to our defining the color , MySQL database stuffs and variables.
This is important part to create the tables and load our MySQL database.
Let's start the main function of our Official tag checker.
Redirecting to the our query.
Now is the time to move on our most important part to set the player official tag
Sorry for indentation it mess. But for proper indentation check the Pastebin link.
Pastebin Link
Thanks to all for reading my thread.
Thanks to Vince for his post on this thread to notifying my mistakes.
Special thanks to my friend jlalt Aka Jalal Amir.Who help me to fix that code and testing the code.
You Must have basic knowledge of MySQL to understand the code.
I am back with my second tutorial on Official Name Tag checker which is got latest saving system MySQL R39-4.
Introduction to this tutorial
This tutorial is based on Official Name Tag Checker can be also used in Clan Tag Name Checker. This tutorial is using latest version of MySQL , SSCANF2 and I-ZCMD you can find links in include. So, this tutorial will teach you how to create an Name Tag Checker. If that find any your official name or your clan tag check will be kicked if he didn't found that name in database. If you want him permission then you have to allow his/her person to use server Official name by using this command /SetOfficialTag to give him permission. If he/she break any rule then you can take the permission back by using this command /UnsetOfficialTag.
How you gonna use that?
First: You have to edit MySQL login to your host server
Second: You Must edit few of the script by your server Official TAG name [Your OFFICIAL SERVER TAG] edit that to your server tag.
So let's start to code.
Код:
#include <a_samp>// Credits to SAMP #include <sscanf2>// Emmet_ #include <i-zcmd> // Yashas and Zeex #include <a_mysql> // BlueG
Код:
enum pData // We are creating a enum. { ID, //Tag ID PTag// We declare a Tag Enum I like enum it easy to use :). So, I do that in enum but u can also do that new Tag[MAX_PLAYERS]; }; new PlayerInfo[MAX_PLAYERS][pData];// I don't think I have to explain that.
Код:
new database;// this is our database variable #define mysql_host "" // You have to add ur server host or whatever u using to connect #define mysql_user "" #define mysql_database "" #define mysql_password ""
Код:
#define C_ORANGE 0xFF9900AA #define C_RED 0xFF0000FF #define C_Yellow 0xFFFF00AA #define C_LIME 0x99FF00FF
This is important part to create the tables and load our MySQL database.
Код:
public OnFilterScriptInit() { mysql_log(LOG_ERROR | LOG_WARNING); // MySQL Log to show us error if it got. database = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password); // Well I am a lazy man. So, I like to create tables from my script. mysql_function_query(database,"CREATE TABLE IF NOT EXISTS OfficialTag(ID int(10) auto_increment PRIMARY KEY, PLAYERNAME varchar(30), 1stTagDate varchar(30) , 1stRevokalDate varchar(30), TagLog varchar(256) , Allowed int(10))", false, "", ""); // So we succesfully create the table if(mysql_errno(database) != 0) // This is checking that our database then it will print in our server.exe file that it connect if didn't connect then it will say that it didn't connect. { printf("[MySQL] The connection has been failed to connect."); } else { printf("[MySQL] The connection was been successed to connect."); } return 1; } public OnFilterScriptExit() { mysql_close(database); // closing the database. return 1; }
Код:
public OnPlayerConnect(playerid) { if(strfind(GetName(playerid), "[UR SERVER OFFICIAL TAG NAME]") != -1) // checking the server tag then it will check to database if it not found then it will kick if it found then he will allow you to join. { new query[256]; // New query var for query mysql_format(database, query, sizeof(query), "SELECT * FROM OfficialTag WHERE PLAYERNAME = '%e'", GetName(playerid));// This is getting table is that playername have permission to have official tag mysql_tquery(database,query,"OnOfficialTagDataLoad","i",playerid);// Excuting the query. } return 1; } GetName(playerid) // This is our simple function to GetName. { new pnameid[24]; GetPlayerName(playerid,pnameid,24); return pnameid; }
Код:
forward public OnOfficialTagDataLoad(playerid); //This is the query which we set on OnPlayerConnect public OnOfficialTagDataLoad(playerid) { new rows,fields; // creating that var to check rows and fields cache_get_data(rows,fields,database); // chaching the data on database. if(rows)// That checking if that row exist then allowed the person if not then kick him or whatever the way u want to punish but if I were your side then I will kick. { PlayerInfo[playerid][PTag] = cache_get_field_content_int(0,"Allowed");// Allowing the person to join } else { SendClientMessage(playerid, C_RED, "You are not an allowed to have an official [Your OFFICIAL SERVER TAG] Tag Holder, you cannot login with the [Your OFFICIAL SERVER TAG] Tag"); SendClientMessage(playerid, C_RED, "Please logout and join again with a different name that does not consist our [Your OFFICIAL SERVER TAG] Tag"); SetTimerEx("KickPublic", 200, false, "i", playerid); // We are setting the timer that player able to get that message otherwise it didn't send message to player. } return 1; } forward public KickPublic(playerid); public KickPublic(playerid)// Timer that we call on OnOfficialTagDataLoad { Kick(playerid); // Kicking the player. return 1; }
Код:
CMD:setofficialtag(playerid, params[]) { if(IsPlayerAdmin(playerid)) // Allowing that rcon admin can use that cmd. { new player1;// var that we gonna use on that cmd. if(sscanf(params, "u", player1)) return SendClientMessage(playerid, C_RED, "USAGE: /setofficialtag [playerid]"); //sscanf better then strtok. Fast. if(!IsPlayerConnected(player1)) return SendClientMessage(playerid, C_ORANGE, "Target player is not online.");// Checking is that player online or not if(PlayerInfo[player1][PTag] != 1) // Checking if that player already got that permission or not. { new query[256], year,month,day,string[256];// creating query var and other to use in that cmd. getdate(year, month, day); //Getting data to save so we can know when we allow that player to use our official tag. PlayerInfo[player1][PTag] = 1; // Setting format(string, sizeof(string), "%d/%d/%d", day, month, year); // formating that in string. mysql_format(database, query, sizeof(query), "INSERT INTO OfficialTag (PLAYERNAME, 1stTagDate, Allowed) VALUES ('%s', '%s', 1)", GetName(player1), string); //inserting on our precious database. mysql_tquery(database, query, "OnTagDataCreate", "i", playerid); // creating the database format(string, sizeof(string), "Administrator %s has set you an official member of [Your Official SERVER TAG NAME] Community", GetName(playerid)); SendClientMessage(player1, C_Yellow, string); SendClientMessage(player1, C_Yellow, "You can now wear the Official [Your Official SERVER TAG NAME] Tag in your name, ask any person to change ur nick");//Well we can set his name by using SetPlayerName but I don't like that way. format(string, sizeof(string), "Administrator %s has set %s as an official member of [Your Official SERVER TAG NAME] Community.", GetName(playerid), GetName(player1)); mysql_format(database, query, sizeof(query), "UPDATE OfficialTag SET TagLog = '%s' WHERE PLAYERNAME = '%e'", string, GetName(player1)); // Updating the taglog. mysql_tquery(database,query,"","");//query excuted SendClientMessage(playerid, C_LIME, "Tag Permission allowed"); } else return SendClientMessage(playerid, C_RED, "[ERROR] {FFFFFF}Player already has the permission to wear the tag."); } else return SendClientMessage(playerid, C_RED, "[ERROR] {FFFFFF}This command is just for rcon admins"); return 1; } forward public OnTagDataCreate(playerid);// That query we use to create on our cmd. to insert data public OnTagDataCreate(playerid) { PlayerInfo[playerid][ID] = cache_insert_id();// inserting the id return 1; } CMD:unsetofficialtag(playerid, params[]) { if(IsPlayerAdmin(playerid)) { new player1, string[256]; if(sscanf(params, "u", player1)) return SendClientMessage(playerid, C_RED, "USAGE: /unsetofficialtag [playerid]"); if(!IsPlayerConnected(player1)) return SendClientMessage(playerid, C_ORANGE, "Target is not online."); if(PlayerInfo[player1][PTag] != 0) { new query[256], year,month,day; getdate(year, month, day); PlayerInfo[player1][PTag] = 0; format(string, sizeof(string), "%d/%d/%d", day, month, year); mysql_format(database, query, sizeof(query), "UPDATE OfficialTag SET 1stRevokalDate = '%s' AND Allowed = '0' WHERE Nick = '%e'", string, GetName(player1));// Updating the query mysql_tquery(database,query,"","");// query excuted format(string, sizeof(string), "Administrator %s has revoked your permission to wear the official community tag of AwC Gaming Community", GetName(playerid)); SendClientMessage(player1, C_LIME, string); format(string, sizeof(string), "Administrator %s has unsetofficialtag %s as an official member of AWC Gaming Community.", GetName(playerid), GetName(player1)); mysql_format(database, query, sizeof(query), "UPDATE OfficialTag SET TagLog = '%s' WHERE PLAYERNAME = '%e'", string, GetName(player1)); // Updating the query mysql_tquery(database,query,"","");// query excuted SendClientMessage(playerid, C_LIME, "Tag permission taken."); } else return SendClientMessage(playerid, C_RED, "[ERROR] {FFFFFF}Player already doesn't have permission to wear the server official tag."); } else return SendClientMessage(playerid, C_RED, "[ERROR] {FFFFFF}This command is just for rcon admins"); return 1; }
Pastebin Link
Thanks to all for reading my thread.
Thanks to Vince for his post on this thread to notifying my mistakes.
Special thanks to my friend jlalt Aka Jalal Amir.Who help me to fix that code and testing the code.