Command: "/something numer string1 string2"
#1

Hey guys.
I need to make command with one number and two strings.
for example:
Код:
/add 0 Text1 Text2
I dont know how to do it so please help

Thanks.
Reply
#2

One solution:

Using sscanf and zcmd:

https://sampwiki.blast.hk/wiki/Sscanf
https://sampwiki.blast.hk/wiki/Fast_Commands#zcmd
Reply
#3

Ok but how command will look like?
Reply
#4

You can simply use Split:

pawn Код:
stock bool:Split(const string[], strdest[][], destsize = sizeof(strdest), separator = 32)
{
new lenght = strlen(string);
new index;
if(!lenght || !destsize || !separator) return false;
for(new i; i<destsize; i++)
{
while(index < lenght && string[index] == separator) index++;
new offset = index;
if(i < destsize - 1) while(index < lenght && string[index] != separator) strdest[i][index - offset] = string[index], index++;
else while(index <= lenght) strdest[i][index - offset] = string[index], index++;
strdest[i][index - offset] = 0;
}
return true;
}
Here is the usage:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[3][50];
Split(cmdtext, cmd, sizeof(cmd), 32);
if(!strcmp(cmd[0], "/command", true))
{
if(!strlen(cmd[2])) return SendClientMessage(...);
DoSomething();
return true;
}
return false;
}
Do you understand?
Reply
#5

Honestly wouldn`t do it that way.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)