Dylmani555 wrote...
Well I made them completely seperate if statements.. and now, if I am not one of those 2 races or classes, nothing happens at all... Although thank you for that advice. It will help me in the future.. how many times can i do that in one if statement? could I make all 4 checks with 1 if statement by putting:
if(GetRacialType(oPC) != RACIAL_TYPE_HALFELF ||
GetRacialType(oPC) != RACIAL_TYPE_HALFORC ||
GetclassByPosition(1, oPC) != class_TYPE_DRAGONDISCIPLE ||
GetclassByPosition(2, oPC) != class_TYPE_DRAGONDISCIPLE ||
GetclassByPosition(3, oPC) != class_TYPE_DRAGONDISCIPLE ||
GetclassByPosition(1, oPC) != class_TYPE_PURPLE_DRAGON_KNIGHT ||
GetclassByPosition(2, oPC) != class_TYPE_PURPLE_DRAGON_KNIGHT ||
GetclassByPosition(3, oPC) != class_TYPE_PURPLE_DRAGON_KNIGHT)
{
//Teleport script here
}
? Or would that not work?
Will not work.
Let me explain what is going on. The 'if' statment takes a expression that evaluates down to a single integer. So yes since it is an expression you can make it as complex and with as many operators as you like. Now if the expression evalulates to 0 (zero) it the expression is FALSE. if the expression evalulates to anything other then 0 the expression is concidered to be true.
Now lets just look at the first part of your expression.
GetRacialType(oPC) != RACIAL_TYPE_HALFELF ||
GetRacialType(oPC) != RACIAL_TYPE_HALFORC
The || ( logical OR operator) has lower precedence then the != ( Not Equal Operator). Therefore the NotEqualOperators (!=) will be evalulated before the Logical OR's ( || ). Just like in normal math addition ( + ) has lower precedence then multiplucation (*) where multication take place befor additions.
The equation
3*4 + 2*2 would have the multication take place first to get
=12 + 4, then the addition would take place to get a result of
=16.
We have the same basic principle here the operators are just different. Instead of the + and * operators you are using the != and || operators.
lets look closer at the parts.
The != operator compairs the right and left for equality and Evaluates to the inverse, That is 0 if they are equal and 1 if they are not.
The Logical OR Operator ( || ) compairs the Right and the Left and evalulates to Zero ( FALSE) if both the right and left of the operator is FALSE ( 0 ) . If either side is True ( Not zero) the operation evalulates out to be TRUE ( 1 )
GetRacialType(oPC) is a function that evalulates to an intenger that is the index into racialtypes.2da that represents the Race that the object oPC is. Functions also have a higher precedence then both the Logical OR operator ( || ) and the Not Equal Operator ( != ) . Therefore it will be evalulated before both of them.
the constants RACIAL_TYPE_HALFELF and RACIAL_TYPE_HALFORC are Lables that represent indexes into racialtypes.2da. This is just like Pi in math where Pi is a lable that represents the number 3.14. In this case we have RACIAL_TYPE_HALFELF which is the number 4 ( line 4 in racialtypes.2da is half elf) and RACIAL_TYPE_HALFORC which is the number 5 ( five being the line for half- orc).
now looking at the first part of your expression
we have:
GetRacialType(oPC) != RACIAL_TYPE_HALFELF || GetRacialType(oPC) != RACIAL_TYPE_HALFORC
we evalulate out the functions first. since we do not know what it is we will just give it a lable and call it nRace for now. we can also replace the constants with there actual values, The lables a actualy replaced with there valules befor the script is even ran. They are replaced with the valules when the script is compiled.
nRace != 4 || nRace != 5
The next thing to be evalulated will be the != operators. lets assume that the race of oPC was human (line 6 in RactialTypes.2da. we would get.
6 != 4 || 6 != 5 // well 6 is not equal to 4 or 5 so both evalulate out to be TRUE or (1).
1 || 1 // Same thing as saying TRUE || TRUE since at least one of them is True (Not Zero) the || operator evalulates to be TRUE.
Ok lets say that nRace was 4 ( HalfElf)
4 != 4 || 4 != 5 // in this case 4 != 4 evalulates to FALSE(0) since they are equal and 4 !=5 evalulates to TRUE(1)
0 || 1 // since one of them is True ( Not Zero) the || operator evalulates to TRUE.
TRUE(1)
So basicly there is no number that can be retrived by GetRacialType(oPC) that will be able to evalulate as FALSE to being Not Equal to both 4 and 5. Therefore your expression will always evalulate as TRUE reguardless of what race oPC is.