[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
#2

Looks preatty neat, well done !
Reply
#3

Nice, But you didn't have to add your name in every function. Lol
Reply
#4

It'd be nicer with like S::*function*
#define S:: Shinja_

Anyway, pastebin please. I wont make the same mistake I did with an another guy who posted a .rar link which fucked up my laptop.
Reply
#5

Pastbin added!
Reply
#6

"Do not edit, even bugs"
I'm done.


Quote:

stock GetName(playerid)
{
new szName[MAX_PLAYER_NAME];
GetPlayerName(playerid, szName, sizeof(szName));
return szName;
}

You really had to copy that from a help thread?
https://sampforum.blast.hk/showthread.php?tid=598704

Quote:

#include <a_samp>
#include <a_mysql>

Oh god..
PHP код:
#if !defined _included_a_samp
     #error I think you forgot to include a_samp
#endif
#if !defined _included_a_mysql
     #error I think you forgot to include a_mysql
#endif 
Why would you use native when you're using stock? Doesn't make sense.

Other than that, Why is this an include and not an filterscript? All you do is run mysql queries.
Reply
#7

All i know that it works fine, i don't matter all what you said, i'm wrong buude?
But, thanks for this tho
Quote:
Originally Posted by Meller
Посмотреть сообщение
"Do not edit, even bugs"

PHP код:
#if !defined _included_a_samp
     #error I think you forgot to include a_samp
#endif
#if !defined _included_a_mysql
     #error I think you forgot to include a_mysql
#endif 
Reply
#8

Why non-threaded queries?

I guess you can use mysql_tquery for all the executions except the SELECT ones since the rows get loaded in a callback and things can get complicated, but the rest use threaded.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)