how to setmember cmd - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: how to setmember cmd (
/showthread.php?tid=442206)
how to setmember cmd -
Xport6050 - 06.06.2013
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
Re: how to setmember cmd -
Lordzy - 06.06.2013
You can use variables for it and if you wish to save it, you can use any type of INI processors or SQL modes.
pawn Код:
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.
}
For the memberlist command, you can use loops and this var to loop it up and show. (Looping tutorials are better!)
pawn Код:
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;
}
The function
ReturnName is just created to return the name directly, here's the stock function of it.
pawn Код:
stock ReturnName(playerid)
{
new Lname[MAX_PLAYER_NAME];
GetPlayerName(playerid, Lname, sizeof(Lname));
return Lname;
}
Not Tested, so if there's mistake; please notify me about it. And some tutorials would help you to understand about these codings well.