Posts: 536
Threads: 81
Joined: Mar 2017
Reputation:
0
Hello guys how can I create command /house setinterior [InteriorID] using if(strcmp)... I want to be SPACE between house and setinterior, but if I check it is as if(strcmp(cmdtext, "/house setinterior", true) == 0) the [InteriorID] is not working, so the problem is because of the space, I know, but can anybody tell me how can I make it?
Thanks!
Posts: 1,266
Threads: 6
Joined: Oct 2014
you can use strfind instead and check if index equal to 0 ->
PHP код:
if(strfind(cmdtext, "/house setinterior", true) == 0)
also you can use sscanf so it would store a string, string and integer, first string will be the cmd, second the order [ setinterior ] and third the id.
Posts: 536
Threads: 81
Joined: Mar 2017
Reputation:
0
Okay, but how can I use it now:
new InteriorType[32];
strmid(InteriorType, tmp, 0, sizeof(InteriorType), sizeof(InteriorType));
if(strcmp(InteriorType, "Small", true) == 0)
{
....
Posts: 1,266
Threads: 6
Joined: Oct 2014
Posts: 536
Threads: 81
Joined: Mar 2017
Reputation:
0
I'm not using sscanf, can you give me it with no using sscanf?
Posts: 1,266
Threads: 6
Joined: Oct 2014
It will be hard, are you ok with it being hard?
also what command processor are you using? if none mind using zcmd?
Posts: 536
Threads: 81
Joined: Mar 2017
Reputation:
0
new cmd[256], tmp[256], idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/house create", true) == 0)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SCM(playerid,COLOR_ERROR,"Usage: /house create [InteriorType] [Price]");
}
new House[32];
strmid(House, tmp, 0, sizeof(House), sizeof(House));
if(strcmp(House, "Small1", true) == 0)
{
//my code
}
}
Posts: 1,266
Threads: 6
Joined: Oct 2014
well, if you use zcmd and sscanf it will be that easy:
PHP код:
CMD:house(playerid, params[])
{
new action[7], interiortype[11], price;
if(sscanf(params,"s[6]s[10]i", action, interiortype, price))
{
if(strcmp(interiortype, "Small1", true) == 0)
{
//my code
}
}
else
{
SCM(playerid, COLOR_ERROR,"Usage: /house create [InteriorType] [Price]");
}
}
but with your code it will need to be
PHP код:
new cmd[256], tmp[256], idx;
cmd = strtok(cmdtext, idx);
if(strfind(cmd, "/house create", true) == 0) // check if /house create, exists in the start
{
new where = -1;
if(strlen(cmd) > 13 && (where = strfind(cmd, " ", true, 13)) != -1) // check if there's more text after /house create if yes, find the which will be after that text
{
new House[32];
strmid(House, cmd, 13, where); // 13 may need to be 14 , get the internior kind, starting from the end of /house create ending at the space which found by strfind
printf("Interior got: %s", House); // simple debug
if(strcmp(House, "Small1", true) == 0) // check interior kind
{
` new tempprice[10], price;
strmid(tempprice, cmd, where, strlen(cmd)); // get the prize which starts after the last space " ", ends at string finish
printf("Prize got: %d", tempprice); // simple debug
price = strval(tempprice); // gets the prize as integer
//my code
}
}
else
{
SCM(playerid,COLOR_ERROR,"Usage: /house create [InteriorType] [Price]");
}
}