Cap variable value
#1

How can i cap a variables value? E.g make the variables limit 5, For example

pawn Код:
COMMAND:finvitelspd(playerid, params[])
{
    if(PlayerInfo[pLSPD][playerid] != 5)
    {
        new toplayerid, // the player we want to make SA-PD
            rank; // extracting player's ID and rank from params
        if (!sscanf(params, "ui", toplayerid, rank))
        {
          if (toplayerid != INVALID_PLAYER_ID)
          {
            PlayerInfo[pLSPD][toplayerid] = rank;
            new
            message[40];
            format(message, sizeof(message), "You were set rank %i By the SA-PD Leader.!", rank);
            SendClientMessage(toplayerid, 0x00FF00FF, message);
          }
          else SendClientMessage(playerid, 0xFF0000FF, "That player is not connected");
        }
        else SendClientMessage(playerid, 0xFF0000FF, "Usage: /finvite <playerid> <rank>");
    }
    else SendClientMessage(playerid, 0xFF0000FF, "Only the SA-PD Leader can use this command!");
    return 1;
}
This command will increase the pLSPD variable to whatever was entered in the command params, I want it so if they type /finvitelspd 1 3

And their rank is already 4, they cant because it will exceed the variable value of 5? If that makes sense...

If need more details please comment

Thanks in advance
Reply
#2

Well you are using
PlayerInfo[pLSPD][toplayerid] = rank;
So if you use /finvitelspd 1 3
the rank will be 3 not 7, because it overwrites the old data.
If you want players to not be able to use /finvitelspd 1 6 or higher, you should put a
pawn Код:
if(rank > 5) return SendPlayerMessage(playerid,-1,"Invalid rank amount.");
line above
PlayerInfo[pLSPD][toplayerid] = rank;

if you want it to increase the rank you should use
pawn Код:
PlayerInfo[pLSPD][toplayerid] += rank;
instead
pawn Код:
PlayerInfo[pLSPD][toplayerid] = rank;
And add a line above it like,
pawn Код:
if(PlayerInfo[pLSPD][toplayerid]+rank > 5) return   SendPlayerMessage(playerid,-1,"Invalid rank amount.");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)