#include <a_samp>
#define MAX_RANKS 11
enum E_RANKDATA
{
RankName[24], // This is to hold our rank name, for example: Privates, Corporal, Lieutenant etc...
RankScore, // This one holds the score that is required to reach certain rank. For example: You will need 50 score to reach rank 1
Float: RankArmour // This is optional, i am using this for the tutorial only (Useful for TDM servers). You can ignore it if you want. This holds the amount of armour player should get at certain ranks.
// For example: 20 percent armour at rank 2, 30 percent at rank 3 and so on...
}
new
g_RankInfo[MAX_RANKS][E_RANKDATA] = {
// Remember we had rank name, rank score and armour data saved in our enumerator? Those data will be held like this in the variable. You can change the scores, rank name to however you like.
// Rank name Score Armour
{"Private", 0, 0.0},
{"Corporal", 50, 10.0},
{"Sergeant", 100, 20.0},
{"Master Sergeant", 150, 30.0},
{"Lieutenant", 200, 40.0},
{"Major", 500, 50.0},
{"Captain", 1000, 60.0},
{"Brigadier", 1500, 70.0},
{"General", 2500, 80.0},
{"Filed Marshal", 5000, 90.0},
{"Master of War", 10000, 100.0}
};
new Text3D: g_RankLabel[MAX_PLAYERS]; // This is a 3D text label to display the rank name on top of the player's head, we will be creating this later
new g_PlayerRank[MAX_PLAYERS]; // This holds the rank id for the player.
// This function updates the player's rank. You can call this anywhere wherever you want to update the player's rank
UpdateRank(playerid)
{
new
i;
for (i = MAX_RANKS - 1; i >= 0; i--)
{
if (GetPlayerScore(playerid) >= g_RankInfo[i][RankScore])
{
break;
}
}
g_PlayerRank[playerid] = i;
}
public OnPlayerConnect(playerid)
{
g_PlayerRank[playerid] = 0; // Clearing the player rank to make sure other player that connects won't get the rank of the previous player that disconnected
g_RankLabel[playerid] = Create3DTextLabel(" ", 0xFFFFFF55, 30.0, 40.0, 50.0, 30.0, 0, 1); // Creating the 3DText label
Attach3DTextLabelToPlayer(g_RankLabel[playerid], playerid, 0.0, 0.0, 0.5); // Attaching the text label to player, making the Z offset 0.5 will put the text on top of the player's head
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
Delete3DTextLabel(g_RankLabel[playerid]); // Deleting the label so that it won't mix up with other player that connects with the same id
return 1;
}
public OnPlayerSpawn(playerid)
{
UpdateRank(playerid); // Updating player's rank to make sure g_PlayerRank variable has the player's current rank stored
new
string[64], // Just a string to send a message to let the player know what's his current rank is
rankstring[24], // String to fetch the rank name
rankid // To hold the player's rank id
;
rankid = g_PlayerRank[playerid]; // Storing the player's rank into the rankid variable
format(rankstring, sizeof(rankstring), "%s", g_RankInfo[rankid][RankName]); // Formatting the rankstring to store the player's rank
Update3DTextLabelText(g_RankLabel[playerid], GetPlayerColor(playerid), rankstring); // Adding the formatted rank name into the 3D text label with the same color that the player have
format(string, sizeof(string), "Your current rank is %i (%s) | Bonus armour: %0.2f", rankid, g_RankInfo[rankid][RankName], g_RankInfo[rankid][RankArmour]); // Let the player know his current rank with how much bonus armour he can get
SendClientMessage(playerid, -1, string);
SetPlayerArmour(playerid, g_RankInfo[rankid][RankArmour]); // Setting armour depending on player's rank
return 1;
}
format(string, sizeof(string), "Your current rank is %i (%s) | Bonus armour: %0.2F", rankid, g_RankInfo[rankid][RankName], g_RankInfo[rankid][RankArmour]); // Let the player know his current rank with how much bonus armour he can get SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "Your current rank is %i (%s) | Bonus armour: %0.2f", rankid, g_RankInfo[rankid][RankName], g_RankInfo[rankid][RankArmour]); // Let the player know his current rank with how much bonus armour he can get SendClientMessage(playerid, -1, string);
Good work.
and make this Код:
format(string, sizeof(string), "Your current rank is %i (%s) | Bonus armour: %0.2F", rankid, g_RankInfo[rankid][RankName], g_RankInfo[rankid][RankArmour]); // Let the player know his current rank with how much bonus armour he can get SendClientMessage(playerid, -1, string); Код:
format(string, sizeof(string), "Your current rank is %i (%s) | Bonus armour: %0.2f", rankid, g_RankInfo[rankid][RankName], g_RankInfo[rankid][RankArmour]); // Let the player know his current rank with how much bonus armour he can get SendClientMessage(playerid, -1, string); and why don't you update it when player get those amount of score that are needed for the new rank? its updating when the Player spawn. |