[Solved] Mixed variables.
#1

I have this command:

pawn Код:
CMD:p(playerid, params[])
{
    new
        id,
        SubPar[24],
        string[128];

    if(PlayerInfo[playerid][Level] > 2)
    {
        if(sscanf(params, "u ", id))
        {
            if(strcmp(id, "help", true, 4)) // for /p help...
            {
                SendClientMessage(playerid, SYSTEM_INFO, "Usage: /p [id] [command].");

                if(PlayerInfo[playerid][Level] == 3)
                {
                    // p mods commands
                }
                else if(PlayerInfo[playerid][Level] == 4)
                {
                    // p admins commands
                }
                else if(PlayerInfo[playerid][Level] == 5)
                {
                    //p management commands
                }
                else if(PlayerInfo[playerid][Level] == MAX_LEVEL)
                {
                    //p Owner only comands
                }
            }
            else if(id == INVALID_PLAYER_ID || !IsPlayerConnected(id))
            {
                SendClientMessage(playerid, SYSTEM_DENIAL, "Error: Invalid player ID.");
            }
        }
    }

    else
    {
         //non admins message
    }
    return 1;
}
If I try that an error would appear, because id isn't a string:
pawn Код:
if(strcmp(id, "help", true, 4)) // for /p help...
{
  //help message
}
How to make a variable, an interger and a string at the same time?
Reply
#2

If you want to make the ID as a string and a varibale:

pawn Код:
new SID[4];
format(SID, sizeof(SID), "%d", id);
SID is the string version of ID and ID is the integer.

My question is, why would you want the players ID to be the same as "Help". It wouldn't work either way.
Reply
#3

Quote:
Originally Posted by [HiC
TheKiller ]
If you want to make the ID as a string and a varibale:

pawn Код:
new SID[4];
format(SID, sizeof(SID), "%d", id);
SID is the string version of ID and ID is the integer.

My question is, why would you want the players ID to be the same as "Help". It wouldn't work either way.
Because otherwise you would need to do it like: /p [id] help, being needed to put an id at the moment of using the help command. So I thought /p help would be better than /p 45 help.

Another question:

May I do this?
pawn Код:
format(SubPar, sizeof(SubPar), "%s", id);
if(strcmp(SubPar, "help", true, 4) == 0);
{
  //w/e help does
}
Reply
#4

I got the solution. I must check params instead of coverting a integer into a string, because params has everything what was typed after the command. So I did:

pawn Код:
if(strcmp(params, "help", true) == 0)
{
  // help message.
}
Thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)