Author Topic: GetRacialType?  (Read 379 times)

Legacy_lordofworms

  • Sr. Member
  • ****
  • Posts: 422
  • Karma: +0/-0
GetRacialType?
« on: August 27, 2011, 10:24:14 pm »


               So I have a custom function that uses a system (modified NESS) for loot drops...
anyways, for some reason it always returns the first IF statement as true, EVEN when the shout says specifcally the right racial type?? I am completely dumbfounded!! help??! what am I missing?

here is the function called on a creatures OnSpawn

for example, I place a RAT and a OOZE down, on spawn they shout that they are of racial type 8 (RAT) and (29) OOZE
BUT when the shout that states what LOOT table they are grabbing it always grabs the first If statement...the one for humans, which I dont see how it can?? if I comment that entire block out then it just makes TRUE the next one (for orcs, goblins...)

??


----------------------------------------------------------------------

void LootStartMe(object oObject)
{
    int iMyRace = GetRacialType(oObject);
     int iRandomStore = Random(3)+100; //allow generic store 100,101,102
     int iRandomDrop1 = Random(50)+1;  //allow generic chance 1-50%
     int iRandomDrop2 = Random(25)+1;  //allow generic chance 1-25%
     int iRandomDrop3 = Random(10)+1;  //allow generic chance 1-10%
     int iAppearanceType = GetAppearanceType(OBJECT_SELF); //  get creature appearance
     ////////////////////////////////////////////////////////////////////////////////////////
    if (iMyRace == 0 || 1 || 4 || 2 || 3 || 5 || 6 || 23)
      { // standard humanoid drops  LOOT_100,101,102
       SetLocalInt(oObject,"LootTable",iRandomStore);
       SetLocalInt(oObject,"LootTable1ItemChance",iRandomDrop1); //generic chance 1-50%
       SetLocalInt(oObject,"LootTable2ItemChance",iRandomDrop2); //generic chance 1-25%
       SetLocalInt(oObject,"LootTable3ItemChance",iRandomDrop3); //generic chance 1-10%
       ActionSpeakString("I am humanoid standard", TALKVOLUME_SHOUT);
      }
    if (iMyRace == 18 || 12 || 14 || 15 )
      { // Giant and Monsterous Humanoid drops  LOOT_211
       SetLocalInt(oObject,"LootTable",211);
       SetLocalInt(oObject,"LootTable1ItemChance",iRandomDrop1); //generic chance 1-50%
       SetLocalInt(oObject,"LootTable2ItemChance",iRandomDrop2); //generic chance 1-25%
       SetLocalInt(oObject,"LootTable3ItemChance",iRandomDrop3); //generic chance 1-10%
       ActionSpeakString("I am Giant,Orc,Goblin", TALKVOLUME_SHOUT);
      }
    else if (iMyRace ==  11 || 20)
      { // Dragons and Outsider drops  LOOT_210
       SetLocalInt(oObject,"LootTable",210);
       SetLocalInt(oObject,"LootTable1ItemChance",iRandomDrop1); //generic chance 1-50%
       SetLocalInt(oObject,"LootTable2ItemChance",iRandomDrop2); //generic chance 1-25%
       SetLocalInt(oObject,"LootTable3ItemChance",iRandomDrop3); //generic chance 1-10%
       ActionSpeakString("I am Dragon or Demon", TALKVOLUME_SHOUT);
      }
    else if (iMyRace == 24)
      { // undead drops LOOT_103
       SetLocalInt(oObject,"LootTable",103);
       SetLocalInt(oObject,"LootTable1ItemChance",15); // 15% chance
       SetLocalInt(oObject,"LootTable2ItemChance",10); // 10% chance
       SetLocalInt(oObject,"LootTable3ItemChance",5);  // 5% chance
       ActionSpeakString("I am undead", TALKVOLUME_SHOUT);
      }
   else if (iMyRace == 8)
    {
     if (iAppearanceType == APPEARANCE_TYPE_DOG_WORG || APPEARANCE_TYPE_DOG_DIRE_WOLF || APPEARANCE_TYPE_DOG_WINTER_WOLF || APPEARANCE_TYPE_DOG_WOLF)
          { // wolf pelt drops LOOT_104
           SetLocalInt(oObject,"LootTable",104);
           SetLocalInt(oObject,"LootTable1ItemChance",50);// 50% chance only
           SetLocalInt(oObject,"LootTable2ItemChance",0);
           SetLocalInt(oObject,"LootTable3ItemChance",0);
           ActionSpeakString("I am a dog", TALKVOLUME_SHOUT);
          }
     if (iAppearanceType == 12 || 13 || 15 || 204 || 14)
          { // bear pelt drops LOOT_105
           SetLocalInt(oObject,"LootTable",105);
           SetLocalInt(oObject,"LootTable1ItemChance",50); // 50% chance only
           SetLocalInt(oObject,"LootTable2ItemChance",0);
           SetLocalInt(oObject,"LootTable3ItemChance",0);
           ActionSpeakString("I am a bear", TALKVOLUME_SHOUT);
          }
       }
   else if (iMyRace == 29 || 25 || 9 || 7 || 19 || 17 || 13)
          { // empty drops LOOT_200
          ActionSpeakString("I am Ooze or vermin", TALKVOLUME_SHOUT);
          /*
           SetLocalInt(OBJECT_SELF,"LootTable",200);
           SetLocalInt(OBJECT_SELF,"LootTable1ItemChance",0); // 50% chance only
           SetLocalInt(OBJECT_SELF,"LootTable2ItemChance",0);
           SetLocalInt(OBJECT_SELF,"LootTable3ItemChance",0);
           */
          }
     else
     {
     ActionSpeakString("I am NOT DEFINED", TALKVOLUME_SHOUT);
     }
   }
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
GetRacialType?
« Reply #1 on: August 27, 2011, 10:48:56 pm »


               

