Advertisement
Guest User

OFFICIAL TAG CHECKER

a guest
Nov 23rd, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.38 KB | None | 0 0
  1. #define FILTERSCRIPT
  2.  
  3. #include <a_samp>
  4. #include <sscanf2>
  5. #include <i-zcmd>
  6. #include <a_mysql>
  7.  
  8. enum pData // We are creating a enum.
  9. {
  10.     ID,
  11.     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];
  12. };
  13. new PlayerInfo[MAX_PLAYERS][pData];// I don't think I have to explain that.
  14.  
  15.  
  16. new database;// this is our database variable
  17.  
  18. #define COLOR_ORANGE        0xFF9900AA
  19. #define red                 0xFF0000FF
  20. #define yellow              0xFFFF00AA
  21. #define C_LIME              0x99FF00FF
  22. #define cwhite                  "{FFFFFF}"
  23.  
  24. #define mysql_host ""  // You have to add ur server host or whatever u using to connect
  25. #define mysql_user ""
  26. #define mysql_database ""
  27. #define mysql_password ""
  28.  
  29. public OnFilterScriptInit()
  30. {
  31.     mysql_log(LOG_ERROR | LOG_WARNING); // MySQL Log to show us error if it got.
  32.     database = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
  33.     // Well I am a lazy man. So, I like to create tables from my script.
  34.     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, "", "");
  35.     // So we succesfully create the table
  36.     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.
  37.     {
  38.         printf("[MySQL] The connection has been failed to connect.");
  39.     }
  40.     else
  41.     {
  42.         printf("[MySQL] The connection was been successed to connect.");
  43.     }
  44.  
  45.     return 1;
  46. }
  47.  
  48. public OnFilterScriptExit()
  49. {
  50.     mysql_close(database); // closing the database.
  51.     return 1;
  52. }
  53.  
  54. // Let's start the main function of our clan tag checker
  55.  
  56.  
  57. public OnPlayerConnect(playerid)
  58. {
  59.     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.
  60.     {
  61.         new query[256]; // New query var for query
  62.         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
  63.         mysql_tquery(database,query,"OnOfficialTagDataLoad","i",playerid);// Excuting the query.
  64.     }
  65.     return 1;
  66. }
  67. GetName(playerid) // This is our simple function to GetName.
  68. {
  69.     new pnameid[24];
  70.     GetPlayerName(playerid,pnameid,24);
  71.     return pnameid;
  72. }
  73.  
  74.  
  75. forward public OnOfficialTagDataLoad(playerid); //This is the query which we set on OnPlayerConnect
  76. public OnOfficialTagDataLoad(playerid)
  77. {
  78.     new rows,fields; // creating that var to check rows and fields
  79.     cache_get_data(rows,fields,database); // chaching the data on database.
  80.     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.
  81.     {
  82.         PlayerInfo[playerid][PTag] = cache_get_field_content_int(0,"Allowed");// Allowing the person to join
  83. //      PlayerInfo[playerid][PTag] = 1;
  84.     }
  85.     else
  86.     {
  87.         SendClientMessage(playerid, 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");
  88.         SendClientMessage(playerid, red, "Please logout and join again with a different name that does not consist our [Your OFFICIAL SERVER TAG] Tag");
  89.         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.
  90.     }
  91.     return 1;
  92. }
  93. forward public KickPublic(playerid);
  94. public KickPublic(playerid)// Timer that we call on OnOfficialTagDataLoad
  95. {
  96.     Kick(playerid); // Kicking the player.
  97.     return 1;
  98. }
  99.  
  100. // Now is the time to move on our most important part to set the player official tag
  101. CMD:setofficialtag(playerid, params[])
  102. {
  103.     if(IsPlayerAdmin(playerid)) // Allowing that rcon admin can use that cmd.
  104.     {
  105.         new player1;// var that we gonna use on that cmd.
  106.         if(sscanf(params, "u", player1)) return SendClientMessage(playerid, red, "USAGE: /setofficialtag [playerid]"); //sscanf better then strtok. Fast.
  107.         if(!IsPlayerConnected(player1)) return SendClientMessage(playerid, COLOR_ORANGE, "Target player is not online.");// Checking is that player online or not
  108.         if(PlayerInfo[player1][PTag] != 1) // Checking if that player already got that permission or not.
  109.         {
  110.             new query[256], year,month,day,string[256];// creating query var and other to use in that cmd.
  111.             getdate(year, month, day); //Getting data to save so we can know when we allow that player to use our official tag.
  112.             PlayerInfo[player1][PTag] = 1; // Setting
  113.             format(string, sizeof(string), "%d/%d/%d", day, month, year); // formating that in string.
  114.             mysql_format(database, query, sizeof(query), "INSERT INTO OfficialTag (PLAYERNAME, 1stTagDate, Allowed) VALUES ('%s', '%s', 1)", GetName(player1), string); //inserting on our precious database.
  115.             mysql_tquery(database, query, "OnTagDataCreate", "i", playerid); // creating the database
  116.             format(string, sizeof(string), "Administrator %s has set you an official member of [Your Official SERVER TAG NAME] Community", GetName(playerid));
  117.             SendClientMessage(player1, yellow, string);
  118.             SendClientMessage(player1, 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.
  119.             format(string, sizeof(string), "Administrator %s has set %s as an official member of [Your Official SERVER TAG NAME] Community.", GetName(playerid), GetName(player1));
  120.             mysql_format(database, query, sizeof(query), "UPDATE OfficialTag SET TagLog = '%s' WHERE PLAYERNAME = '%e'", string, GetName(playerid)); // Updating the taglog.
  121.             mysql_tquery(database,query,"","");//query excuted
  122.             SendClientMessage(playerid, C_LIME, "Tag Permission allowed");
  123.         }   else return SendClientMessage(playerid, red, "[ERROR] "cwhite"Player already has the permission to wear the tag.");
  124.     }   else return SendClientMessage(playerid, red, "[ERROR] "cwhite"This command is just for rcon admins");
  125.     return 1;
  126. }
  127.  
  128. forward public OnTagDataCreate(playerid);// That query we use to create on our cmd. to insert data
  129. public OnTagDataCreate(playerid)
  130. {
  131.     PlayerInfo[playerid][ID] = cache_insert_id();// inserting the id
  132.     return 1;
  133. }
  134. CMD:unsetofficialtag(playerid, params[])
  135. {
  136.     if(IsPlayerAdmin(playerid))
  137.     {
  138.         new player1, string[256];
  139.         if(sscanf(params, "u", player1)) return SendClientMessage(playerid, red, "USAGE: /unsetofficialtag [playerid]");
  140.         if(!IsPlayerConnected(player1)) return SendClientMessage(playerid, COLOR_ORANGE, "Target is not online.");
  141.         if(PlayerInfo[player1][PTag] != 0)
  142.         {
  143.             new query[256], year,month,day;
  144.             getdate(year, month, day);
  145.             PlayerInfo[player1][PTag] = 0;
  146.             format(string, sizeof(string), "%d/%d/%d", day, month, year);
  147.             mysql_format(database, query, sizeof(query), "UPDATE OfficialTag SET 1stRevokalDate = '%s' AND Allowed = '0' WHERE Nick = '%e'", string, GetName(playerid));// Updating the query
  148.             mysql_tquery(database,query,"","");// query excuted
  149.             format(string, sizeof(string), "Administrator %s has revoked your permission to wear the official community tag of AwC Gaming Community", GetName(playerid));
  150.             SendClientMessage(player1, C_LIME, string);
  151.             format(string, sizeof(string), "Administrator %s has unsetofficialtag %s as an official member of AWC Gaming Community.", GetName(playerid), GetName(player1));
  152.             mysql_format(database, query, sizeof(query), "UPDATE OfficialTag SET TagLog = '%s' WHERE PLAYERNAME = '%e'", string, GetName(playerid)); // Updating the query
  153.             mysql_tquery(database,query,"","");// query excuted
  154.             SendClientMessage(playerid, C_LIME, "Tag permission taken.");
  155.         }   else return SendClientMessage(playerid, red, "[ERROR] "cwhite"Player already doesn't have permission to wear the server official tag.");
  156.     }   else return SendClientMessage(playerid, red, "[ERROR] "cwhite"This command is just for rcon admins");
  157.     return 1;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement