[Tutorial] Clan Tag Checker - MySQL
#1

Introduction

Basically this was supposed to be a Filterscript but as everyone has their own defines, it'd be pain editing. This tutorial openly explains how to make a clan checker system which checks if there's a player with server tag name on without authorization, if so, server will kick him out. After that we'll make two commands for for adding and removing from clan. This is a MySQL tutorial so your saving system should be in MySQL.

I'll thank Jeff for fixing the issue with checking if the player has it's tag on. Thanks

Jumping into the code!

1. We want to say that if player connects, server will look through the player data and check if player is a clan member, if so server will continue, but if not, server will kick him/her out.

- Using the public OnPlayerConnect
pawn Код:
public OnPlayerConnect(playerid)
{
   return 1;
}
- Checking if player has the name tag on. In my case the tag is [TM]

pawn Код:
if(!strcmp(pName(playerid),"[Tm]",false,4)) // Thanks Jeff for solving this.
{

}
- Quering the clanmember field and checking if it's 1 (which means he/she's a clan member)

pawn Код:
if(!strcmp(pName(playerid),"[Tm]",false,4))
{
    format ( query , sizeof ( query ) , " SELECT `clanmember` FROM `users` WHERE `username` = '%s' " , pName ( playerid ) );
    mysql_query( query ); // Quering the above query.
    mysql_store_result(); // Store the result of the above query
    new clanmember = 0; // Define a new variable 'clanmember'
    if(mysql_num_rows())
    {
         clanmember = mysql_fetch_int(); // Set clan member variable equal to the result of the query.
    }
    if(clanmember != 1) return KickWithMessage(playerid,"You're not in clan, remove your clan tag."); // If clanmember does not equal to one ( if player is not a clan member, kick him with a message.
    mysql_free_result(); // Free the stored result.
}
Combined OnPlayerConnect

pawn Код:
public OnPlayerConnect(playerid)
{
   if(!strcmp(pName(playerid),"[Tm]",false,4))
  {
       format(query,sizeof(query),"SELECT `clanmember` FROM `users` WHERE `username` = '%s'",pName(playerid));
       mysql_query(query);
       mysql_store_result();
       new clanmember = 0;
    if(mysql_num_rows())
    {
        clanmember = mysql_fetch_int();
    }
        if(clanmember != 1) return KickWithMessage(playerid,"You're not in clan, remove your clan tag.");
        mysql_free_result();
  }
  return 1;
}
2. Now that we've done checking if player has the clanmember, let him/her in but if he is not a clanmember, kick him out. Lets create /setclanmember and /deleteclanmember.

pawn Код:
CMD:setclanmember(playerid,params[]) // I am using ZCMD.
{
   return 1;
}
- Basic checks and then updating users clanmember field to on so that he becomes a clan member. There is nothing really complicated in the commands part.
pawn Код:
CMD:setclanmember(playerid,params[])
{
    new pID;
    if(pInfo[playerid][AdminLevel] <= 2) return 0; // Change it to your admin level check
    if(sscanf(params,"u",pID)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /setcmem [playerid]");
    if(!IsPlayerConnected(pID)) return SendClientMessage(playerid,COLOR_GREY,"Player is not connected.");
    if(pInfo[pID][ClanMember] == 1) return SendClientMessage(playerid,COLOR_GREY,"Player is already a clan member."); //What I did is I made ClanMember an enum and when player logs in, it saves the clanmember value to this variable so it's handy to check.
    format(query,sizeof(query),"UPDATE `users` SET `clanmember` = '1' WHERE `username` = '%s'",pName(pID));
    mysql_query(query); // update query
    pInfo[pID][ClanMember] = 1;
    format(string,sizeof(string),"You've successfully made %s a clan member.",pName(pID));
    SendClientMessage(playerid,COLOR_YELLOW,string);
    SendClientMessage(pID,COLOR_GREEN,"You're now a Clan Member. Congratulations!");
    GameTextForPlayer(pID,"~g~Clan Member",1000,1);
    return 1;
}
- Same stuff for the /deleteclanmember but opposite.

pawn Код:
CMD:deleteclanmember(playerid,params[])
{
    new pID;
    if(pInfo[playerid][AdminLevel] <= 2) return 0;
    if(sscanf(params,"u",pID)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /dcmemb [playerid]");
    if(!IsPlayerConnected(pID)) return SendClientMessage(playerid,COLOR_GREY,"Player is not connected.");
    if(pInfo[playerid][ClanMember] == 0) return SendClientMessage(playerid,COLOR_GREY,"That player is not a clan member.");
    format(query,sizeof(query),"UPDATE `users` SET `clanmember` = '0' WHERE `username` = '%s'",pName(pID));
    mysql_query(query);
    pInfo[pID][ClanMember] = 0;
    format(string,sizeof(string),"You've successfully kicked %s out of the clan.",pName(pID));
    SendClientMessage(playerid,COLOR_YELLOW,string);
    SendClientMessage(pID,COLOR_RED,"You've been kicked out of the Clan.");
    GameTextForPlayer(pID,"~r~Kicked!",1000,1);
    return 1;
}
KickWithMessage

You realized why I used KickWithMessage function to kick the player out of the server instead of the simple Kick(playerid) function. The reason why is because the default Kick(playerid) fails at sending the message first before kicking out. So they have made a function that overcomes that issue. KickWithMessage delays for 1 second after sending the message and then kicks the player.

Copy this in the bottom of your script
pawn Код:
forward KickPublic(playerid);
public KickPublic(playerid) Kick(playerid);
 
stock KickWithMessage(playerid, color, message[])
{
    SendClientMessage(playerid, color, message);
    SetTimerEx("KickPublic", 1000, 0, "d", playerid);   //Delay of 1 second before kicking the player so he receives the message
}
Thanks

I thank you for reading through my tutorial! I hope it's helpful for people.
Reply
#2

Very Good!
Reply
#3

1. Whats KickWithMessage. (i know it but a lot of new commers won't know it, its better u explain a bit about it);
Reply
#4

That was so helpful! Thanks!
Reply
#5

Quote:
Originally Posted by newbie scripter
Посмотреть сообщение
1. Whats KickWithMessage. (i know it but a lot of new commers won't know it, its better u explain a bit about it);
I've added a little paragraph explaining about KickWithMessage. Thanks for pointing out.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)