tmp -
omer5198 - 04.05.2011
is it possible to make tmp = to name... like:
Код:
new tmp[256];
...
...(the command)
...
new option;
option = strval(tmp);
if(option == "f") // this is the "Unknown" part the i am asking about... can i make tmp equals to text?
Re: tmp -
Sascha - 04.05.2011
don't use "strval(tmp)" for that..
strval returns a value / number / integer (1, 2, 3, 4, ................., 10450239 - ya know?^^)...
use:
if(!strcmp(tmp, "f", true)) << set it to "false" if you want it to detect "f" only and not "f" and "F"
hope that helped^^
This forum requires that you wait 120 seconds between posts. Please try again in 26 seconds.
Re: tmp -
omer5198 - 04.05.2011
[QUOTE=Sascha;1192561]don't use "strval(tmp)" for that..
strval returns a value / number / integer (1, 2, 3, 4, ................., 10450239 - ya know?^^)...
use:
if(!strcmp(tmp, "f", true)) << set it to "false" if you want it to detect "f" only and not "f" and "F"
hope that helped^^
This forum requires that you wait 120 seconds between posts. Please try again in 26 seconds.[/ QUOTE]
thx!!! i'll try it... if i'll have any problems i will post them here...
Re: tmp -
omer5198 - 04.05.2011
Quote:
Originally Posted by Sascha
don't use "strval(tmp)" for that..
strval returns a value / number / integer (1, 2, 3, 4, ................., 10450239 - ya know?^^)...
use:
if(!strcmp(tmp, "f", true)) << set it to "false" if you want it to detect "f" only and not "f" and "F"
hope that helped^^
This forum requires that you wait 120 seconds between posts. Please try again in 26 seconds.
|
sorry for double post but... i have a problem... i want that if you type like /choose it will give you optios like:
/choose [option] [answer] and more... - this is no problem but how can i make that after i choose the
/choose option. i will have to type another text?
Re: tmp -
Sascha - 04.05.2011
pawn Код:
new tmp[256], idx;
tmp = strtok(params, idx); //or strtok(cmdtext, idx) depends on the cmd engine you are using (for default sa-mp OnPlayerCommandText use (cmdtext, idx) )
if(!strcmp(tmp, "options", true))
{
.......
}
edit:
if you get an error because of "strtok" add this to your code:
pawn Код:
stock strtok(const string[], &index,seperator=' ')
{
new length = strlen(string);
new offset = index;
new result[128];
while ((index < length) && (string[index] != seperator) && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
if ((index < length) && (string[index] == seperator))
{
index++;
}
return result;
}
Re: tmp -
omer5198 - 04.05.2011
Quote:
Originally Posted by Sascha
pawn Код:
new tmp[256], idx; tmp = strtok(params, idx); //or strtok(cmdtext, idx) depends on the cmd engine you are using (for default sa-mp OnPlayerCommandText use (cmdtext, idx) ) if(!strcmp(tmp, "options", true)) { ....... }
edit:
if you get an error because of "strtok" add this to your code:
pawn Код:
stock strtok(const string[], &index,seperator=' ') { new length = strlen(string); new offset = index; new result[128]; while ((index < length) && (string[index] != seperator) && ((index - offset) < (sizeof(result) - 1))) { result[index - offset] = string[index]; index++; }
result[index - offset] = EOS; if ((index < length) && (string[index] == seperator)) { index++; } return result; }
|
you didn't understand what i've asked you... i did this already... but what should i do if i want the player to write:
/choose option up // excemple
Re: tmp -
Sascha - 04.05.2011
ok I guess I really didn't get you (not even now...)
well here's a more complete example which might help you as I have no clue what you exactly want^^
pawn Код:
if(strcmp("/choose", cmdtext, true, 7) == 0)
{
new tmp[256], idx;
tmp = strtok(cmdtext, idx); //or strtok(cmdtext, idx) depends on the cmd engine you are using (for default sa-mp OnPlayerCommandText use (cmdtext, idx) )
if(!strlen(tmp))
{
SendClientMessage(playerid, 0x999999AA, "/choose [option] [up/down]"); //whatever
}
else
{
if(!strcmp(tmp, "option", true))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, 0x999999AA, "/choose [option] [up/down]");
}
else
{
if(!strcmp(tmp, "up", true))
{
SendClientMessage(playerid, 0x999999AA, "Option Up");
}
else if(!strcmp(tmp, "down", true))
{
SendClientMessage(playerid, 0x999999AA, "Option Down");
}
else
{
SendClientMessage(playerid, 0x999999AA, "/choose [option] [up/down]");
}
}
}
else
{
SendClientMessage(playerid, 0x999999AA, "/choose [option] [up/down]");
}
}
return 1;
}