06.06.2013, 13:05
hey all how can i make /setmember cmd it need rank upto 7 and i need one more cmd /memberlist to show that who where online members and with rank pls help me i will give you +1 rep
new pRank[MAX_PLAYERS]; //A rank variable for players.
public OnPlayerConnect(playerid)
{
pRank[playerid] = 0; //Set it to 0 or else the previous player's rank will be for the new connected player too.
return 1;
}
CMD:setrank(playerid, params[])
{
//You can split the parameters using sscanf2. Check out the sscanf2 tutorials for more info about it.
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to login as RCON admin to use this command!"); //To ensure that admins can only use it, else you can uncomment this line or replace with your variables.
new p2, rank;
if(sscanf(params, "ri", p2, rank)) return SendClientMessage(playerid, -1, "Usage: /setrank [playerid] [rank]");
if(p2 == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "This player ID is not VALID!");
if(!IsPlayerConnected(p2)) return SendClientMessage(playerid, -1, "This player is not connected!");
if(rank > 7 || rank < 0) return SendClientMessage(playerid, -1, "Invalid rank. Ranks from 1 - 7 only!"); //if rank > 7 (rank is greater than 7) or if rank < 0 (rank is lesser than 0); then it messages that it's not valid rank!
if(rank == pRank[p2]) return SendClientMessage(playerid, -1, "Player is already in this rank!"); //If rank is the same value of other player's rank, it will send as it's already the other's rank.
//In case of messages / notifications:
new string[128];
format(string, sizeof(string), "%s (ID: %d) has set your rank to %d", ReturnName(playerid), playerid, rank);
SendClientMessage(p2, -1, string);
format(string, sizeof(string), "You have set %s's (ID: %d) rank to %d", ReturnName(p2), p2, rank);
SendClientMessage(playerid, -1, string);
pRank[p2] = rank; //Sets the rank here!
return 1; //Returns the command.
}
CMD:memberlist(playerid, params[])
{
new string[128];
SendClientMessage(playerid, -1, "=================User rankings==================");
for(new i; i< GetMaxPlayers(); i++)
{
if(!IsPlayerConnected(i)) continue;
if(pRank[i] >= 1)
{
format(string, sizeof(string), "%s (ID:%d) - Rank: %d\n", ReturnName(i), i, pRank[i]);
SendClientMessage(playerid, -1, string);
}
}
return 1;
}
stock ReturnName(playerid)
{
new Lname[MAX_PLAYER_NAME];
GetPlayerName(playerid, Lname, sizeof(Lname));
return Lname;
}