19.02.2014, 21:55
(
Последний раз редактировалось MattTucker; 19.02.2014 в 22:00.
Причина: Explaining
)
pawn Код:
new finvited[MAX_PLAYERS]; // To store the player's ID
new fnumber[MAX_PLAYERS]; // For storing the faction number that he was invited to join
new finviter[MAX_PLAYERS]; // To send a client message for him to tell that the player accepted his invite
// All of the lines above can be placed ontop of the script - not the very top like after the enums.
CMD:finvite(playerid,params[])
{
new factionid,targetid, targetname[24], playername[24], string[128]; // Why not creating all of the "new"s here? :D
switch(PlayerInfo[playerid][Faction])
{
case 1: // Switch is faster than "if"
{
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad! Use /acceptfaction", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
// pInfo[targetid][Faction] = 1; Instead of those two lines we will get store some variables for use in other commands
// pInfo[targetid][Rank] = 1; (I explain better with commands)
finvited[targetid] = targetid;
fnumber[targetid] = 1;
}
case 2:
{
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
finvited[targetid] = targetid;
fnumber[targetid] = 2;
}
case 3:
{
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
finvited[targetid] = targetid;
fnumber[targetid] = 3;
}
case 4:
{
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
finvited[targetid] = targetid;
fnumber[targetid] = 4;
}
}
return 1; //Returns a value
}
CMD:acceptfaction(playerid, params[])
{
new string[100], name[MAX_PLAYER_NAME], name1[MAX_PLAYER_NAME]; // you can use this to make sure it's all working well
if(finvite[playerid] > -1) // Normally in any kind of server the player ids start from 0 - 1 - 2 - 3 -4 so on
{
GetPlayerName(finviter, name, sizeof(name));
GetPlayerName(finvited, name1, sizeof(name1));
PlayerInfo[playerid][Faction] = fnumber;
format(string, sizeof(string), "You have accepted %s request to join faction number %d",name, fnumber);
SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "%s has accepted your invite to join your faction!", name1);
SendClientMessage(finviter, -1, string);
}
return 1;
}
CMD:fkick(playerid, params[]) //Format to create a command
{ //Open bracket
new id, string[128];
if(sscanf(params,"u",id)) return SendClientMessage(playerid,COLOR_RED,"Usage: /fkick [playerid]");
// I moved the sscanf line to above the inner code to be able to compare the targetid's faction and the playerid's faction
// They are equal, the player gets kicked
if(pInfo[playerid][Faction] == PlayerInfo[id][Faction] && pInfo[playerid][Rank] == 6)
{
SendClientMessage(id,COLOR_RED,"You have been kicked from RAF squad!");
format(string,sizeof(string),"You have kicked %s(%d) from the squad",GetName(id),id);
SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
pInfo[id][Faction] = 0;
pInfo[id][Rank] = 0;
}
else
{
SendClientMessage(playerid, -1, "Player is not in you faction!");
return 1;
}
return 1;
} //Closed
EDIT: I have placed for you all commands /fkick /finvite /acceptfaction and some explaination inside the code and changed the 'if' statements as 'switch' is faster.

