[Include] clan.inc -> Easy-to-use, plug-n-play clan system
#1

CLAN SYSTEM v1.4

UPDATED ON 17.4.2013.



INTRO:
Hello! As you can see, have finished my latest project which is my own clan system! Havent found nor saw any clan systems round here on SAMP forums, so I decided to make one! This clan system has a lots of features! Also, this system is using MySQL plugin for efficient saving and loading! Now, lets start!

__________________________________________________ _______________________________________________

CHANGELOG:
Код:
[15.8.2012. | 21:45 | Version 1.1] Fixed bug involving "GetClanMembers" function which would return just the last member's name -> now should and will return all members' names

[4.10.2012. | 11:40 | Version 1.2] Added "SendMessageToClanMembersEx" - this function doesn't have "playerid" parameter and has "clan" parameter
                                   Added "GetClanWeapon" - this function will return weapon ID from specific slot in certain clan
                                   Added optional parameters named "old_weapX" to "ChangeClanWeapons" - now, you don't have to change all 3 clan weapons if you dont want too, for example you can just simply change 1 or 2 without touching third one
[15.4.2013. | 20:45 | Version 1.3] Fixed problem involving "GetClanWeapon" and "ChangeClanWeapons" usage that would cause bunch of errors in output (no more bugs and errors)

[17.4.2013. | 11:20 | Version 1.4] Added "ChangeClanTag" function - easily change some clan's tag
                                   Added "GetClanTag" function - retrieve tag of specific clan
                                   Added "GetClanPassword" function - get clan's password
                                   Added "UseClanTags" function - enable/disable clan [TAG] showing on playerlist (requires player name change, watch out when using saving systems)
                                   Added "UseClanPasswords" function - player must enter correct password to play in server, if he fails MAX_PASS_FAILS times, he gets kicked
                                   Added "OnPlayerChangeClanTag" callback - called when "ChangeClanTag" is performed
                                   Updated and changed 3 optional values in "ChangeClanWeapons" to just 1 (old_weap for all)
                                   Updated some function's messages with some more color codes
Version 1.4 should be error-free version! If you find any bugs/errors, please post them so I can fix them!

__________________________________________________ _______________________________________________

NATIVES:
Total of 20 custom natives that helps you to properly use this clan system! Here, I am going to show you all natives and examples of using them!

List of the natives:
pawn Код:
native CreateClan(playerid, clan_name[], clan_tag[], clan_pass[], clan_description[], clan_motd[], weap1, weap2, weap3);
native AddPlayerToClan(playerid, addid);
native RemovePlayerFromClan(playerid, removeid);
native LeaveClan(playerid);
native DisbandClan(playerid);
native ChangePlayerClanRank(playerid, giveid, rank);
native ChangeClanMOTD(playerid, new_motd[]);
native ChangeClanDescription(playerid, new_description[]);
native ChangeClanWeapons(playerid, new_weap1 = old_weap, new_weap2 = old_weap, new_weap3 = old_weap);
native ChangeClanPassword(playerid, new_pass[]);
native ChangeClanTag(playerid, new_tag[]);
native IsPlayerAnyClanMember(playerid);
native IsPlayerClanMember(playerid, clan_name[]);
native GetPlayerClan(playerid);
native GetPlayerClanRank(playerid);
native GetClanMOTD(clan[]);
native GetClanDescription(clan[]);
native GetClanMembers(clan[]);
native GetClanWeapon(clan[], weap_slot);
native GetClanTag(clan[]);
native GetClanPassword(clan[]);
native UseClanTags(bool:use = true);
native UseClanPasswords(bool:use = true);
native SendMessageToClanMembers(playerid, color, msg[]);
native SendMessageToClanMembersEx(clan[], color, msg[]);

Now, here is explanation and example usage of each native!


Creating a clan:
pawn Код:
native CreateClan(playerid, clan_name[], clan_tag[], clan_pass[], clan_description[], clan_motd[], weap1, weap2, weap3);

//playerid - for calling function and sending a message
//clan_name[] - name of your clan
//clan_tag[] - tag that will be saved to your clan's stats
//clan_pass[] - password for your clan
//clan_description[] - describe your clan in few words
//clan_motd[] - clan's message of the day
//weap1 - weapon 1 that will be given OnPlayerSpawn
//weap2 - weapon 1 that will be given OnPlayerSpawn
//weap3 - weapon 1 that will be given OnPlayerSpawn
Example:
pawn Код:
COMMAND:cclan(playerid,params[])
{
     new cname[30], ctag[30], cpass[30], cw1, cw2, cw3;
     if(!sscanf(params, "s[30]s[30]s[30]iii", cname, ctag, cpass, cw1, cw2, cw3))
     {
          CreateClan(playerid, cname, ctag, cpass, "", "", cw1, cw2, cw3);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /cclan <clan-name> <clan-tag> <clan-pass> <weap1> <weap2> <weap3>");
     return 1;
}

Adding player to clan:
pawn Код:
native AddPlayerToClan(playerid, addid);

//playerid - player that perfoms the action
//addid - ID of player that will be added to clan
Example:
pawn Код:
COMMAND:addplayer(playerid,params[])
{
     new target;
     if(!sscanf(params, "u", target))
     {
          AddPlayerToClan(playerid, target);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /addplayer <playerid>");
     return 1;
}

Removing player from clan:
pawn Код:
native RemovePlayerFromClan(playerid, removeid);

//playerid - player that will perform action
//removeid - player that will be remove from clan
Example:
pawn Код:
COMMAND:remplayer(playerid,params[])
{
     new target;
     if(!sscanf(params, "u", target))
     {
          RemovePlayerFromClan(playerid, target);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /remplayer <playerid>");
     return 1;
}

Leaving clan:
pawn Код:
native LeaveClan(playerid);

//playerid - player that will leave the clan
Example:
pawn Код:
COMMAND:cleave(playerid,params[])
{
     return LeaveClan(playerid);
}

Disbanding clan:
pawn Код:
native DisbandClan(playerid);

//playerid - player that will disband their clan
Example:
pawn Код:
COMMAND:cdisband(playerid,params[])
{
     return DisbandClan(playerid);
}

Changing player's clan rank:
pawn Код:
native ChangePlayerClanRank(playerid, giveid, rank);

//playerid - player performing the action
//giveid - player that will have their rank changed
//rank - assign new rank to giveid (1 - member, 2 - officer, 3 - co-leader, 4 - leader)
Example:
pawn Код:
COMMAND:changerank(playerid,params[])
{
     new target, crank;
     if(!sscanf(params, "ui", target, crank))
     {
          ChangePlayerClanRank(playerid, target, crank);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /changerank <playerid> <rank>");
     return 1;
}

Changing clan's message of the day:
pawn Код:
native ChangeClanMOTD(playerid, new_motd[]);

//playerid - player that will change MOTD
//new_motd[] - new message of the day
Example:
pawn Код:
COMMAND:changemotd(playerid,params[])
{
     new cmotd[100];
     if(!sscanf(params, "s[100]", cmotd))
     {
          ChangeClanMOTD(playerid, cmotd);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /changerank <new-motd>");
     return 1;
}

Changing clan's description:
pawn Код:
native ChangeClanDescription(playerid, new_description[]);

//playerid - player that will perform change
//new_description[] - brand new clan description
Example:
pawn Код:
COMMAND:changedes(playerid,params[])
{
     new cdes[200];
     if(!sscanf(params, "s[200]", cdes))
     {
          ChangeClanDescription(playerid, cdes);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /changedes <new-description>");
     return 1;
}

Changing clan's weapons:
pawn Код:
native ChangeClanWeapons(playerid, new_weap1 = old_weap1, new_weap2 = old_weap2, new_weap3 = old_weap3);

//playerid - player performing command
//new_weap1 = old_weap1 - new/old weapon 1, given OnPlayerSpawn
//new_weap2 = old_weap2 - new/old weapon 2, given OnPlayerSpawn
//new_weap3 = old_weap3 - new/old weapon 3, given OnPlayerSpawn
Example:
pawn Код:
COMMAND:changeweaps(playerid,params[])
{
     new cw1, cw2, cw3;
     if(!sscanf(params, "iii", cw1, cw2, cw3))
     {
          ChangeClanWeapons(playerid, cw1, cw2, cw3);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /changeweaps <weap1> <weap2> <weap3>");
     return 1;
}

Changing clan's password:
pawn Код:
native ChangeClanPassword(playerid, newpass[]);

//playerid - player changing pass
//newpass[] - password that will replace old one
Example:
pawn Код:
COMMAND:changepass(playerid,params[])
{
     new cpass[20];
     if(!sscanf(params, "s[20]", cpass))
     {
          ChangeClanPassword(playerid, cpass);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /changepass <new-password>");
     return 1;
}
Changing clan's tag:
pawn Код:
native ChangeClanTag(playerid, new_tag[]);

//playerid - player changing pass
//new_tag[] - tag that will replace old one
Example:
pawn Код:
COMMAND:changetag(playerid,params[])
{
     new tag[10];
     if(!sscanf(params, "s[10]", tag))
     {
          ChangeClanTag(playerid, tag);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /changetag <new-tag>");
     return 1;
}
Checking if player is part of any clan:
pawn Код:
native IsPlayerAnyClanMember(playerid);

//playerid - player to check
//returns 1 if player is in clan, returns 0 if not

Checking if player is part of specific clan:
pawn Код:
native IsPlayerClanMember(playerid, clan_name[]);

//playerid - player to check
//clan_name[] - exact clan name
//will return 1 if player in "clan_name" clan, returns 0 if not

Getting name of player's clan:
pawn Код:
native GetPlayerClan(playerid);

//playerid - player to check
//returns string (clan's name) if player in clan

Getting clan rank of player:
pawn Код:
native GetPlayerClanRank(playerid);

//playerid - player to check
//returns player's clan rank (if in clan)

Getting clan's message of the day:
pawn Код:
native GetClanMOTD(clan[]);

//clan[] - clan to check
//returns message of the day of that specific "clan[]"

Getting clan's description:
pawn Код:
native GetClanDescription(clan[]);

//clan[] - clan to check
//returns description of that specific "clan[]"

Getting clan member names:
pawn Код:
native GetClanMembers(clan[]);

//clan[] - clan to check
//returns all player's name in a string
Getting clan's weapon(s):
pawn Код:
native GetClanWeapon(clan[],weap_slot);

//clan - in which clan will the weapons be checked
//weap_slot - since you can have only 3 clan weapons, slots are - 1, 2 and 3
//returns weapon ID in "weap_slot"
Getting clan's tag:
pawn Код:
native GetClanTag(clan[]);

//clan - retrieve the tag
//returns clan tag as string
Getting clan's password:
pawn Код:
native GetClanPassword(clan[]);

//clan - retrieve the tag
//returns clan password as string
Enabling clans' tags:
pawn Код:
native UseClanTags(bool:use = true);

//use - do you want players to have [TAG] in front of their names  

//NOTE: Should be used under "OnFilterScriptInit" or "OnGameModeInit"
Enabling clans' passwords:
pawn Код:
native UseClanPasswords(bool:use = true);

//use - players must input correct password to proceed to server

//NOTE: Should be used under "OnFilterScriptInit" or "OnGameModeInit"
Sending message to clan members (with "playerid" parameter):
pawn Код:
native SendMessageToClanMembers(playerid, color, msg[]);

//playerid - used in checking if player is in same clan as his clanmates
//color - message color
//msg[] - message to send
Sending message to clan members (without "playerid" parameter):
pawn Код:
native SendMessageToClanMembersEx(clan[], color, msg[]);

//clan[] - clan's members that will receive "msg"
//color - message color
//msg[] - message to send
__________________________________________________ _______________________________________________

CALLBACKS:
This system has a several custom callbacks that are called on performing specific natives!

Callbacks list:
pawn Код:
forward OnPlayerClanCreate(playerid, clan_name[]); //called when player creates a clan
forward OnPlayerAddPlayerToClan(playerid, addid, clan_name[]); //called on adding new member to clan
forward OnPlayerRemovePlayerFromClan(playerid, removeid, clan_name[]); //called when removing member from clan
forward OnPlayerLeaveClan(playerid, clan_name[]); //called when someone leaves some clan
forward OnPlayerDisbandClan(playerid, clan_name[]); //called when clan gets disbanded
forward OnPlayerChangeClanMOTD(playerid, new_motd[]); //called when clan's message of the day is changed
forward OnPlayerChangeClanDescription(playerid, new_description[]); //called when clan's description is changed
forward OnPlayerChangeClanWeapons(playerid, new_weap1, new_weap2, new_weap3); //called when clan weapons are changed
forward OnPlayerChangeClanPassword(playerid, new_pass[]); //called when clan password is changed
forward OnPlayerChangeClanTag(playerid, new_tag[]); //called when clan tag is changed
forward OnPlayerChangePlayerRank(playerid, giveid, new_rank); //called when someone get promoted/demoted
Examples:
pawn Код:
public OnPlayerClanCreate(playerid, clan_name[])
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    printf("Player %s created clan named %s", name, clan_name);
    return 1;
}

public OnPlayerAddPlayerToClan(playerid, addid, clan_name[])
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new addname[MAX_PLAYER_NAME];
    GetPlayerName(addid,addname,sizeof(addname));
    printf("Player %s added player %s to clan %s", name, addname, clan_name);
    return 1;
}

public OnPlayerRemovePlayerFromClan(playerid, removeid, clan_name[])
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new remname[MAX_PLAYER_NAME];
    GetPlayerName(removeid,remname,sizeof(remname));
    printf("Player %s removed player %s from clan %s", name, remname, clan_name);
    return 1;
}

public OnPlayerLeaveClan(playerid, clan_name[])
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    printf("Player %s left clan %s", name, clan_name);
    return 1;
}

public OnPlayerDisbandClan(playerid, clan_name[])
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    printf("Player %s disbanded clan %s", name, clan_name);
    return 1;
}

public OnPlayerChangeClanMOTD(playerid, new_motd[])
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    printf("Player %s changed clan's %s MOTD to %s", name, GetPlayerClan(playerid), new_motd);
    return 1;
}

public OnPlayerChangeClanPassword(playerid, new_pass[])
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    printf("Player %s changed clan's %s password to %s", name, GetPlayerClan(playerid), new_pass);
    return 1;
}

public OnPlayerChangeClanTag(playerid, new_tag[])
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    printf("Player %s changed clan's %s tag to %s", name, GetPlayerClan(playerid), new_tag);
    return 1;
}

public OnPlayerChangePlayerRank(playerid, giveid, new_rank)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new givename[MAX_PLAYER_NAME];
    GetPlayerName(giveid,givename,sizeof(givename));
    printf("Player %s changed rank of player %s to %d", name, givename, new_rank);
    return 1;
}
__________________________________________________ _______________________________________________

