Returns as Unknown Command
#1

EDIT: MAY LOOK UN-INDENTED BUT IT IS INTENTED

Hi, Im making an RP,
And im making a pilot school, Ive done the mapicon ect i just need the cmds,
I have done an /requestland, That returns as, Usage: /requestland [ls/sf/lv]
But when i say /requestland ls, That returns as: Unknown Command,
And it shouldnt

MyCode:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new idx;
    if(strcmp(cmdtext, "/requestland", true) == 0)
    {
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' '))
        {
            idx++;
        }
        new offset = idx;
        new result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
        {
            result[idx - offset] = cmdtext[idx];
            idx++;
        }
        result[idx - offset] = EOS;
        if(!strlen(result))
        {
            SendClientMessage(playerid, COLOR_GREY, "USAGE: /requestland [ls/sf/lv]");
            return 1;
        }
        if(!strcmp(result,"ls",true))
        {
        SendClientMessageToAll(COLOR_GREY, "%s to LS ATC, %s is requesting landing.");
        }
        else if(!strcmp(result,"sf",true))
        {
            SendClientMessageToAll(COLOR_GREY, "%s to SF ATC, %s is requesting landing.");
        }
        else if(!strcmp(result,"lv",true))
        {
            SendClientMessageToAll(COLOR_GREY, "%s to LV ATC, %s is requesting landing.");
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREY, "USAGE: /requestland [ls/sf/lv]");
        }
        return 1;
    }
    if(strcmp(cmdtext, "/runwaycheck", true) == 0)
    {
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' '))
        {
            idx++;
        }
        new offset = idx;
        new result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
        {
            result[idx - offset] = cmdtext[idx];
            idx++;
        }
        result[idx - offset] = EOS;
        if(!strlen(result))
        {
            SendClientMessage(playerid, COLOR_GREY, "USAGE: /runwaycheck [ls/sf/lv]");
            return 1;
        }
        if(!strcmp(result,"ls",true))
        {
        SendClientMessageToAll(COLOR_GREY, "%s to LS ATC, %s is requesting runway clearance.");
        }
        else if(!strcmp(result,"sf",true))
        {
            SendClientMessageToAll(COLOR_GREY, "%s to SF ATC, %s is requesting runway clearance.");
        }
        else if(!strcmp(result,"lv",true))
        {
            SendClientMessageToAll(COLOR_GREY, "%s to LV ATC, %s is requesting runway clearance.");
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREY, "USAGE: /runwaycheck [ls/sf/lv]");
        }
        return 1;
    }

    return 0;
      }
     
stock strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Compiles fine.
Reply
#2

Shitty way of getting command parameters.
Reply
#3

Quote:

SendClientMessageToAll(COLOR_GREY, "%s to LS ATC, %s is requesting landing.");

And all else:

You need to create a format(string, sizeof(string), "%s to LS ATC, %s is requesting landing.", blah blah);
Then add it to SendClientMessageToAll.

So it should look like this:

pawn Код:
new string[128], sendername[MAX_PLAYER_NAME];
GetPlayerName(playerid, sendername, sizeof sendername);
format(string, sizeof(string), "%s to LS ATC, %s is requesting landing.", sendername);
SendClientMessageToAll(COLOR_GREY, string);
Correct me if I'm wrong or missed something...
Reply
#4

Quote:
Originally Posted by SpiderPork
Quote:

SendClientMessageToAll(COLOR_GREY, "%s to LS ATC, %s is requesting landing.");

And all else:

You need to create a format(string, sizeof(string), "%s to LS ATC, %s is requesting landing.", blah blah);
Then add it to SendClientMessageToAll.

So it should look like this:

pawn Код:
new string[128], sendername[MAX_PLAYER_NAME];
GetPlayerName(playerid, sendername, sizeof sendername);
format(string, sizeof(string), "%s to LS ATC, %s is requesting landing.", sendername);
SendClientMessageToAll(COLOR_GREY, string);
Correct me if I'm wrong or missed something...
Ahh yes how foolish i had these on my old commands,
Im losing my memory!! lol
Reply
#5

pawn Код:
new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' '))
        {
            idx++;
        }
        new offset = idx;
        new result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
        {
            result[idx - offset] = cmdtext[idx];
            idx++;
        }
        result[idx - offset] = EOS;
        if(!strlen(result))
        {
            SendClientMessage(playerid, COLOR_GREY, "USAGE: /runwaycheck [ls/sf/lv]");
            return 1;
        }
is the same as
pawn Код:
new tmpstr[5];
format(tmpstr,sizeof(tmpstr),"%s",cmdtext[strlen("/command")+1]);
if(!strlen(tmpstr))
{
    SendClientMessage(playerid, COLOR_GREY, "USAGE: /runwaycheck [ls/sf/lv]");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)