20.11.2011, 05:16
(
Last edited by Tee; 22/11/2011 at 12:05 AM.
)
Clan Tag Checker
- IntroductionI 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
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;
}
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;
}
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;
}
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.