IMPORTANT NOTES:
- This system uses OnFilterScriptInit in itself
- This system uses OnPlayerSpawn in itself
- This system uses OnPlayerText in itself
- This system uses OnDialogResponse in itself
- This system uses OnPlayerConnect in itself
- This system uses it's own messages/notifications so there is no need of using extra SendClientMessages
- To use clan chat, you have to type symbol "$" first!
- You will need MySQL plugin from BlueG (click here)! NOTE: Has to be version R6 or R6-2, otherwise wont work!
- In this thread, I used ZCMD/sscanf only as example, but if you wanna copy/paste my examples in script, make sure you have ZCMD include and sscanf include + plugin (sscanf)

__________________________________________________ _______________________________________________

CREDITS:
fiki574_CRO - creating this system
Zeex - ZCMD include
****** - sscanf include + plugin
BlueG - MySQL include + plugin
__________________________________________________ _______________________________________________

DOWNLOAD:

Pastebin (v1.4) (newest, recommended)

<Mediafire link removed>

__________________________________________________ _______________________________________________

Hope you people like it! ^^

Best regards,
Fiki!
Reply
#2

Nice Thing

But i have suggestion
can you put there that:
Код:
IsPlayerClanLeader(playerid, clan_name[]);
MakePlayerClanLeader(playerid, clan_name[]);
GetPlayerClan(playerid,clan_name[]);
TakePlayerClanLeader(playerid, clan_name[]);
Like Exemple:

pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    if(!strcmp(name, "[DKT]BlackHawk", true)) {
    MakePlayerClanLeader(playerid, "TheDragons");
 SendClientMessageToAll(COLOR_RED, "You are the new leader of TheDragons");
            }
   return 1;
}
Reply
#3

wow nice!
Reply
#4

Quote:
Originally Posted by James Coral
Посмотреть сообщение
Nice Thing

But i have suggestion
can you put there that:
Код:
IsPlayerClanLeader(playerid, clan_name[]);
MakePlayerClanLeader(playerid, clan_name[]);
GetPlayerClan(playerid,clan_name[]);
TakePlayerClanLeader(playerid, clan_name[]);
Like Exemple:

pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    if(!strcmp(name, "[DKT]BlackHawk", true)) {
    MakePlayerClanLeader(playerid, "TheDragons");
 SendClientMessageToAll(COLOR_RED, "You are the new leader of TheDragons");
            }
   return 1;
}
Thanks you!

For "IsPlayerClanLeader(playerid, clan_name[])" -> you can do it easily yourself using GetPlayerClanRank(playerid)
For "MakePlayerClanLeader(playerid, clan_name[]);" -> ok, next version
For "GetPlayerClan(playerid,clan_name[]);" -> firstly, whats the point of getting the clan's name when you have "clan_name" in same native?? Also, read my post again -> there is a "GetPlayerClan"
For "TakePlayerClanLeader(playerid, clan_name[]);" -> elaborate more, or you thought on "Make" instead of "Take"?


