#include <a_samp>
#include <zcmd>
#include <YSI\y_ini>
#include <sscanf2>
#define COLOR_RED 0xFF0000AA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_CYAN 0x00FFFFFF
#define COLOR_PDRAD 0x297CCFFF
enum pInfo
{
pFaction, //saves the ID of the faction the player is in, in the players file
pFacrank,//saves the faction rank of the player, in the players file
pFacleader// saves weather the player is a leader of the faction and what faction that is
}
new PlayerInfo[MAX_PLAYERS][pInfo];
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Faction",PlayerInfo[playerid][pFaction]);//when the player logs in it will load his faction id
INI_Int("Facrank",PlayerInfo[playerid][pFacrank]);// when the player logs in it will load his faction rank
INI_Int("Facleader",PlayerInfo[playerid][pFacleader]);//when the player logs in it will load his leadership status
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Faction",PlayerInfo[playerid][pFaction]);//saves the players faction id on disconnect
INI_WriteInt(File,"Facrank",PlayerInfo[playerid][pFacrank]);//saves the players faction rank on disconnect
INI_WriteInt(File,"Facleader",PlayerInfo[playerid][pFacleader]);//saves the players faction leadership status on disconnect
INI_Close(File);
return 1;
}
INI_WriteInt(File,"Faction",0);//sets the players faction to none when they connect for the first time
INI_WriteInt(File,"Facrank",0);sets the players faction rank to none when they connect for the first time
INI_WriteInt(File,"Facleader",0);//sets the players factions leadership status to none when they connect for the first time
CMD:fackick(playerid,params[])
{
if(PlayerInfo[playerid][pAdmin] >= 3)//Replace this with your player variable
{
new targetid;//establishes a person on the server to use the command on
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "/fackick [id]");//tells you how to use the command if you use it incorrectly
if(targetid != INVALID_PLAYER_ID)//checks if the id you type in is an id that is not connected to the server
{
PlayerInfo[targetid][pFaction] = 0; //kicks the player from his faction
PlayerInfo[targetid][pFacrank] = 0;//sets his rank to 0
PlayerInfo[targetid][pFacleader] = 0;// revokes his leadership status
SendClientMessage(targetid,COLOR_CYAN,"You have been kicked from your faction by an admin.");//tells them they have been kicked out of their faction by an admin.
}
}
else//if they arent an admin then it will send them they message below telling them they may not use the command
{
SendClientMessage(playerid, COLOR_RED, "Only certain levels of Administration have access to this command.");
}
return 1;
}
CMD:makeleader(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 4) //Replace this with your player variable
{
new targetid, facid;//establishes a player and a faction id, to be typed in
if(sscanf(params,"ui",targetid, facid)) return SendClientMessage(playerid, COLOR_RED,"/makeleader [id][Faction id]");//if the command is misused it will tell them the correct way to use it
if(targetid != INVALID_PLAYER_ID)//checks if the id you type in is an id that is not connected to the server
{
PlayerInfo[targetid][pFaction] = facid; //sets the players faction to the faction you choose
PlayerInfo[targetid][pFacrank] = 10;//sets their rank to the highest rank
PlayerInfo[targetid][pFacleader] = facid;//sets their leadership to the id of the faction
if(facid == 1)//checks if the factionid typed was 1, and tells them they are the leader of the police below
{
SendClientMessage(targetid,COLOR_CYAN,"You have been made the leader of the police department");
}
}
}
else //if the player is not an admin it will show the below message telling them they are not an admin.
{
SendClientMessage(playerid, COLOR_RED, "Only certan levels of Administration have access to this command.");
}
return 1;
}
CMD:invite(playerid, params[])
{
if(PlayerInfo[playerid][pFacleader] > 0 || PlayerInfo[playerid][pFacrank] >= 8)//checks if the player is the leader of a faction or a high rank in it
{
new tarid, facid;//establishes a player in the server and a faction id for you to type in
if(sscanf(params, "u", tarid)) return SendClientMessage(playerid, COLOR_RED, "> USAGE: /invite [playerid]");//if the command is not typed correctly, it will show you the correct way to use the command.
facid = PlayerInfo[playerid][pFaction];//sets the faction the player is being invited to, as the faction the player that is inviting is in.
SetPVarInt(tarid, "invitefac", facid);//saves the invite, to /accept it
SendClientMessage(tarid, COLOR_GREEN, "You have been invited into a faction, use /acceptinvite to join");//tells you that you have been invited to a faction
}
else //if you're not the correct rank it will display the message below stating that the player is not the rank to invite
{
SendClientMessage(playerid, COLOR_RED, "You do not have the rank to invite");
}
return 1;
}
CMD:acceptinvite(playerid, params[])
{
new facid, string[128];//creates a faction id and some text on the players screen
facid = GetPVarInt(playerid, "invitefac");//calls the saved invite from the previous command
PlayerInfo[playerid][pFaction] = facid; //sets the players faction to that of the person inviting.
PlayerInfo[playerid][pFacrank] = 1;//sets the players faction rank to 1
format(string, sizeof(string), "> You have accepted the invite to faction %d", facid);//tells the player they have accepted the faction invite
SendClientMessage(playerid, COLOR_CYAN, string);//shows the above message in the color of CYAN
DeletePVar(playerid, "invitefac");//deletes the saved invite
return 1;
}
CMD:uninvite(playerid,params[])
{
if(PlayerInfo[playerid][pFacleader] > 0 || PlayerInfo[playerid][pFacrank] >= 8)//checks if the player is high enough rank to uninvite
{
new targetid;//establishes a person to use the command on in the server
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "/copuninvite [id]");//if the command is not typed correctly it will display how to do it the right way.
if(targetid != INVALID_PLAYER_ID)//checks if the id typed is an actual player on the server
{
PlayerInfo[targetid][pFaction] = 0;//uninvites the player from the faction
PlayerInfo[targetid][pFacrank] = 0;//sets the players rank to 0
PlayerInfo[targetid][pFacleader] = 0;//revokes leadership status
SendClientMessage(targetid,COLOR_CYAN,"You have been kicked from your faction.");//states you've been kicked from the faction to the player the command is used on.
}
}
else //if the player is not the sufficient rank to uninvinte it will state that in the chat
{
SendClientMessage(playerid, COLOR_RED, "You do not have the rank to uninvite");
}
return 1;
}
CMD:giverank(playerid, params[])
{
if(PlayerInfo[playerid][pFacleader] > 0 || PlayerInfo[playerid][pFacrank] >= 8)//checks if the player is high enough rank
{
new targetid, rank, string[128];//establishes a player to use the command on, the rank you want to set, and some words to tell the players the actions used on them.
if(sscanf(params, "ui", targetid, rank)) return SendClientMessage(playerid, COLOR_RED, "Usage: /coprank [playerid][rank]");//checks if the command was typed correctly
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "That player is not connected!");//if the player id typed is not connected it will state that to you.
if(PlayerInfo[targetid][pFaction] != PlayerInfo[playerid][pFaction]) return SendClientMessage(playerid, COLOR_RED, "That player is not in your faction!");//if the player is not in the same faction it will not let him set the rank.
if(rank < 1 || rank > 10) return SendClientMessage(playerid, COLOR_RED,"Rank must be 1-10");//checks if the rank number typed is above or below the correct numbers
PlayerInfo[targetid][pFacrank] = rank;//sets the players rank to the rank you choose
format(string, sizeof(string), "Your rank has been changed to rank %d!", rank);
SendClientMessage(targetid, COLOR_GREEN, string);//states that the players rank was changed
}
else //if the player is not the correct rank it will display this message below
{
SendClientMessage(playerid, COLOR_RED, "You do not have the rank to set ranks");
}
return 1;
}
CMD:r(playerid, params[]) return cmd_radio(playerid, params);
CMD:radio(playerid, params[])
{
new string[128], text[128], ctext[60], pname[MAX_PLAYER_NAME+1];//establishes a few things needed to tell the players name, rank, and the text he has written.
GetPlayerName(playerid, pname, sizeof(pname));//gets the name of the player using /radio
if(sscanf(params, "s[128]", text)) return SendClientMessage(playerid, 0x46E850FF, "SERVER:{FFFFFF} /r(adio) [text]");//if /r is not used correctly it will tell you the correct way to use it
if(PlayerInfo[playerid][pFaction] == 1)//checks if the player is in the first faction
{
if(PlayerInfo[playerid][pFacrank] == 1){ ctext = "Cadet"; }//all of these check the players rank and
if(PlayerInfo[playerid][pFacrank] == 2){ ctext = "Officer"; }// sets each rank to a specific name
if(PlayerInfo[playerid][pFacrank] == 3){ ctext = "Senior Officer"; }
if(PlayerInfo[playerid][pFacrank] == 4){ ctext = "Corporal"; }
if(PlayerInfo[playerid][pFacrank] == 5){ ctext = "Sergeant"; }
if(PlayerInfo[playerid][pFacrank] == 6){ ctext = "Lieutenant"; }
if(PlayerInfo[playerid][pFacrank] == 7){ ctext = "Captain"; }
if(PlayerInfo[playerid][pFacrank] == 8){ ctext = "Commander"; }
if(PlayerInfo[playerid][pFacrank] == 9){ ctext = "Deputy Chief"; }
if(PlayerInfo[playerid][pFacrank] == 10){ ctext = "Chief"; }
format(string, sizeof(string), "%s %s: %s", ctext, pname, text);
if(PlayerInfo[playerid][pFaction] > 0)//if the player is not in a faction it will not send him any messages
{
SendCopMessage(COLOR_PDRAD, string);//calls a stock below that checks who the /r should be sent to
}
}
return 1;
}
stock SendCopMessage(col, string[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(PlayerInfo[i][pFaction] == 1)
SendClientMessage(i, col, string); //goes through all the players checking who is and isint in faction 1
}
return 1;
}
stock IsACopCar(vehicleid)
{
switch(GetVehicleModel(vehicleid))
{
case 523,427,528,596,598,597,599,601,497,430: return 1; //checks if the vehicle id is a faction restricted vehicle
}
return 0;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(IsACopCar(vehicleid) && PlayerInfo[playerid][pFaction] == 0 && !ispassenger) //checks if the car is a faction car,and checks if the player is not in a faction or is not a passenger
{
ClearAnimations(playerid);//if they are a civillian and aren't a passenger it will put them out
SendClientMessage(playerid, COLOR_GREY, " You are not a Cop !");//will send them a message telling them only police can access this vehicle
}
return 1;
}
CMD:makeleader(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 4) //Replace this with your player variable
{
new targetid, facid;//establishes a player and a faction id, to be typed in
if(sscanf(params,"ui",targetid, facid)) return SendClientMessage(playerid, COLOR_RED,"/makeleader [id][Faction id]");//if the command is misused it will tell them the correct way to use it
if(targetid != INVALID_PLAYER_ID)//checks if the id you type in is an id that is not connected to the server
{
PlayerInfo[targetid][pFaction] = facid; //sets the players faction to the faction you choose
PlayerInfo[targetid][pFacrank] = 10;//sets their rank to the highest rank
PlayerInfo[targetid][pFacleader] = facid;//sets their leadership to the id of the faction
if(facid == 1)//checks if the factionid typed was 1, and tells them they are the leader of the police below
{
SendClientMessage(targetid,COLOR_CYAN,"You have been made the leader of the police department");
}
if(facid == 2)//checks if the factionid typed was 2, and tells them below, they are the leader of the faction
{
SendClientMessage(targetid,COLOR_CYAN,"You have been made the leader of blank");//change this to the faction name you want
}
}
}
else //if the player is not an admin it will show the below message telling them they are not an admin.
{
SendClientMessage(playerid, COLOR_RED, "Only certan levels of Administration have access to this command.");
}
return 1;
}
if(facid == 2)//checks if the factionid typed was 2, and tells them below, they are the leader of the faction
{
SendClientMessage(targetid,COLOR_CYAN,"You have been made the leader of blank");//change this to the faction name you want
}
CMD:r(playerid, params[]) return cmd_radio(playerid, params);
CMD:radio(playerid, params[])
{
new string[128], text[128], ctext[60], pname[MAX_PLAYER_NAME+1];//establishes a few things needed to tell the players name, rank, and the text he has written.
GetPlayerName(playerid, pname, sizeof(pname));//gets the name of the player using /radio
if(sscanf(params, "s[128]", text)) return SendClientMessage(playerid, 0x46E850FF, "SERVER:{FFFFFF} /r(adio) [text]");//if /r is not used correctly it will tell you the correct way to use it
if(PlayerInfo[playerid][pFaction] == 1)//checks if the player is in the first faction
{
if(PlayerInfo[playerid][pFacrank] == 1){ ctext = "Cadet"; }//all of these check the players rank and
if(PlayerInfo[playerid][pFacrank] == 2){ ctext = "Officer"; }// sets each rank to a specific name
if(PlayerInfo[playerid][pFacrank] == 3){ ctext = "Senior Officer"; }
if(PlayerInfo[playerid][pFacrank] == 4){ ctext = "Corporal"; }
if(PlayerInfo[playerid][pFacrank] == 5){ ctext = "Sergeant"; }
if(PlayerInfo[playerid][pFacrank] == 6){ ctext = "Lieutenant"; }
if(PlayerInfo[playerid][pFacrank] == 7){ ctext = "Captain"; }
if(PlayerInfo[playerid][pFacrank] == 8){ ctext = "Commander"; }
if(PlayerInfo[playerid][pFacrank] == 9){ ctext = "Deputy Chief"; }
if(PlayerInfo[playerid][pFacrank] == 10){ ctext = "Chief"; }
format(string, sizeof(string), "%s %s: %s", ctext, pname, text);
if(PlayerInfo[playerid][pFaction] > 0)//if the player is not in a faction it will not send him any messages
{
SendCopMessage(COLOR_PDRAD, string);//calls a stock below that checks who the /r should be sent to
}
}
if(PlayerInfo[playerid][pFaction] == 2)//checks if the player is in the second faction
{
if(PlayerInfo[playerid][pFacrank] == 1){ ctext = "rank 1 name"; }//all of these check the players rank and
if(PlayerInfo[playerid][pFacrank] == 2){ ctext = "rank 2 name"; }// sets each rank to a specific name
if(PlayerInfo[playerid][pFacrank] == 3){ ctext = "rank 3 name"; }
if(PlayerInfo[playerid][pFacrank] == 4){ ctext = "rank 4 name"; }
if(PlayerInfo[playerid][pFacrank] == 5){ ctext = "rank 5 name"; }
if(PlayerInfo[playerid][pFacrank] == 6){ ctext = "rank 6 name"; }
if(PlayerInfo[playerid][pFacrank] == 7){ ctext = "rank 7 name"; }
if(PlayerInfo[playerid][pFacrank] == 8){ ctext = "rank 8 name"; }
if(PlayerInfo[playerid][pFacrank] == 9){ ctext = "rank 9 name"; }
if(PlayerInfo[playerid][pFacrank] == 10){ ctext = "rank 10 name"; }
format(string, sizeof(string), "%s %s: %s", ctext, pname, text);
if(PlayerInfo[playerid][pFaction] > 0)//if the player is not in a faction it will not send him any messages
{
SendfacnameMessage(COLOR_PDRAD, string);//calls a stock below that checks who the /r should be sent to
}
}
return 1;
}
if(PlayerInfo[playerid][pFaction] == 2)//checks if the player is in the second faction
{
if(PlayerInfo[playerid][pFacrank] == 1){ ctext = "rank 1 name"; }//all of these check the players rank and
if(PlayerInfo[playerid][pFacrank] == 2){ ctext = "rank 2 name"; }// sets each rank to a specific name
if(PlayerInfo[playerid][pFacrank] == 3){ ctext = "rank 3 name"; }
if(PlayerInfo[playerid][pFacrank] == 4){ ctext = "rank 4 name"; }
if(PlayerInfo[playerid][pFacrank] == 5){ ctext = "rank 5 name"; }
if(PlayerInfo[playerid][pFacrank] == 6){ ctext = "rank 6 name"; }
if(PlayerInfo[playerid][pFacrank] == 7){ ctext = "rank 7 name"; }
if(PlayerInfo[playerid][pFacrank] == 8){ ctext = "rank 8 name"; }
if(PlayerInfo[playerid][pFacrank] == 9){ ctext = "rank 9 name"; }
if(PlayerInfo[playerid][pFacrank] == 10){ ctext = "rank 10 name"; }
format(string, sizeof(string), "%s %s: %s", ctext, pname, text);
if(PlayerInfo[playerid][pFaction] > 0)//if the player is not in a faction it will not send him any messages
{
SendfacnameMessage(COLOR_PDRAD, string);//calls a stock below that checks who the /r should be sent to
}
}
stock SendfacnameMessage(col, string[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(PlayerInfo[i][pFaction] == 2)
SendClientMessage(i, col, string); //goes through all the players checking who is and isint in faction 1
}
return 1;
}
This is pretty good and really understable.I'll practice with this.
Thank you sir!. |
CMD:invite(playerid, params[])
{
if(PlayerInfo[playerid][pFacleader] > 0 || PlayerInfo[playerid][pFacrank] >= 5)
{
new tarid, facid;//establishes a player in the server and a faction id for you to type in
if(sscanf(params, "u", tarid)) return SendClientMessage(playerid, COLOR_RED, "{0033cc}FACTION:Използвайте: /invite [playerid]");//if the command is not typed correctly, it will show you the correct way to use the command.
facid = PlayerInfo[playerid][pFaction];//sets the faction the player is being invited to, as the faction the player that is inviting is in.
SetPVarInt(tarid, "invitefac", facid);//saves the invite, to /accept it
SendClientMessage(tarid, COLOR_GREEN, "{0033cc}FACTION:Вие получихте покана за банда/мафия , използвайте /acceptinvite за да я приемете!");//tells you that you have been invited to a faction
}
else //if you're not the correct rank it will display the message below stating that the player is not the rank to invite
{
SendClientMessage(playerid, COLOR_RED, "{0033cc}FACTION:Вие трябва да сте 5 ранг за да може да инвийтвате");
}
return 1;
}
CMD:acceptfaction(playerid, params[])
{
new facid, string[128];//creates a faction id and some text on the players screen
facid = GetPVarInt(playerid, "invitefac");//calls the saved invite from the previous command
PlayerInfo[playerid][pFaction] = facid; //sets the players faction to that of the person inviting.
PlayerInfo[playerid][pFacrank] = 1;//sets the players faction rank to 1
format(string, sizeof(string), "FACTION:Вие приехте предложението за влизане в банда %d", facid);//tells the player they have accepted the faction invite
SendClientMessage(playerid, COLOR_CYAN, string);//shows the above message in the color of CYAN
DeletePVar(playerid, "invitefac");//deletes the saved invite
return 1;
}
my commands..
PHP Code:
|
Its amazing how you made it so... simple!
Pretty sure you can do this in MySQL - but ofc. with some extras ( faction name for an example ) |
CMD:acceptinvite(playerid, params[]) { new facid, string[128];//creates a faction id and some text on the players screen facid = GetPVarInt(playerid, "invitefac");//calls the saved invite from the previous command PlayerInfo[playerid][pFaction] = facid; //sets the players faction to that of the person inviting. PlayerInfo[playerid][pFacrank] = 1;//sets the players faction rank to 1 format(string, sizeof(string), "> You have accepted the invite to faction %d", facid);//tells the player they have accepted the faction invite SendClientMessage(playerid, COLOR_CYAN, string);//shows the above message in the color of CYAN DeletePVar(playerid, "invitefac");//deletes the saved invite return 1; } |
//Under the command if(facid<0) return SendClientMessage(playerid, color,"You have not been invited to any faction."); |