SA-MP Forums Archive
Help me in this - 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: Help me in this (/showthread.php?tid=628758)



Help me in this - Krauser123 - 14.02.2017

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 !


Re: Help me in this - AjaxM - 14.02.2017

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;




Re: Help me in this - Krauser123 - 14.02.2017

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


Re: Help me in this - AjaxM - 14.02.2017

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




Re: Help me in this - X337 - 14.02.2017

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



Re: Help me in this - Dayrion - 14.02.2017

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


Re: Help me in this - Krauser123 - 14.02.2017

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


Re: Help me in this - Krauser123 - 15.02.2017

Any solution :/


Re: Help me in this - Vince - 15.02.2017

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;




Re: Help me in this - Krauser123 - 15.02.2017

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.