Quote:
Originally Posted by tyler12
Посмотреть сообщение
wow nice!
Thanks!
Reply
#5

Very nice, I don't know why I didn't got this idea before you :P

Also

native ChangeClanWeapons(playerid, new_weap1, new_weap2, new_weap3);

you should use optional parameters in new_weap1,2,3 and that optional parameters would be equal to variable for clan weap1,2,3

If you don't understand, here is example

native ChangeClanWeapons(playerid, new_weap1 = clan_weap1, new_weap2 = clan_weap2, new_weap3 = clan_weap3);

so just change clan_weap1,2,3 change to your variables for weap1
Reply
#6

Quote:
Originally Posted by System64
Посмотреть сообщение
If you don't understand, here is example

native ChangeClanWeapons(playerid, new_weap1 = clan_weap1, new_weap2 = clan_weap2, new_weap3 = clan_weap3);

so just change clan_weap1,2,3 change to your variables for weap1
I still don't understand it.

Anyway, very nice include. I was creating one but this spares me a lot of time. I will edit this a lot tho, I will screenshot the results later ^^
Reply
#7

Beautiful Work !! +1
Reply
#8

Quote:
Originally Posted by System64
Посмотреть сообщение
Very nice, I don't know why I didn't got this idea before you :P

Also

native ChangeClanWeapons(playerid, new_weap1, new_weap2, new_weap3);