lordofworms wrote...

   if (iMyRace == 18 || 12 || 14 || 15 )
    



It is these checks that are doing you in.  You need format it like this

if(iMyRace == 18 || iMyRace == 12 || iMyRace == 14 || iMyRace == 15)

EDIT To put it more clearly
if(iMyRace == 18 || 12 || 14 || 15) means if((iMyRace == 18) || TRUE || TRUE || TRUE) which will always return TRUE
               
               

               


                     Modifié par WhiZard, 27 août 2011 - 10:01 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
GetRacialType?
« Reply #2 on: August 28, 2011, 12:07:26 am »


               I just thought that using ORs in multiple ways can cause confusion as BioWare sometimes uses the single or double.

For those who might have seen some by scripts use the single or (denoted "|") there is a difference why the single can operate with many arguments.

Example:

oObject = GetNearestObject(OBJECT_TYPE_CREATURE | OBJECT_TYPE_ITEM, OBJECT_SELF);

In this case every object type is designated a different power of 2, and the single OR acts similarly the normal OR, except every single binary digit of the first integer goes through an OR relation of the corresponding binary digit of the next integer.

e.g. 11 | 13 would translate into binary as 1011 | 1101, then each digit would be compared by OR to the corresponding.   This results in 1111 (binary) which is 15.

Using powers of two makes this much more simple as each binary digit of the number indicates whether or not the corresponding power of 2 is used. Thus OBJECT_TYPE_CREATURE is 1 and OBJECT_TYPE_ITEM is 2.  Doing the single or produces 1 | 2 which is in binary 01 | 10 which goes to 11 (binary) which is 3.  When this number is returned the function looks at the last and second to last binary digit to determine if it is looking for creatures and/or items.  Since 3 (in binary 11) shows both are listed as true, the object searching knows to look only for creatures and items.

--

When using the double OR (standard OR denoted "||") each argument on the list is either TRUE (if non zero) or FALSE (if zero) and the function will only return TRUE or FALSE.  So OBJECT_TYPE_CREATURE || OBJECT_TYPE_ITEM would return TRUE which doesn't tell a thing about what objects are being used.
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
GetRacialType?
« Reply #3 on: August 28, 2011, 12:37:13 am »


               <squirms in his seat...>
So each number between || is TRUE because it is *not* 0 (FALSE), right? So expression will always say it's true.

(iMyRace == 0 ||      1      ||      4    ||    2    ||   3   ||   5   ||   6   || 23)
evaluates as
(False || True|| True || etc...)

<...and wishes he wasn't in the corner with a pointy hat>
               
               

               


                     Modifié par Rolo Kipp, 27 août 2011 - 11:42 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
GetRacialType?
« Reply #4 on: August 28, 2011, 12:52:25 am »


               You have got it.
               
               

               
            

Legacy_Morbane

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
GetRacialType?
« Reply #5 on: August 28, 2011, 01:10:04 am »


               

(iMyRace == 0 ||      1      ||      4    ||    2    ||   3   ||   5   ||   6   || 23)
evaluates as
(False || True|| True || etc...)


iMyRace == 0 is correct - the TRUEs are the ones with no definition they all have to be iMyRace == ** so they will have a definition of what the integer stands for.

if(iMyRace == 18 || iMyRace == 12 || iMyRace == 14 || iMyRace == 15)

That is correct '<img'>
               
               

               


                     Modifié par Morbane, 28 août 2011 - 12:11 .
                     
                  


            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
GetRacialType?
« Reply #6 on: August 28, 2011, 01:24:22 am »


               <looks around frantically...>

You have got it.

What? Where?! GET IT OFF!

oh.

Cool :-)

<...for an exit>
               
               

               


                     Modifié par Rolo Kipp, 28 août 2011 - 12:27 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
GetRacialType?
« Reply #7 on: August 28, 2011, 01:29:08 am »


               Since we are all saying the same exact thing.  Why not Her is my version of the answer.  

the single symbol '|' or is a bitwize logical or on two numbers.

The double symbol  '||" or is a logical comparsion between two numbers that returns either 1 (true) or 0 (false) .  

In the if(expression) statment the expression is evaluated down to a single number.  If the number is 0 it is considerded to be false.   True is never checked for.   for the expression to be true it is simply not 0 (false).
               
               

               
            

Legacy_lordofworms

  • Sr. Member
  • ****
  • Posts: 422
  • Karma: +0/-0
GetRacialType?
« Reply #8 on: August 28, 2011, 02:49:02 am »


               wow, i did not know that, and I can see now why some of my older scripts never seemed to work either!!! thanks a ton guys!!! that worked and I also now understand it better as well!!

thank you sooo much!!
               
               

               
            

Legacy_Morbane

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
GetRacialType?
« Reply #9 on: August 28, 2011, 03:20:25 am »


               

Lightfoot8 wrote...

In the if(expression) statment the expression is evaluated down to a single number.  If the number is 0 it is considerded to be false.   True is never checked for.   for the expression to be true it is simply not 0 (false).



"Short Circuit"

Once a bool is in agreement with the equation the script continues - any further comparisons are ignored (in that particular equation)
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
GetRacialType?
« Reply #10 on: August 28, 2011, 03:43:24 am »


               

Morbane wrote...

Lightfoot8 wrote...

In the if(expression) statment the expression is evaluated down to a single number. If the number is 0 it is considerded to be false. True is never checked for. for the expression to be true it is simply not 0 (false).



"Short Circuit"

Once a bool is in agreement with the equation the script continues - any further comparisons are ignored (in that particular equation)



To me that one is a differant argument.   If anyone is intrested in what Morbane is talking about with Short circuit. That was discused in the Execution speeds  thread