[SOLVED] Checking multiple variables for their values
#1

Hi,

I got a command called /combine. In it player specifies 4 numbers, for example..
Код:
/combine 3 14 2 26
The problem is that those numbers can be arranged in any way..
Код:
/combine 2 3 14 26
or
/combine 2 14 26 3
Then i use "sscanf" to get the variables and store them into s1, s2, s3 and s4.

Is there some fast way to check if those variables are exactly what i need instead of making something like..
pawn Код:
if((s1==2 && s2==3 && s3==14 && s4==26) || (s1==3 && s2==2 && s3==14 && s4==26) || (...) || (...))
It is kinda hard to do it that way.

Thanks.
Reply
#2

pawn Код:
if(s1 == 3)
    {
        if(s2 == 14)
        {
            if(s3 == 2)
            {
                if(s4 == 26)
                {
                    //func...
                }
            }
        }
    }
Reply
#3

pawn Код:
stock split(const strsrc[], strdest[][], delimiter)
{
  new li;
  i = 0;
  new aNum;
  new len;
  while(i <= strlen(strsrc))
  {
    if(strsrc[i] == delimiter || i == strlen(strsrc))
    {
      len = strmid(strdest[aNum], strsrc, li, i, 128);
      strdest[aNum][len] = 0;
      li = i+1;
      aNum++;
    }
    i++;
  }
  return 1;
}
So pretty much, do this.

pawn Код:
new data[4][10];
split(/*Source*/, data, ' ');
for(new i = 0; i<4; i++)
{
  if(strval(data[i]) == /*Value here*/)
  {
  //One of the numbers is a certain number
  }
}
Reply
#4

Quote:
Originally Posted by Phento
pawn Код:
if(s1 == 3)
    {
        if(s2 == 14)
        {
            if(s3 == 2)
            {
                if(s4 == 26)
                {
                    //func...
                }
            }
        }
    }
This is wrong because s1 can be 14 as well as 2 and 26. Same for the s2, s3 and s4.

Quote:
Originally Posted by [HiC
TheKiller ]
pawn Код:
stock split(const strsrc[], strdest[][], delimiter)
{
  new li;
  i = 0;
  new aNum;
  new len;
  while(i <= strlen(strsrc))
  {
    if(strsrc[i] == delimiter || i == strlen(strsrc))
    {
      len = strmid(strdest[aNum], strsrc, li, i, 128);
      strdest[aNum][len] = 0;
      li = i+1;
      aNum++;
    }
    i++;
  }
  return 1;
}
So pretty much, do this.

pawn Код:
new data[4][10];
split(/*Source*/, data, ' ');
for(new i = 0; i<4; i++)
{
  if(strval(data[i]) == /*Value here*/)
  {
  //One of the numbers is a certain number
  }
}
I don't understand what "split" has to do here..

I need something like..
pawn Код:
*a player enters /combine 2 5 6 1*
if(!sscanf(params, "iiii", s1, s2, s3, s4))
{
 if(All of the numbers contain 6 5 2 1)
 {
 ...
 }
}
Reply
#5

Quote:
Originally Posted by CaHbKo
pawn Код:
*a player enters /combine 2 5 6 1*
if(!sscanf(params, "iiii", s1, s2, s3, s4))
{
 if(All of the numbers contain 6 5 2 1)
 {
 ...
 }
}
pawn Код:
dcmd_combine(playerid,params[])
{
    new
        s1,
        s2,
        s3,
        s4,
        bool:Correct = false;
    if(sscanf(params, "dddd", s1, s2, s3, s4)) { return SendClientMessage(playerid, red, "Usage: /combine 4 number"); }
    else
    {
        if(s1 == 2) { if(s2 == 5) { if(s3 == 6) { if(s4 == 1) {
            Correct = true;
        }}}}
    }
    if(Correct == true)
    {
        SendClientMessage(playerid, red, "Correct");
    } else {
        SendClientMessage(playerid, yellow, "Not agreement.");
    }
    return 1;
}
Reply
#6

Okay, I made this function..
pawn Код:
stock VarsContain(v1, c1, v2, c2, v3=-1, c3=-1, v4=-1, c4=-1)
{
    if(v3>-1 && v4>-1)
    {
      if(v1==c1||v1==c2||v1==c3||v1==c4)
      {
        if(v2==c1||v2==c2||v2==c3||v2==c4)
        {
            if(v3==c1||v3==c2||v3==c3||v3==c4)
                {
                  if(v4==c1||v4==c2||v4==c3||v4==c4)
                  {
                    return 1;
                  }
                }
        }
      }
    }
    else if(v3>-1 && v4==-1)
    {
      if(v1==c1||v1==c2||v1==c3)
      {
        if(v2==c1||v2==c2||v2==c3)
        {
            if(v3==c1||v3==c2||v3==c3)
                {
                  return 1;
                }
        }
        }
    }
    else if(v3==-1 && v4==-1)
    {
      if(v1==c1||v1==c2)
      {
        if(v2==c1||v2==c2)
        {
          return 1;
        }
        }
    }
    return 0;
}
Thank you all anyway.

forums spoil my indentation, lol.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)