you should use optional parameters in new_weap1,2,3 and that optional parameters would be equal to variable for clan weap1,2,3

If you don't understand, here is example

native ChangeClanWeapons(playerid, new_weap1 = clan_weap1, new_weap2 = clan_weap2, new_weap3 = clan_weap3);

so just change clan_weap1,2,3 change to your variables for weap1
Thanks!
Yea, I know whats optional parameter, anyways will do it in next version!

Quote:
Originally Posted by Biesmen
Посмотреть сообщение
I still don't understand it.

Anyway, very nice include. I was creating one but this spares me a lot of time. I will edit this a lot tho, I will screenshot the results later ^^
Thank you! Just dont re-release your edited version!

Quote:
Originally Posted by Niko_boy
Посмотреть сообщение
Beautiful Work !! +1
Tnx!
Reply
#9

Oh, very nice include when i read first the post i think all this is with dini, but when i open the pastebin it was MySQL, very GOOD! Rep++
Reply
#10

Quote:
Originally Posted by Edvin
Посмотреть сообщение
Oh, very nice include when i read first the post i think all this is with dini, but when i open the pastebin it was MySQL, very GOOD! Rep++
Thanks! Yea I decided for MySQL, since its a billion times better!
Reply
#11

Very well explained, nice system. Keep this work out, its very useful.
Reply
#12

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
Very well explained, nice system. Keep this work out, its very useful.
Thanks, man, appriciated!
Reply
#13

Also, forgot to mention!

Please, report any bugs if found!
Post your suggestions, if you have any!

Reply
#14

Wow! This include would be useful for my server, thanks!
Reply
#15

Quote:
Originally Posted by rscaerzx
Посмотреть сообщение
Wow! This include would be useful for my server, thanks!
You are welcome!
Reply
#16

Can you make an example of the script? And how can i give the weapons of the clan to the members?

and where is: native RemovePlayerFromClan(playerid, removeid); ??
Reply
#17

Quote:
Originally Posted by Anonym2009
Посмотреть сообщение
Can you make an example of the script? And how can i give the weapons of the clan to the members?

and where is: native RemovePlayerFromClan(playerid, removeid); ??
Have you read my whole post? Cause everything is there! Read again and you'll find RemovePlayerFromClan and examples for every single native! Also, weapons are given OnPlayerSpawn which can be found inside the include!

Next time, please, read whole post before asking! Thank you!
Reply
#18

pawn Код:
new clanquery[300];
                        format(clanquery, sizeof(clanquery), "UPDATE clans SET clanmotd = '%s' WHERE clanname = '%s'", new_motd, GetPlayerClan(playerid));
There are so many things you need to optimize.

pawn Код:
ChangeClanMOTD(playerid, "DROP TABLE clans;");
Probably exploitable like that, make protection against SQL injections too.

I might create a improved version soon, when I have the time.
Reply
#19

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
pawn Код:
new clanquery[300];
                        format(clanquery, sizeof(clanquery), "UPDATE clans SET clanmotd = '%s' WHERE clanname = '%s'", new_motd, GetPlayerClan(playerid));
There are so many things you need to optimize.

pawn Код:
ChangeClanMOTD(playerid, "DROP TABLE clans;");
Probably exploitable like that, make protection against SQL injections too.

I might create a improved version soon, when I have the time.
Oh, havent thought about that! Thanks for reminding!
Reply
#20

Getting Error: include\clan.inc(169) : error 001: expected token: ")", but found "{"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.

pawn Код:
COMMAND:remplayer(playerid,params[])
{
     new target;
     if(!sscanf(params, "u", target))
     {
          Here-> RemovePlayerFromClan(playerid, target);
          return 1;
     }
     else SendClientMessage(playerid,-1,"USAGE: /remplayer <playerid>");
     return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)