[Tutorial] How to make a Clan Tag Checker [MySQL | ZCMD | sscanf]
#1

Clan Tag Checker
- Introduction

I made this like 1 month ago and it's worked effectively so I decided to share it. This tutorial will show you how to make a simple "Clan Checker". What it does is looks for your clan tag, in a player's name, and if they're not in the clan, it will kick them from the server. This can prevent unwanted or random people connecting to the server, with the clan's tag.



- Commands

We'll also be making some commands for ingame use, namely:
  • /setclanmember
  • /removeclanmember
- Setting up

First you need to create a table in your database named "clanmembers" or whatever you want, it will store the names of the clan members. This table will have one field, named "Name".
You'll also need the sscanf and zcmd includes, click links below to download them.

ZCMD Download
sscanf Download

- The Code

This is where all the work is concentrated. Let's get started!

OnPlayerConnect:

pawn Code:
new String[128];//Declaring the string.

public OnPlayerConnect(playerid)
{
    GetPlayerName(playerid,namevar,24);//Make sure you already defined the variable that stores the player's name.
    if(strfind(namevar,"The clan tag will go here: example '[mG]' ",true) != -1)//Change to the your clan tag.
    {
        format(String,76,"SELECT Name FROM clanmembers WHERE Name='%s' LIMIT 1",escapename);//Selecting the Name field from the "clanmembers" table.
        mysql_query(String);
        mysql_store_result();//Storing the result.
        if(mysql_num_rows() != 0)//If the name was found in the table, then we can give the player a warm welcome.
        {
            mysql_free_result();//Remember to free the result, or you'll get lag issues.
            SendClientMessage(playerid,-1,"Nice, you're in the clan.");//Warm welcome :)
        }
        if(mysql_num_rows() == 0)//Now, if the player's name was not found in the clan table, then take the following actions:
        {
            mysql_free_result();//Free the result.
            format(String,sizeof(String),"%s has been kicked from the server. Reason: Not in clan.",GetName(playerid));
            SendClientMessageToAll(-1,String);
            Kick(playerid);//Kicking the player.
            return 1;
        }
    }
    return 1;
}
Now for the commands that you'll use in game.
The command below will be used to accept the player into the clan.

pawn Code:
COMMAND:setclanmember(playerid, params[])
{
    if(!IsPlayerAdmin(playerid))return 0;//Checking if the player is a RCON admin.
    new id;
    if(sscanf(params,"u",id))return SendClientMessage(playerid,-1,"Usage: /setclanmember [id]");//Using sscanf to check if the params where filled.
    GetPlayerName(id,namevar,24);//Again, getting the player's name, and storing it into the name variable.
    format(String,sizeof(String),"SELECT Name FROM clanmembers WHERE Name='%s' LIMIT 1",namevar);//Selecting the name from the table.
    mysql_query(String);
    mysql_store_result();//Storing the result.
    if(mysql_num_rows() != 0)return (mysql_free_result() && SendClientMessage(playerid,-1,"That player is already in the clan."));//Freeing the result, and making sure you don't add that name again.
    mysql_free_result();//Freeing the result.
    format(String,sizeof(String),"INSERT INTO clanmembers (Name) VALUES ('%s')",namevar);//If the name was not found, then insert it into the table.
    mysql_query(String);
    format(String,sizeof(String),"You've accepted %s into the clan.",namevar);//
    SendClientMessage(playerid,-1,String);
    GetPlayerName(playerid,namevar,24);//Getting your name (user of the command)
    format(String,sizeof(String),"You've been accepted into the clan by admin %s.",namevar);
    SendClientMessage(id,-1,String);
    return 1;
}
The command below will remove the player from the clan.

pawn Code:
COMMAND:removeclanmember(playerid, params[])
{
    if(!IsPlayerAdmin(playerid))return 0;//Checking if the player is a RCON admin.
    if(sscanf(params,"s",params))return SendClientMessage(playerid,-1,"Usage: /removeclanmember [name]");
    format(String,76,"SELECT Name FROM clanmembers WHERE Name='%s' LIMIT 1",params);//Selecting the name from the table.
    mysql_query(String);
    mysql_store_result();//Storing the result.
    if(mysql_num_rows() == 0)return (mysql_free_result() && SendClientMessage(playerid,-1,"That name was not found in the table."));//Freeing the result, and giving an error that the name entered is not in the table.
    mysql_free_result();//Freeing the result.
    format(String,60,"DELETE FROM clanmembers WHERE Name='%s'",params);//If the name was found, then delete it.
    mysql_query(String);
    format(String,100,"You've removed %s from the clan.",params);
    SendClientMessage(playerid,-1,String);
    return 1;
}
- Conclusion

Basically we're finished, if you've done everything correct then the code should work. Thanks for learning .

Note: This does not change the player's name to fit the clan tag, you'll have to implement it into your own name changing system, or however you do it.
Reply
#2

Great tutorial, but you should make a command that does.

/setclanowner - Makes it so that you can set a player a clan owner. (Multiple people)
Reply
#3

Nice one Tee, great way to make a clan training server
Reply
#4

OMFG, that's really great ! Good Job, Tee
Reply
#5

greate, also you can make a chat command for clan members
Reply
#6

Amazing job tee
Reply
#7

Quote:
Originally Posted by Horatio12
View Post
Great tutorial, but you should make a command that does.

/setclanowner - Makes it so that you can set a player a clan owner. (Multiple people)
The command only works if a certain admin level is met, also, the owner of a server will automatically be the clan owner.

Quote:
Originally Posted by System64
View Post
greate, also you can make a chat command for clan members
Thanks, I didn't think of that.
Reply
#8

very nice and great idea , good job! :P
Reply
#9

amazing ill try it
Reply
#10

Quote:

C:\Users\Faqahat\LSSW\Server\gamemodes\LS-SW.pwn(2417) : error 017: undefined symbol "namevar"
C:\Users\Faqahat\LSSW\Server\gamemodes\LS-SW.pwn(241 : error 017: undefined symbol "namevar"
C:\Users\Faqahat\LSSW\Server\gamemodes\LS-SW.pwn(2420) : error 017: undefined symbol "escapename"
C:\Users\Faqahat\LSSW\Server\gamemodes\LS-SW.pwn(2421) : error 017: undefined symbol "mysql_query"
C:\Users\Faqahat\LSSW\Server\gamemodes\LS-SW.pwn(2431) : error 017: undefined symbol "GetName"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


5 Errors.

Any help please?
Reply
#11

Quote:
Originally Posted by Mr.Faqahat
View Post
Any help please?
pawn Code:
new namevar[MAX_PLAYER_NAME];
new escapename[MAX_PLAYER_NAME];
// Replace GetName To GetPlayerName
mysql_query got replaced to mysql_function_query --- Try getting the R6/5 version and it should work
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)