CMD problem
#1

How to do as, for example, enter /giverank 0 2.
Example rank:
Number 1 - pInfo[playerid][pMod] = 1;
Number 2 - pInfo[playerid][pAdmin] = 1;

Код:
CMD:giverank(playerid, params[])
{
    if(pInfo[playerid][pAdmin] == 1)
    {
        new string[128], giveplayerid, rank;

        if(sscanf(params, "ud", giveplayerid, rank)) return SendClientMessage(playerid, -1, "USAGE: /giverank [playerid] [Rank (1-2)]");

        if(rank > 6 || rank < 0) { SendClientMessage(playerid, -1, "Don't go below number 0, or above number 6!"); return 1; }

        if(IsPlayerConnected(giveplayerid))
        {
            pInfo[giveplayerid][pAdmin] = rank;
            SendClientMessage(giveplayerid, -1, string);
            format(string, sizeof(string), "You have given %s rank %d.", PlayerName(giveplayerid), rank);
            SendClientMessage(playerid, -1, string);
        }
    }
    else
    {
        SendClientMessage(playerid, -1, "You are not authorized to use that command!");
    }
    return 1;
}
Reply
#2

Use strcmp for that.
Reply
#3

Yes, but there will be an error because it is `new rank[16]` and not `new rank`.
Код:
if(rank > 6 || rank < 0) { SendClientMessage(playerid, -1, "Don't go below number 0, or above number 6!"); return 1; }
Reply
#4

PHP код:
if (rank == 1pInfo[giveplayerid][pMod] = 1;
else if (
rank == 2pInfo[playerid][pAdmin] = 1
Or just use a switch statement.
Reply
#5

//del
Reply
#6

PHP код:
CMD:giverank(playeridparams[])
{
    if(
pInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, -1"You are not authorized to use that command!");
    new 
giveplayeridrank;
    if(
sscanf(params"ud"giveplayeridrank)) return SendClientMessage(playerid, -1"USAGE: /giverank [playerid] [Rank (1-2)]");
    if(!
IsPlayerConnected(giveplayerid)) return SendClientMessage(playerid, -1"There is no such player!");
    switch(
rank)
    {
        case 
1pInfo[giveplayerid][pMod] = 1;
        case 
2..6pInfo[giveplayerid][pAdmin] = rank 1;
        default: 
SendClientMessage(playerid, -1"Don't go below number 0, or above number 6!");
    }
    return 
1;

'rank' is not a string or array in this instance, so it doesn't need you to specify a size. It is an integer and can be a standalone variable.

I'm assuming pAdmin is increased when a number above 1 is entered, so this is the code I've given you. Please change accordingly.
Reply
#7

Okay. I will need it. Thanks!

How to write CMD [/giverank [id] [rank]] /giverank 0 5 is how to make it a message that there is no such rank.

Код:
if(strcmp(rank, "1", true) == 0)
else if(strcmp(rank, "2", true) == 0)
else if(strcmp(rank, "3", true) == 0)
Reply
#8

I literally just gave you the code... just change the 'switch' statement values.
PHP код:
case 
Means rank = 1.
PHP код:
case 2..6 
Means rank = 2, 3, 4, 5 or 6.
PHP код:
default 
Means rank = something else

If you want it to be up to 5, just change 2..6 to 2..5
Reply
#9

Thanks!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)