PDA

View Full Version : Help me in this


Krauser123
14/02/2017, 04:11 PM
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 !

AjaxM
14/02/2017, 04:16 PM
Continue the sequence i just gave but using what you need! It's simple, the way below:

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!


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;
}

Krauser123
14/02/2017, 04:38 PM
Continue the sequence i just gave but using what you need! It's simple, the way below:

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!


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

AjaxM
14/02/2017, 04:40 PM
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:


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;
}

X337
14/02/2017, 04:57 PM
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

Dayrion
14/02/2017, 05:58 PM
Why do you have '!' in :
static const
name[][] = {
{!"Medkit" },
{!"Computer" },
{!"Jus" },
{!"Journal" },
{!"Burger" }
}?

Krauser123
14/02/2017, 06:37 PM
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

Krauser123
15/02/2017, 09:41 AM
Any solution :/

Vince
15/02/2017, 10:35 AM
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:

FindItemByPartialName(items[][], input[], size = sizeof items)
{
for(new i; i < size; i++)
{
if(!strcmp(items[i], input, true, strlen(input))
{
return i;
}
}
return -1;
}

Krauser123
15/02/2017, 01:47 PM
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:

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.

X337
15/02/2017, 01:59 PM
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.

Show us the code where you use "FindCsByPartialName" function.

Krauser123
15/02/2017, 02:07 PM
Show us the code where you use "FindCsByPartialName" function.

Here we go

CMD:showcs(playerid, params[])
{
new csname[28];
if(sscanf(params, "s[28]", csname))
return SendClientMessage(playerid, -1, "Usage: /showcs [fulltraitname]");


new pSheet:csenum = GetSheetEnum(csname);
if(csenum == pSheet:-1)
return SendClientMessage(playerid, COLOR_RED, "ERROR: Invalid trait name");

new fmt[128];
format(fmt, sizeof(fmt), "%s %d/5. ((%s))", FindCsByPartialName(csname), PlayerSheet[playerid][csenum], GetPlayerNameEx(playerid));
ProxDetector(30.0, playerid, fmt, COLOR_BP,COLOR_BP,COLOR_BP,COLOR_BP,COLOR_BP);
return 1;
}

X337
15/02/2017, 02:11 PM
CMD:showcs(playerid, params[])
{
new csname[28];
if(sscanf(params, "s[28]", csname))
return SendClientMessage(playerid, -1, "Usage: /showcs [fulltraitname]");

new pSheet:csenum = GetSheetEnum(csname);
if(csenum == pSheet:-1)
return SendClientMessage(playerid, COLOR_RED, "ERROR: Invalid trait name");

new fmt[128], index = FindCsByPartialName(csname); // index = Get index of itemname
if(index != -1) // Make a check to prevent runtime error
{
strunpack(fmt, name[index]); // Unpacks packed string "name" to fmt
format(fmt, sizeof(fmt), "%s %d/5. ((%s))", fmt, PlayerSheet[playerid][csenum], GetPlayerNameEx(playerid));
ProxDetector(30.0, playerid, fmt, COLOR_BP,COLOR_BP,COLOR_BP,COLOR_BP,COLOR_BP);
}
return 1;
}

Krauser123
15/02/2017, 02:22 PM
CMD:showcs(playerid, params[])
{
new csname[28];
if(sscanf(params, "s[28]", csname))
return SendClientMessage(playerid, -1, "Usage: /showcs [fulltraitname]");

new pSheet:csenum = GetSheetEnum(csname);
if(csenum == pSheet:-1)
return SendClientMessage(playerid, COLOR_RED, "ERROR: Invalid trait name");

new fmt[128], index = FindCsByPartialName(csname); // index = Get index of itemname
if(index != -1) // Make a check to prevent runtime error
{
strunpack(fmt, name[index]); // Unpacks packed string "name" to fmt
format(fmt, sizeof(fmt), "%s %d/5. ((%s))", fmt, PlayerSheet[playerid][csenum], GetPlayerNameEx(playerid));
ProxDetector(30.0, playerid, fmt, COLOR_BP,COLOR_BP,COLOR_BP,COLOR_BP,COLOR_BP);
}
return 1;
}


Okay that's fine but there's a problem !! it gives a different name for example if I do /show burg it gives me Journal and Journ it gives me Burger...