[Include] Sclan.inc - MySQL Clans System
#1

Sclan.inc - MySQL Clans System

by Shinja


First release [29/07/2016]

This [Include] allows you to add clan system to your gamemode easily with very simple functions!

Note: MySQL R39-5 Required! Credits to BlueG

If you can't create table manually, add this under OnGameModeInit();
Replace g_SQL with your MySQL connectionHandle
Код:
mysql_query(g_SQL, "CREATE TABLE IF NOT EXISTS Clans(`ID` int(5) NOT NULL auto_increment PRIMARY KEY, `Name` varchar(50) NOT NULL)");
Natives
Код:
native Shinja_CreateClan(name[], connectionHandle);
native Shinja_DestroyClan(clanid, connectionHandle);
native Shinja_IsClanExists(clanid, connectionHandle);
native Shinja_IsClanNameExists(name[], connectionHandle);
native Shinja_GetClanID(name[], connectionHandle);
native Shinja_GetClanName(clanid, connectionHandle);
native Shinja_GetPlayerClan(playerid, connectionHandle);
native Shinja_SetPlayerClan(playerid, clanid, connectionHandle);
native Shinja_IsPlayerInAnyClan(playerid, connectionHandle);
Example Usage:

PHP код:
CMD:createclan(playeridparams[])
{
    new 
cname[50], string[126];
     if(
sscanf(params"s[50]"cname)) return SendClientMessage(playerid, -1"{0008F7}USAGE: {FFFFFF}/CREATECLAN CLAN_NAME");
    new 
lenght strlen(cname);
    if(
lenght 6) return SendClientMessage(playerid, -1"{FF0000}Clan name must contain atleast 6 Characters");
    if(
IsClanNameExists(cnameg_SQL)) return SendClientMessage(playerid, -1"{FF0000}This clan already exists");
    
CreateClan(cnameg_SQL);
    
SetPlayerClan(playeridGetClanID(cnameg_SQL), g_SQL);
    
format(string126"{00FF1E}You have succesfully created a clan ''{FF0000}%s''"cname);
    
SendClientMessage(playerid, -1string);
    new 
FloatPPos[3];
    
GetPlayerPos(playeridPPos[0], PPos[1], PPos[2]);
    
PlayerPlaySound(playerid1137PPos[0], PPos[1], PPos[2]);
    return 
1;
}
CMD:closeclan(playeridparams[])
{
    new 
string[126];
    if(!
IsPlayerInAnyClan(playeridg_SQL)) return SendClientMessage(playerid, -1"{FF0000}You are not owner of any clan");
    
DestroyClan(pClan[playerid], g_SQL);
    
SetPlayerClan(playerid, -1g_SQL);
    
format(string126"{00FF1E}You have succesfully destroyed your clan clan ''{FF0000}%s''");
    
SendClientMessage(playerid, -1string);
    new 
FloatPPos[3];
    
GetPlayerPos(playeridPPos[0], PPos[1], PPos[2]);
    
PlayerPlaySound(playerid1137PPos[0], PPos[1], PPos[2]);
    return 
1;
}
CMD:c(playeridparams[])
{
    new 
string[250], msg[150];
    if(!
IsPlayerInAnyClan(playeridg_SQL)) return SendClientMessage(playerid, -1"{FF0000}You are not in any clan");
    if(
sscanf(params"s[150]"msg)) return SendClientMessage(playerid, -1"{0008F7}USAGE: {FFFFFF}/C MESSAGE");
    
format(string200"{000000}[{32DBAB}CLAN{000000}.{32DBAB}CHAT{000000}] {00B884}%s(%d){000000}: {9AF5DB}%s"GetName(playerid), playeridmsg);
    
SendToClan(playerid, -1string);
    return 
1;
}
CMD:cinvite(playeridparams[])
{
    new 
string[250],id;
    if(!
IsPlayerInAnyClan(playeridg_SQL)) return SendClientMessage(playerid, -1"{FF0000}You are not in any clan");
    if(
sscanf(params"d"id)) return SendClientMessage(playerid, -1"{0008F7}USAGE: {FFFFFF}/CINVITE ID");
    if(
GetPlayerClan(idg_SQL) != -1) return SendClientMessage(playerid, -1"{FF0000}Player already in a clan");
    
format(string200"{000000}[{32DBAB}CLAN{000000}.{32DBAB}INVITATION{000000}] {00B884}%s(%d) has invited %s(%d) to join the clan"GetName(playerid), playeridGetName(id), id);
    
SendToClan(playerid, -1string);
    
format(string200"{000000}[{32DBAB}CLAN{000000}.{32DBAB}INVITATION{000000}] {00B884}%s(%d) has invited you to join his clan. /cjoin to accept"GetName(playerid), playerid);
    
SendClientMessage(id, -1string);
    
InvitedClan[id] = GetPlayerClan(playeridg_SQL);
    
clan[id] = SetTimerEx("CancelClan"15000false"i"id);
    return 
1;
}
CMD:cjoin(playeridparams[])
{
    new 
string[250];
    if(
InvitedClan[playerid] == -1) return SendClientMessage(playerid, -1"{FF0000}You are not invited to join any clan!");
    
pClan[playerid] = InvitedClan[playerid];
    new 
qufery[100];
    
format(quferysizeof(qufery), "UPDATE Users SET Clan = %d WHERE Name = '%s'"pClan[playerid], GetName(playerid));
    
mysql_query(g_SQLqufery);
    
format(string200"{000000}[{32DBAB}CLAN{000000}.{32DBAB}JOIN{000000}] {00B884}%s(%d) has joined the clan"GetName(playerid), playerid);
    
SendToClan(playerid, -1string);
    
KillTimer(clan[playerid]);
    return 
1;

Download: Sclan.inc

Pastbin

Don't hesitate reporting any bug!
Reply


Messages In This Thread
Sclan.inc - MySQL Clans System - by Shinja - 29.07.2016, 23:56
Re: Sclan.inc - MySQL Clans System - by JustMe.77 - 30.07.2016, 00:37
Re: Sclan.inc - MySQL Clans System - by oMa37 - 30.07.2016, 00:48
Re: Sclan.inc - MySQL Clans System - by Luicy. - 30.07.2016, 01:18
Re: Sclan.inc - MySQL Clans System - by Shinja - 30.07.2016, 01:25
Re: Sclan.inc - MySQL Clans System - by Luicy. - 30.07.2016, 01:32
Re: Sclan.inc - MySQL Clans System - by Shinja - 30.07.2016, 01:47
Re: Sclan.inc - MySQL Clans System - by Gammix - 30.07.2016, 02:55

Forum Jump:


Users browsing this thread: 3 Guest(s)