05.11.2012, 07:57
Hello SA:MP forum... I'm new user, but I have some PAWN knowledge. This is my first tutorial so don't be rough
Introduction
-This is tutorial about Gang System. In this tutorial i will try to helps you to figure Y_Ini loading/saving better, how to use Y_cmds and sscanf2 and ofcourse how to create a gang system..
What I need?
-YSI 3.1 which you can download HERE
-sscanf2 download it HERE
-foreach this you will download HERE
Start
-Add on top of your script theese includes if you don't have them:
-Under includes add define of some colors, to easy of using it and some other defines that will help ous of typing much of code :
-Now we will define a place where gang will saves:
-Now we need some variables
-Now add enums..
-Now we will do OnPlayerConnect and OnPlayerDisconnect when player connect to load his gang stats and when he leaves to save his gang stats
-Ok when you have Load/Save player gang stats, we can move on OnPlayerSpawn where we will set players x,y,z position of spawning, give some weapons and set player skin...
-Now we should put things for loading and things we use before (UsePath..) for loading and timer
-This are some stuff that will help ous for Radio and other things, just that we don't have to type too much of codes..
-Almost and we are done, now we need to add some commands..
If you have any others question ask it
Introduction
-This is tutorial about Gang System. In this tutorial i will try to helps you to figure Y_Ini loading/saving better, how to use Y_cmds and sscanf2 and ofcourse how to create a gang system..
What I need?
-YSI 3.1 which you can download HERE
-sscanf2 download it HERE
-foreach this you will download HERE
Start
-Add on top of your script theese includes if you don't have them:
pawn Код:
#include <a_samp>
#include <YSI\y_commands> //Using it for commands
#include <YSI\y_ini> //Using it for loading/saving variables
#include <sscanf2> //Credits to ******
#include <foreach> //Loop trough players... (******)
#include <YSI\y_timers> //for timers
pawn Код:
#define COL_VALUE "{A3E4FF}"
#define COL_LRED2 "{C77D87}"
#define COL_WHITE "{FFFFFF}"
#define COL_LGREEN "{C9FFAB}"
#define COL_ORANGE "{FFAF00}"
#define COL_RED "{F81414}"
#define COL_YELLOW "{F3FF02}"
#define COL_PINK "{FF00EA}"
#define COL_LIGHTBLUE "{00C0FF}"
#define YouAreNotAdmin(%0); \
SendClientMessage(%0, -1, "| "#COL_RED"X::Gang "#COL_WHITE"| "#COL_GREY"You are not Admin!"); //Message that will show to player if he isn't admin when he is adding a leader to someone..
#define WrongID(%0); \
GangMSG(%0, "ID igraca ili Ime koje ste upisali ne postoji!"); //Message that will show to player if the selected player isn't online..
pawn Код:
#define Path "/Gang/%s.ini"
pawn Код:
new GangName[MAX_PLAYERS][128], //The name of Gang
RankName[MAX_PLAYERS][128], //Rank name of player
gangG, //We are going to use this for get player Gang ID
lidG, //We are going to use this for get if the player is Leader
ClA, //This will be amount of player that are in Gang A
ClB //This will be amount of player that are in Gang B
;
pawn Код:
enum gInfo
{
gGang, //ID of gang
gLeader, //ID of Leader gang (Leader of which Gang ID)
gCont, //Contract of player in gang
gRank, //Rank of player in Gang
gSkin, //Skin of player in Gang
gColor //Color of player in Gang
}
new G_Info[MAX_PLAYERS][gInfo]; //Form
pawn Код:
public OnPlayerConnect(playerid)
{
if(fexist(UserPath(playerid))) //If exist a file in "Gang" folder with player name
{
//If exist Load player gang stats and set player color of the gang in which he is.. If player
//isn't in any of gang, he's color will be White
INI_ParseFile(UserPath(playerid), "LoadGang_%s", .bExtra = true, .extra = playerid);
SetPlayerColor(playerid, G_Info[playerid][gColor]);
}
else //if player has connect first time, and a file dosen't exist
{
//Make a new file in folder "Gang" whit player name in which we will store some variables
//We save all necesery variables of gang(Leader, Skin, Color, Rank...)
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"gang");
INI_WriteInt(File,"gContract",0);
G_Info[playerid][gCont] = 0;
INI_WriteInt(File,"gGang",0);
G_Info[playerid][gGang] = 0;
INI_WriteInt(File,"gLeader",0);
G_Info[playerid][gLeader] = 0;
INI_WriteInt(File,"gRank",0);
G_Info[playerid][gRank] = 0;
INI_WriteInt(File,"gColor",4294967295);
G_Info[playerid][gColor] = 4294967295;
INI_WriteInt(File,"gSkin",0);
G_Info[playerid][gSkin] = 0;
INI_WriteString(File,"gGangName","Civil");
GangName[playerid] = "Civil";
INI_WriteString(File,"gRankName","Nothing");
RankName[playerid] = "Nothing";
INI_Close(File);
//Close file
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
//When player leave server, we have to save his stats
//So, open his file in folder "Gang" and write variables of gang (Leader, Skin...)
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"gang");
INI_WriteInt(File,"gGang",G_Info[playerid][gGang]);
INI_WriteInt(File,"gLeader",G_Info[playerid][gLeader]);
INI_WriteInt(File,"gContract",G_Info[playerid][gCont]);
INI_WriteInt(File,"gRank",G_Info[playerid][gRank]);
INI_WriteInt(File,"gSkin",G_Info[playerid][gSkin]);
INI_WriteInt(File,"gColor",G_Info[playerid][gColor]);
INI_WriteString(File,"gGangName",GangName[playerid]);
INI_WriteString(File,"gRankName",RankName[playerid]);
INI_Close(File);
return 1;
}
pawn Код:
public OnPlayerSpawn(playerid)
{
if(G_Info[playerid][gGang] == 1) //If is the player in Gang A
{
SetPlayerPos(playerid, 50.0, 0.0, 10.0); //This is just test coordinats...
SetPlayerFacingAngle(playerid, 50.5); //Test angle
GivePlayerWeapon(playerid, 26, 200); //Random weapons
GivePlayerWeapon(playerid, 24, 150);
GivePlayerWeapon(playerid, 28, 300);
GivePlayerWeapon(playerid, 31, 250);
SetPlayerSkin(playerid, G_Info[playerid][gSkin]); //Set Player skin which his gang use it..
}
if(G_Info[playerid][gGang] == 2) //If is the player in Gang B
{
SetPlayerPos(playerid, 50.0, 0.0, 10.0);
SetPlayerFacingAngle(playerid, 50.5);
GivePlayerWeapon(playerid, 26, 200);
GivePlayerWeapon(playerid, 24, 150);
GivePlayerWeapon(playerid, 28, 300);
GivePlayerWeapon(playerid, 31, 250);
SetPlayerSkin(playerid, G_Info[playerid][gSkin]);
}
return 1;
}
pawn Код:
forward LoadGang_gang(playerid,name[],value[]);
public LoadGang_gang(playerid,name[],value[])
{
INI_Int("gGang",G_Info[playerid][gGang]); //This will load a 'name' of variable "gGang" and store it at variable "G_Info[playerid][gGang]"...
INI_Int("gLeader",G_Info[playerid][gLeader]);
INI_Int("gContract",G_Info[playerid][gCont]);
INI_Int("gRank",G_Info[playerid][gRank]);
INI_Int("gSkin",G_Info[playerid][gSkin]);
INI_Int("gColor",G_Info[playerid][gColor]);
INI_String("gGangName",GangName[playerid], 128);
INI_String("gRankName",RankName[playerid], 128);
return 1;
}
forward Load_G(name[], value[]);
public Load_G(name[], value[])
{
INI_Int("Gang", gangG); //Load GangID which we use later for offline kicking and store it in variable "gangG"
INI_Int("Leader", lidG);
return 1;
}
INI:cGang[broj](name[], value[]) //Loading how much players are in gang.. We use it because we won't to have a 100 players in one gang :)
{
INI_Int("MembersA", ClA);
INI_Int("MembersB", ClB);
return 1;
}
stock UserPath(playerid) //Use it for easy saving/loading when player is online
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),Path,playername);
return string;
}
stock GPath(gang[]) //Using it later, for offline kicking if player isn't online
{
new stringBC[128];
format(stringBC,sizeof(stringBC),Path,gang);
return stringBC;
}
stock PlayerName(playerid)
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
return pName;
}
ptask ContractG[3600000](playerid) //Create timer that will evry hour incres player contract if he is in gang
{
if(G_Info[playerid][gGang] != 0)
{
G_Info[playerid][gCont]++;
}
return 1;
}
pawn Код:
stock SendRadioMessage(gang, color, string[])
{
foreach(new u: Player)
{
if(G_Info[u][gGang] == gang)
{
SendClientMessage(u, color, string);
}
}
}
stock Use(playerid, usage[])
{
new Str[256];
format(Str, sizeof(Str), ""COL_ORANGE"Koristite: "COL_WHITE"%s", usage);
SendClientMessage(playerid, -1, Str);
return 1;
}
stock GangMSG(playerid, smsg[])
{
new gangmsg[128];
format(gangmsg, sizeof(gangmsg), "| "COL_VALUE"X:Gang "COL_WHITE"| "COL_LRED2"%s", smsg);
SendClientMessage(playerid, -1, gangmsg);
return 1;
}
pawn Код:
YCMD:leaders(playerid, params[], help) //Command to get online leaders
{
SendClientMessage(playerid, -1, ""COL_LGREEN"Online Leaders:");
new string[128];
foreach(Player, x) //using foreach to loop trough all players
{
if(G_Info[x][gLeader] >= 1)
{
format(string, sizeof(string), ""COL_ORANGE"Leader "COL_WHITE"%s "COL_RED"| "COL_ORANGE"Gang: "COL_WHITE"%s", PlayerName(x), GangName[x]);
SendClientMessage(playerid, -1, string);
}
}
return 1;
}
YCMD:members(playerid, params[], help) //Command to get online members of your gang
{
SendClientMessage(playerid, -1, ""COL_LGREEN"Online Members:");
new string[128];
foreach(Player, x)
{
if(G_Info[x][gGang] == G_Info[playerid][gGang])
{
format(string, sizeof(string), ""COL_ORANGE"Member "COL_WHITE"%s "COL_RED"| "COL_ORANGE"Rank: "COL_WHITE"%s(%d)", PlayerName(x), RankName[x], G_Info[x][gRank]);
SendClientMessage(playerid, -1, string);
}
}
return 1;
}
YCMD:f(playerid, params[], help) //Family chat, using it for a chat in gang
{
if(G_Info[playerid][gGang] == 0)return GangMSG(playerid, "You are not member of any gang!");
new chat[128], string[128];
if(sscanf(params, "s[128]", chat))return Use(playerid, "/f(amily) [Chat]");
if(G_Info[playerid][gGang] == 1)
{
format(string, sizeof(string), ""COL_YELLOW"(A)%s %s: "#COL_WHITE"%s, "COL_YELLOW"over...", RankName[playerid], PlayerName(playerid), chat);
SendRadioMessage(1, -1, string);
}
if(G_Info[playerid][gGang] == 2)
{
format(string, sizeof(string), ""COL_YELLOW"(B)%s %s: "COL_WHITE"%s, "COL_YELLOW"over...", RankName[playerid], PlayerName(playerid), chat);
SendRadioMessage(2, -1, string);
}
return 1;
}
YCMD:invite(playerid, params[], help) //Command to invite someone to your gang
{
if(G_Info[playerid][gLeader] == 0)return GangMSG(playerid, "You are not Leader!"); //If you are not Leader you can't invite no one to your gang
new id, string[128], stringa[128];
if(sscanf(params, "u", id))return Use(playerid, "/invite [playerid/Player Name]");
if(id == playerid)return GangMSG(playerid, "You can't invite yourself to gang!"); //If 'id' is equal to 'playerid' that means that you want to invite yourself to gang.. and it's not possible becouse you are already in gang as Leader
if(id == INVALID_PLAYER_ID)return WrongID(playerid); //If player isn't online
if(G_Info[id][gGang] != 0)return GangMSG(playerid, "Player is in another gang!"); //If player is in another gang you can't invite him to yours gang
INI_Load("cGang.ini"); //load file in which we will save how many players are in gang
if(G_Info[playerid][gLeader] == 1)
{
if(ClA == 12)return GangMSG(playerid, "You have reach max amout of members!");//If the gang A has 12 members that means that gang is full
format(string, sizeof(string), "You have been invited to gang from Leader "COL_WHITE"%s!", PlayerName(playerid));
GangMSG(id, string);
format(stringa, sizeof(stringa), "You have invited player "COL_WHITE"%s "COL_LRED2"in your gang!", PlayerName(id));
GangMSG(playerid, stringa);
GangName[id] = "Gang A"; //Set gang name of player
RankName[id] = "Rank_A1"; //set rank name of player
G_Info[id][gGang] = 1;
G_Info[id][gRank] = 1;
G_Info[id][gColor] = 3265452714;
G_Info[id][gSkin] = 124;
ClA++; //incress players in gang A
}
if(G_Info[playerid][gLeader] == 2)
{
if(ClB == 12)return GangMSG(playerid, "You have reach max ammout of members!");
format(string, sizeof(string), "You have been invited to gang from Leader "COL_WHITE"%s!", PlayerName(playerid));
GangMSG(id, string);
format(stringa, sizeof(stringa), "You have invited player "COL_WHITE"%s "COL_LRED2"in your gang!", PlayerName(id));
GangMSG(playerid, stringa);
G_Info[id][gRank] = 1;
RankName[id] = "Rank_B1";
GangName[id] = "Rakovica Boys";
G_Info[id][gGang] = 2;
G_Info[id][gColor] = 4278190335;
G_Info[id][gSkin] = 114;
ClB++;
}
new INI:iniFile = INI_Open("cGang.ini");//open file
INI_SetTag(iniFile,"num"); //set tag
INI_WriteInt(iniFile,"MembersA",ClA); //write down value
INI_WriteInt(iniFile,"MembersB",ClB); //write down value
INI_Close(iniFile);
return 1;
}
YCMD:qf(playerid, params[], help)
{
/*
If player want to quit his gang he can do it whit this command
but player has to have 10 contract hours
*/
if(G_Info[playerid][gGang] == 0)return GangMSG(playerid, "You are not in any gang!");
if(G_Info[playerid][gCont] < 10)return GangMSG(playerid, "You cant leave gang! You have to have at least 10h of contract!");
if(G_Info[playerid][gLeader] != 0)return GangMSG(playerid, "You are Leader! You can't leave gang!");
if(G_Info[playerid][gGang] == 1) ClA--;
if(G_Info[playerid][gGang] == 2) ClB--;
G_Info[playerid][gCont] = 0;
G_Info[playerid][gGang] = 0;
G_Info[playerid][gColor] = 4294967295;
G_Info[playerid][gSkin] = 0;
GangName[playerid] = "Civil";
RankName[playerid] = "Nothing";
new INI:iniFile = INI_Open("cGang.ini");
INI_SetTag(iniFile,"num");
INI_WriteInt(iniFile,"MembersA",ClA);
INI_WriteInt(iniFile,"MembersB",ClB);
INI_Close(iniFile);
return 1;
}
YCMD:uninvite(playerid, params[], help)
{
/*
if you want to uninvite player from your gang, and the player is online...
*/
if(G_Info[playerid][gLeader] == 0)return GangMSG(playerid, "You are not Leader!");
new id, string[128], stringa[128];
if(sscanf(params, "u", id))return Use(playerid, "/uninvite [playerid/Player Name]");
if(id == playerid)return GangMSG(playerid, "You can't uninvite yourself!");
if(id == INVALID_PLAYER_ID)return WrongID(playerid);
if(G_Info[playerid][gGang] != G_Info[id][gGang])return GangMSG(playerid, "Player is not in your gang!");
if(G_Info[id][gLeader] != 0)return GangMSG(playerid, "You can't uninvite Leader!");
if(G_Info[id][gGang] == 1) ClA--;
if(G_Info[id][gGang] == 2) ClB--;
G_Info[id][gRank] = 0;
G_Info[id][gGang] = 0;
G_Info[id][gColor] = 4294967295;
G_Info[id][gCont] = 0;
GangName[id] = "Civil";
RankName[id] = "Nothing";
format(string, sizeof(string), "You have been uninvited by Leader "COL_WHITE"%s!", PlayerName(playerid));
GangMSG(id, string);
format(stringa, sizeof(stringa), "You have uninvite player "COL_WHITE"%s "COL_LRED2"from your gang!", PlayerName(id));
GangMSG(playerid, stringa);
new INI:iniFile = INI_Open("cGang.ini");
INI_SetTag(iniFile,"broj");
INI_WriteInt(iniFile,"ClanoviP",ClA);
INI_WriteInt(iniFile,"ClanoviR",ClB);
INI_Close(iniFile);
return 1;
}
YCMD:offkick(playerid, params[], help)
{
/*
You want to kick out player that if is your gang, but he isn't online, then you use this commande
*/
if(G_Info[playerid][gLeader] == 0)return GangMSG(playerid, "You are not Leader!");
new name[24], string[128], stringa[128];
if(sscanf(params, "s[24]", name))return Use(playerid, "/offkick [Player Name]");
format(string, sizeof(string), Path, name);
if(fexist(string))
{
INI_ParseFile(GPath(name), "Load_G");
if(G_Info[playerid][gGang] != gangG)return GangMSG(playerid, "Player is not in your gang!");
if(lidG != 0)return GangMSG(playerid, "You can't kick out Leader!");
new INI:File = INI_Open(GPath(name));
INI_SetTag(File, "gang");
INI_WriteInt(File,"gGang",0);
INI_WriteInt(File,"gRank",0);
INI_WriteInt(File,"gColor",4294967295);
INI_WriteInt(File,"gContract",0);
INI_WriteString(File,"gGangName","Civil");
INI_WriteString(File,"gRankName","Nothing");
INI_Close(File);
format(stringa, sizeof(stringa), "You have kick out %s from your gang!", name);
GangMSG(playerid, stringa);
}
else GangMSG(playerid, "That player not even exist!");
return 1;
}
YCMD:giverank(playerid, params[], help)
{
/*
Adding to player a rank
*/
if(G_Info[playerid][gLeader] == 0)return GangMSG(playerid, "You are not Leader!");
new id, rank, string[128], stringa[128];
if(sscanf(params, "ui", id, rank))return Use(playerid, "/giverank [playerid/Player Name] [Rank]");
if(rank < 1 || rank > 6)return GangMSG(playerid, "Rank has to be from 1- 6!");
if(id == INVALID_PLAYER_ID)return WrongID(playerid);
if(G_Info[playerid][gGang] != G_Info[id][gGang])return GangMSG(playerid, "Player isn't in your gang!");
if(G_Info[playerid][gLeader] == 1)
{
if(rank == 1) RankName[id] = "Rank_A1"; G_Info[id][gSkin] = 124; //Set Player Rank name and add skin, that is going with that rank
if(rank == 2) RankName[id] = "Rank_A2"; G_Info[id][gSkin] = 126;
if(rank == 3) RankName[id] = "Rank_A3"; G_Info[id][gSkin] = 273;
if(rank == 4) RankName[id] = "Rank_A4"; G_Info[id][gSkin] = 125;
if(rank == 5) RankName[id] = "Rank_A5"; G_Info[id][gSkin] = 3;
if(rank == 6) RankName[id] = "Rank_A6"; G_Info[id][gSkin] = 127;
}
if(G_Info[playerid][gLeader] == 2)
{
if(rank == 1) RankName[id] = "Rank_B1"; G_Info[id][gSkin] = 114;
if(rank == 2) RankName[id] = "Rank_B2"; G_Info[id][gSkin] = 115;
if(rank == 3) RankName[id] = "Rank_B3"; G_Info[id][gSkin] = 116;
if(rank == 4) RankName[id] = "Rank_B4"; G_Info[id][gSkin] = 174;
if(rank == 5) RankName[id] = "Rank_B5"; G_Info[id][gSkin] = 175;
if(rank == 6) RankName[id] = "Rank_B6"; G_Info[id][gSkin] = 208;
}
G_Info[id][gRank] = rank;
format(string, sizeof(string), "Leader "COL_WHITE"%s "COL_LRED2"has given to you Rank "COL_LIGHTBLUE"%s (%d)!", PlayerName(playerid), RankName[id], rank);
GangMSG(id, string);
format(stringa, sizeof(stringa), "You have gave to Member "COL_WHITE"%s "COL_LRED2"Rank "COL_LIGHTBLUE"%s (%d)!", PlayerName(id), RankName[id], rank);
GangMSG(playerid, stringa);
return 1;
}
YCMD:makeleader(playerid, params[], help)
{
/*
Command with which you can make someone leader of some gang, but you have to
be a RCON Admin...
*/
if(!IsPlayerAdmin(playerid))return YouAreNotAdmin(playerid);
new id, Leader, string[128], stringa[128];
if(sscanf(params, "ui", id, Leader))return Use(playerid, "/makeleader [playerid/Player Name] [Gang]");
if(id == INVALID_PLAYER_ID)return WrongID(playerid);
if(G_Info[id][gGang] != 0)return GangMSG(playerid, "Igrac je vec u drugoj bandi!");
if(Leader < 0 || Leader > 2)return GangMSG(playerid, "Bande mogu biti pod ID-om: 1 - Gang A, 2 - Gang B");
switch(Leader)
{
case 0:
{
G_Info[id][gLeader] = 0;
G_Info[id][gGang] = 0;
GangName[id] = "Civil";
RankName[id] = "Nothing";
G_Info[id][gRank] = 0;
G_Info[id][gColor] = 4294967295;
G_Info[id][gCont] = 0;
G_Info[id][gSkin] = 0;
format(string, sizeof(string), "Admin "COL_WHITE"%s "COL_LRED2"has remove your Leader status!", PlayerName(playerid));
GangMSG(id, string);
format(stringa, sizeof(stringa), "You have removed "COL_WHITE"%s "COL_LRED2"Leader status!", PlayerName(id));
GangMSG(playerid, stringa);
}
case 1:
{
G_Info[id][gLeader] = 1;
G_Info[id][gGang] = 1;
GangName[id] = "Gang A";
RankName[id] = "Rank_A6";
G_Info[id][gRank] = 6;
G_Info[id][gColor] = 3265452714;
G_Info[id][gCont] = 0;
G_Info[id][gSkin] = 127;
format(string, sizeof(string), "Admin "COL_WHITE"%s "COL_LRED2"has gave you leader of "COL_PINK"Gang A!", PlayerName(playerid));
GangMSG(id, string);
format(stringa, sizeof(stringa), "You gave player "COL_WHITE"%s "COL_LRED2"Leadera of "COL_PINK"Gang A!", PlayerName(id));
GangMSG(playerid, stringa);
}
case 2:
{
G_Info[id][gLeader] = 2;
G_Info[id][gGang] = 2;
GangName[id] = "Rakovica Boys";
RankName[id] = "Rank_B6";
G_Info[id][gRank] = 6;
G_Info[id][gColor] = 4278190335;
G_Info[id][gCont] = 0;
G_Info[id][gSkin] = 208;
format(string, sizeof(string), "Admin "COL_WHITE"%s "COL_LRED2"has gave you leader of "COL_RED"Rakovica Boys!", PlayerName(playerid));
GangMSG(id, string);
format(stringa, sizeof(stringa), "You gave player "COL_WHITE"%s "COL_LRED2"Leadera of "COL_RED"Rakovica Boys!", PlayerName(id));
GangMSG(playerid, stringa);
}
}
return 1;
}