Help me in this
#1

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 !
Reply
#2

Continue the sequence i just gave but using what you need! It's simple, the way below:
PHP код:
public OnPlayerText(playeridtext[])
{
    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(playeridparams[])
{
    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;

Reply
#3

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(playeridtext[])
{
    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(playeridparams[])
{
    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
Reply
#4

Quote:
Originally Posted by Krauser123
Посмотреть сообщение
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
I already told you to continue the sequence. Repeat the codes (strcmp) but change the "burg" to "journal" and things that you need!

Example Code:

PHP код:
CMD:test(playeridparams[]) 

    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

Reply
#5

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
Reply
#6

Why do you have '!' in :
PHP код:
static const
    
name[][] = {
        {!
"Medkit" },
        {!
"Computer" },
        {!
"Jus" },
        {!
"Journal" },
        {!
"Burger" }
    } 
?
Reply
#7

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
Reply
#8

Any solution :/
Reply
#9

Quote:
Originally Posted by AjaxM
Посмотреть сообщение
I already told you to continue the sequence. Repeat the codes (strcmp) but change the "burg" to "journal" and things that you need!
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 
isizei++)
    {
        if(!
strcmp(items[i], inputtruestrlen(input))
        {
            return 
i;
        }
    }
    return -
1;

Reply
#10

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 
isizei++)
    {
        if(!
strcmp(items[i], inputtruestrlen(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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)