Posts: 84
Threads: 21
Joined: Mar 2015
Okay so I want to make a cmd that shows the player the name depends on what he type ! for example /show brug
it shows him that he have Burger so the cmd check from a const that is already written if burg found in any word it types it directly okay for example
Код:
static const
name[][] = {
{!"Medkit" },
{!"Computer" },
{!"Jus" },
{!"Journal" },
{!"Burger" }
}
;
so when the player types /show burg it gives him "Burger" if /show Ju it gives him "Jus" I wish you understand and can help me !
Posts: 84
Threads: 21
Joined: Mar 2015
Quote:
Originally Posted by AjaxM
Continue the sequence i just gave but using what you need! It's simple, the way below:
PHP код:
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
}
}
EDIT ;
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 код:
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;
}
|
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
Posts: 84
Threads: 21
Joined: Mar 2015
Quote:
Originally Posted by X337
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
|
We don't know if the user will write computer or something else in /show so I guess we need a stock for it and that what I want to know
Posts: 84
Threads: 21
Joined: Mar 2015
Posts: 84
Threads: 21
Joined: Mar 2015
Quote:
Originally Posted by Vince
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 код:
FindItemByPartialName(items[][], input[], size = sizeof items)
{
for(new i; i < size; i++)
{
if(!strcmp(items[i], input, true, strlen(input))
{
return i;
}
}
return -1;
}
|
I tried to do something like yours
Код:
stock FindCsByPartialName(input[])
{
for(new i; i < 44; i++)
{
if(strfind(items[i], input, true))
{
return i;
}
}
return -1;
}
But when I'm in game it shows me nothing like an empty string.