Simple help
#1

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!
Reply
#2

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.
Reply
#3

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)
{
....
Reply
#4

How I can make command /house create [InteriorType] [Price] ?
Please give me the code! And if player write only /house create it calls "Usage: /house create [InteriorType] [Price]"
Please help!
Reply
#5

Please help me faster!
Reply
#6

you may wanna take a look here.
http://forum.sa-mp.com/showpost.php?...05&postcount=2
Reply
#7

I'm not using sscanf, can you give me it with no using sscanf?
Reply
#8

It will be hard, are you ok with it being hard?

also what command processor are you using? if none mind using zcmd?
Reply
#9

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
}
}
Reply
#10

well, if you use zcmd and sscanf it will be that easy:
PHP код:
CMD:house(playeridparams[])
{
    new 
action[7], interiortype[11], price;
    if(
sscanf(params,"s[6]s[10]i"actioninteriortypeprice))
    {
        if(
strcmp(interiortype"Small1"true) == 0)
        {
            
//my code
        
}
    }
    else
    {
        
SCM(playeridCOLOR_ERROR,"Usage: /house create [InteriorType] [Price]");
    }

but with your code it will need to be

PHP код:
new cmd[256], tmp[256], idx;
cmd strtok(cmdtextidx);
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" "true13)) != -1// check if there's more text after /house create if yes, find the which will be after that text
    
{
        new 
House[32];
        
strmid(Housecmd13where); // 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]");
    }

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)