SA-MP Forums Archive
Command - 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: Command (/showthread.php?tid=487028)



Command - cnoopers - 11.01.2014

Look. When I apply this cmd(with argument or not), pops up error for bad command. What's wrong?
Код:
if(!strcmp(cmdtext, "/p", true))
{
    new option[7];
    if(sscanf(cmdtext, "s[7]", option)) return SendClientMessage(playerid, -1, "Użyj: /p [szukaj/lista]."); //Usage: /p [find/list]    
if(strcmp(option,"szukaj",true) == 0)
    {
        // code..
    }
    else if(strcmp(option,"lista",true) == 0)
    {
        new dialog[512], item, amount, idx;
        while(GetPlayerItems(playerid, idx, item, amount))
        {
            format(dialog, 512, "%s%d x %s (ID:%d)\n", dialog, amount, GetItemName(item), item);
        }
        ShowPlayerDialog(playerid, DIALOG_ITEMSGUI, DIALOG_STYLE_LIST, "Przedmioty", dialog, "Wybierz", "Zamknij");
    }
    else SendClientMessage(playerid, -1, "Niepoprawna opcja."); //Bad Option
    return 1;
	}

//Down of script
	return ShowPlayerDialog(playerid, DIALOG_CMDBAD, DIALOG_STYLE_MSGBOX, "Błąd!", "Nie ma takiej komendy!", "OK", ""); //Thats pops, this is message if bad cmd
}



Re: Command - cnoopers - 11.01.2014

refresh.
optional who can change here strcmp to zcmd, right? have to work.


Re: Command - AliveBG - 11.01.2014

Where did you put it? Exactly after OnPlayerCommandText?
If that's on right place, try to change
PHP код:
if(!strcmp(cmdtext"/p"true)) 
to
PHP код:
if(!strcmp(cmd"/p"true)) 
and add at the top of OnPlayerCommandText one
PHP код:
new cmd[64]; 



Re: Command - Konstantinos - 11.01.2014

For ZCMD:
pawn Код:
CMD:p(playerid, params[])
{
    new option[7];
    if(sscanf(params, "s[7]", option)) return SendClientMessage(playerid, -1, "Użyj: /p [szukaj/lista]."); //Usage: /p [find/list]"); 
    if(strcmp(option,"szukaj",true) == 0)
    {
        // code..
    }
    else if(strcmp(option,"lista",true) == 0)
    {
        new dialog[512], item, amount, idx;
        while(GetPlayerItems(playerid, idx, item, amount))
        {
            format(dialog, 512, "%s%d x %s (ID:%d)\n", dialog, amount, GetItemName(item), item);
        }
        ShowPlayerDialog(playerid, DIALOG_ITEMSGUI, DIALOG_STYLE_LIST, "Przedmioty", dialog, "Wybierz", "Zamknij");
    }
    else SendClientMessage(playerid, -1, "Niepoprawna opcja."); //Bad Option
    return 1;
}
The "bad command" (basically unknown command) is displayed when you type "/p lista"? Maybe, there's something wrong with the stock and cause run time errors. In that case, it returns 0 and the command not found message is being displayed.


Re: Command - 1FreeHost - 11.01.2014

What language is this i don't understand.


Re: Command - cnoopers - 11.01.2014

Quote:
Originally Posted by 1FreeHost
Посмотреть сообщение
What language is this i don't understand.
Polish

Translate for you:
Код:
CMD:p(playerid, params[])
{
    new option[7];
    if(sscanf(params, "s[7]", option)) return SendClientMessage(playerid, -1, "Usage: /items [find/list].");
    if(strcmp(option,"find",true) == 0)
    {
        // code..
    }
    else if(strcmp(option,"list",true) == 0)
    {
        new dialog[512], item, amount, idx;
        while(GetPlayerItems(playerid, idx, item, amount))
        {
            format(dialog, 512, "%s%d x %s (ID:%d)\n", dialog, amount, GetItemName(item), item);
        }
        ShowPlayerDialog(playerid, DIALOG_ITEMSGUI, DIALOG_STYLE_LIST, "Items", dialog, "Select", "Close");
    }
    else SendClientMessage(playerid, -1, "Bad option");
    return 1;
}



Re: Command - cnoopers - 11.01.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
For ZCMD:
pawn Код:
CMD:p(playerid, params[])
{
    new option[7];
    if(sscanf(params, "s[7]", option)) return SendClientMessage(playerid, -1, "Usage: /items [find/list].");
    if(strcmp(option,"find",true) == 0)
    {
        // code..
    }
    else if(strcmp(option,"list",true) == 0)
    {
        new dialog[512], item, amount, idx;
        while(GetPlayerItems(playerid, idx, item, amount))
        {
            format(dialog, 512, "%s%d x %s (ID:%d)\n", dialog, amount, GetItemName(item), item);
        }
        ShowPlayerDialog(playerid, DIALOG_ITEMSGUI, DIALOG_STYLE_LIST, "Items", dialog, "Select", "Close");
    }
    else SendClientMessage(playerid, -1, "Bad option");
    return 1;
}
The "bad command" (basically unknown command) is displayed when you type "/p lista"? Maybe, there's something wrong with the stock and cause run time errors. In that case, it returns 0 and the command not found message is being displayed.
Commands parameters still not work.


Re: Command - cnoopers - 11.01.2014

bump


Respuesta: Command - Stront - 11.01.2014

Код:
CMD:p(playerid, params[])
{
    new option[7];
    if(sscanf(params, "s[7]", option)) return SendClientMessage(playerid, -1, "Usage: /items [find/list].");
    if(strcmp(option,"find",true) == 0)
    {
        // code..
    }
    else if(strcmp(option,"list",true) == 0)
    {
        new dialog[512], item, amount, idx;
        while(GetPlayerItems(playerid, idx, item, amount)) // CHECK THIS FUNCTION, MAYBE RETURNS 0 OR SOMETHING.
        {
            format(dialog, 512, "%s%d x %s (ID:%d)\n", dialog, amount, GetItemName(item), item);
        }
        ShowPlayerDialog(playerid, DIALOG_ITEMSGUI, DIALOG_STYLE_LIST, "Items", dialog, "Select", "Close"); // CHECK FOR VALID ID.
    }
    else SendClientMessage(playerid, -1, "Bad option");
    return 1;
}
Check that the function GetPlayerItems and the dialogid returns a valid id. And I also recommend you not to put else just before return 1;

You can delete that else or put it at the beginning with a different syntax, for example, if(strcmp(...) != 0 && strcmp(...) != 0) return SOMETHING;