static const name[][] = { {!"Medkit" }, {!"Computer" }, {!"Jus" }, {!"Journal" }, {!"Burger" } } ;
public OnPlayerText(playerid, text[])
{
if (!strcmp(text, "show burg", true))
{
// Code here
return 0; // Not allowing him to display the message on the open chat
}
}
CMD:test(playerid, params[])
{
new str[16];
if(sscanf(params, "s[16]", str)) return SendClientMessage(playerid, -1, "Usage: /test [params]");
if (!strcmp(str, "burg", true))
{
// Code here
}
return 1;
}
Continue the sequence i just gave but using what you need! It's simple, the way below:
PHP код:
Sorry, i didn't read what you wanted quite carefully. Below is maybe what you need. Also, the one with OnPlayerText seems to be more stylish but it's your choice! BELOW CODE IS UNTESTED! PHP код:
|
Thanks for your help, But it's not just about typing burg the player may type /show bu and he gets "Burger" and there is something else except burger like Journal
|
CMD:test(playerid, params[])
{
new str[16];
if(sscanf(params, "s[16]", str)) return SendClientMessage(playerid, -1, "Usage: /test [params]");
if (!strcmp(str, "burg", true))
{
// Code here
}
else if (!strcmp(str, "jour", true)) // Journal
{
// Code here
}
// Continue
return 1;
}
static const name[][] = { {!"Medkit" }, {!"Computer" }, {!"Jus" }, {!"Journal" }, {!"Burger" } } ; new msg[56]; format(msg, 56, "You have %d ", 2); strcat(msg, name[1]); // msg = You have 2 Computer // or... new itemname[10]; strunpack(itemname, name[1]); format(msg, 56, "You have %d %s", 2, itemname); // msg = You have 2 Computer
static const
name[][] = {
{!"Medkit" },
{!"Computer" },
{!"Jus" },
{!"Journal" },
{!"Burger" }
}
You have to use strcat / strunpack for packed string.
Example: Код:
static const name[][] = { {!"Medkit" }, {!"Computer" }, {!"Jus" }, {!"Journal" }, {!"Burger" } } ; new msg[56]; format(msg, 56, "You have %d ", 2); strcat(msg, name[1]); // msg = You have 2 Computer // or... new itemname[10]; strunpack(itemname, name[1]); format(msg, 56, "You have %d %s", 2, itemname); // msg = You have 2 Computer |
I already told you to continue the sequence. Repeat the codes (strcmp) but change the "burg" to "journal" and things that you need!
|
FindItemByPartialName(items[][], input[], size = sizeof items)
{
for(new i; i < size; i++)
{
if(!strcmp(items[i], input, true, strlen(input))
{
return i;
}
}
return -1;
}
If he was to add a hundred items would he have to repeat the same code a hundred times? That would be ridiculous. Use some logic and reason.
Try something like this: PHP код:
|
stock FindCsByPartialName(input[]) { for(new i; i < 44; i++) { if(strfind(items[i], input, true)) { return i; } } return -1; }