Назад

Вопрос по Countitem()

Автор: Aaron: Дата: 02.12.2010

Приветствую вас дамы и господа!

Вопрос таков :
Как сделать, что при проверке предметов на наличие , шла такая проверка - Если есть предмет 1 (или ) есть предмет 2 ( или) есть предмет 3 ...

if (countitem(1) > 1 && countitem(1) > 1 )

Повторюсь, как сделать чтобы было условие не (и) , а (или) ?

Благодарствую!

Автор: Aaron: Дата: 02.12.2010

Попробую. Очень признателен за помощь!

Автор: Aaron: Дата: 02.12.2010

Прошу прощения , но вот написал так :
if (countitem(20010) > 0 or countitem(20011) > 0 or countitem(20012) > 0) {

Мне выдаёт ошибку , что мол не правильная строка . Пишет "unmatch >" ...

Автор: Sanasol: Дата: 02.12.2010

Не правильно подсказал просто.

Будет примерно так

countitem(20010) > 0 | countitem(20011) > 0 | countitem(20012) > 0



Вот что в доках

Operators
---------

Operators are things you can do to variables and numbers. They are either the
common mathematical operations or conditional operators

+ - will add two numbers. If you try to add two strings, the result will be a
string glued together at the +. You can add a number to a string, and the
result will be a string. No other math operators work with strings.
- - will subtract two numbers.
* - will multiply two numbers.
/ - will divide two numbers. Note that this is an integer division, i.e.
7/2 is not equal 3.5, it's equal 3.
% - will give you the remainder of the division. 7%2 is equal to 1.

There are also conditional operators. This has to do with the conditional
command 'if' and they are meant to return either 1 if the condition is satisfied
and 0 if it isn't. (That's what they call 'boolean' variables. 0 means 'False'.
Anything except the zero is 'True' Odd as it is, -1 and -5 and anything below
zero will also be True.)

You can compare numbers to each other and you compare strings to each other, but
you can not compare numbers to strings.

== - Is true if both sides are equal. For strings, it means they are the same.
>= - True if the first value is equal to, or greater than, the second value.
<= - True if the first value is equal to, or less than, the second value
> - True if the first value greater than the second value
< - True if the first value is less than the second value
!= - True if the first value IS NOT equal to the second one

Examples:

1==1 is True.
1<2 is True while 1>2 is False.
@x>2 is True if @x is equal to 3. But it isn't true if @x is 2.

Only '==' and '!=' have been tested for comparing strings. Since there's no way
to code a seriously complex data structure in this language, trying to sort
strings by alphabet would be pointless anyway.

Comparisons can be stacked in the same condition:

&& - Is True if and only if BOTH sides are true.
('1==1 && 2==2' is true. '2==1 && 1==1' is false.)
|| - Is True if either side of this expression is True.

1==1 && 2==2 is True.
1==1 && 2==1 is False.
1==1 || 2==1 is True.

Logical bitwise operators work only on numbers, and they are the following:

<< - Left shift.
>> - Right shift.
Left shift moves the binary 1(s) of a number n positions to the left,
which is the same as multiplying by 2, n times.
In the other hand, Right shift moves the binary 1(s) of a number n positions
to the right, which is the same as dividing by 2, n times.
Example:
set b,2;
set a, b << 3;
mes a;
set a, a >> 2;
mes a;
The first mes command would display 16, which is the same as 2 x (2 x 2 x 2) = 16.
The second mes command would display 4, which is the same as 16 / 2 = 8. 8 / 2 = 4.
& - And.
| - Or.

The bitwise operator AND (&) is used to test two values against eachother,
and results in setting bits which are active in both arguments. This can
be used for a few things, but in eAthena this operator is usually used to
create bitmasks in scripts.

The bitwise operator OR (|)sets to 1 a binary position if the binary position
of one of the numbers is 1. This way a variable can hold several values we can check,
known as bitmaks. A variable currently can hold up to 32 bitmasks (from position 0
to position 1). This is a cheap(skate) and easy way to avoid using arrays to store several checks
that a player can have.

A bitmask basically is (ab)using the variables bits to set various options in
one variable. With the current limit if variables it is possible to store 32
different options in one variable (by using the bits on position 0 to 31).

Example(s):
- Basic example of the & operator, bit example:
10 & 2 = 2
Why? :
10 = 2^1 + 2^3 (2 + 8), so in bits, it would be 1010
2 = 2^1 (2), so in bits (same size) it would be 0010
The & (AND) operator sets bits which are active (1) in both arguments, so in the
example 1010 & 0010, only the 2^1 bit is active (1) in both. Resulting in the bit
0010, which is 2.
- Basic example of creating and using a bit mask:
set @options,2|4|16; //(note: this is the same as 2+4+16, or 22)
if (@options & 1) mes "Option 1 is activated";
if (@options & 2) mes "Option 2 is activated";
if (@options & 4) mes "Option 3 is activated";
if (@options & 8) mes "Option 4 is activated";
if (@options & 16) mes "Options 5 is activated";
This would return the messages about option 2, 3 and 5 being shown (since we've set
the 2,4 and 16 bit to 1).
^ - Xor.
The bitwise operator XOR (eXclusive OR) sets a binary position to 0 if both
numbers have the same value in the said position. On the other hand, it
sets to 1 if they have different values in the said binary position.
This is another way of setting and unsetting bits in bitmasks.

Example:
- First let's set the quests that are currently in progress:
set inProgress,1|8|16; // quest 1,8 and 16 are in progress
- After playing for a bit, the player starts another quest:
if( inProgress&2 == 0 ){
// this will set the bit for quest 2 (inProgress has that bit set to 0)
set inProgress,inProgress^2;
mes "Quest 2: find a newbie and be helpful to him for an hour.";
close;
}
- After spending some time reading info on Xor's, the player finally completes quest 1:
if( inProgress&1 && isComplete ){
// this will unset the bit for quest 1 (inProgress has that bit set to 1)
set inProgress,inProgress^1;
mes "Quest 1 complete!! You unlocked the secrets of the Xor dinasty, use them wisely.";
close;
}

Автор: Aaron: Дата: 02.12.2010

Если быть точнее , то получается так :
countitem(20010) > 0 || countitem(20011) > 0 || countitem(20012) > 0

Благодарю за помощь! Спасибо нажал :)

Автор: Мяфк: Дата: 02.13.2010

Доки врут? Но когда я пишу квесты, я ставлю ||, это считается за И.
if(countitem(5009) < 1 || countitem(1003) < 10 || countitem(1041) < 50 || countitem(999) < 20)
Нпц проверяет ВСЕ итемы, то есть считает за "And"

Автор: Gr1nS1de: Дата: 02.13.2010

Цитата Мяфк;20157:
Доки врут? Но когда я пишу квесты, я ставлю ||, это считается за И.
if(countitem(5009) < 1 || countitem(1003) < 10 || countitem(1041) < 50 || countitem(999) < 20)
Нпц проверяет ВСЕ итемы, то есть считает за "And"


Че за херня?
|| - ИЛИ
&& - И
Так же и в языке С++

Автор: Мяфк: Дата: 02.13.2010

Но попробуй например в квесте использовать || и посмотреть проверяет ли он все итемы или любой.

Автор: Aaron: Дата: 02.14.2010

У меня проверяет на наличие хотя бы одного из перечисленных.