#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
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; }
Some colors which we gonna need
Код:
#define COLOR_ORANGE 0xFF9900AA #define red 0xFF0000FF #define yellow 0xFFFF00AA #define C_LIME 0x99FF00FF #define cwhite "{FFFFFF}" |
new red, green, blue, alpha; // color parts
This doesn't seem much like a tutorial but rather a complete filterscript. You explain every line but I don't feel that it actually teaches anything, which is kind of the point of a tutorial. In the end it's still mostly copy-paste and the person reading this won't have done or learned anything at all.
Please, if you're going to define colors, be consistent. You either use COLOR_ or C_ or whatever, but be consistent. Rule of thumb for constants is also to write them in ALL_CAPS to distinguish them from regular variables. If you mix and match them like this you're bound to run into trouble. If a user ever decides to do something like: PHP код:
|
You have to clarify what this tutorial helps in, it took me a little bit of time to understand what this does.. Good but keep in mind what Vince said.
|