Author Topic: Stuck on conversation conditional check - help!  (Read 385 times)

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Stuck on conversation conditional check - help!
« on: January 18, 2012, 04:13:19 pm »


               Hey folks! Got another sneaky script that I just can't seem to fire on a conversation conditional - TEXT APPEARS - and would like some help. I've tried two variations from examples found via the NWN Omnibus but it still does not return TRUE.


int StartingConditional()
{
object oPC = GetPCSpeaker();
object oItemR = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
object oItemL = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC);

if ( (GetItemHasItemProperty(oItemR, SPELL_FLAME_WEAPON)) ||
     (GetItemHasItemProperty(oItemL, SPELL_FLAME_WEAPON))
   ) return TRUE;

return FALSE;
}


My second attempt was with a loop to detect the item property but it fails too.

int StartingConditional()
{
object oPC = GetPCSpeaker();
object oItemR = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
object oItemL = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC);

itemproperty ipLoopR=GetFirstItemProperty(oItemR);
itemproperty ipLoopL=GetFirstItemProperty(oItemL);

while (
        (GetIsItemPropertyValid(ipLoopR)) ||
        (GetIsItemPropertyValid(ipLoopL))
         )

{

if (
      (GetItemPropertyType(ipLoopR)==SPELL_FLAME_WEAPON) ||
      (GetItemPropertyType(ipLoopL)==SPELL_FLAME_WEAPON)
   )

return TRUE;

ipLoopR=GetNextItemProperty(oItemR);
ipLoopL=GetNextItemProperty(oItemL);

}

oItemR = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
oItemL = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC);


return FALSE;
}


The idea here is to check for the spell FLAME_WEAPON in a conversation, so a mounted wall torch can be lit with the flames from the weapon.

Thanks,

FP!
               
               

               
            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Stuck on conversation conditional check - help!
« Reply #1 on: January 18, 2012, 05:49:03 pm »


               Don't know if this will work for you, since I'm not sure if the function to compare an item property takes the caster level of the onhitcastspell into account.


#include "x2_inc_spellhook"

int StartingConditional()
{
object oPC = GetPCSpeaker();
object oItemR = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
object oItemL = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC);
int nCasterLevel = 5; // just a sample caster level
itemproperty ipFlameWeapon = ItemPropertyOnHitCastSpell(124, nCasterLevel);

// Check right hand first.
if (GetIsObjectValid(oItemR) == TRUE)
   {
   if (IPGetItemHasProperty(oItemR, ipFlameWeapon, DURATION_TYPE_TEMPORARY) == TRUE)
      {
      return TRUE;
      }
   }
else // no weapon in right hand = no weapon in left...no reason to continue the check
   {
   return FALSE;
   }

if (GetIsObjectValid(oItemL) == TRUE)
   {
   if (IPGetItemHasProperty(oItemL, ipFlameWeapon, DURATION_TYPE_TEMPORARY) == TRUE)
      {
      return TRUE;
      }
   }

return FALSE;
}

               
               

               


                     Modifié par The Amethyst Dragon, 18 janvier 2012 - 05:53 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Stuck on conversation conditional check - help!
« Reply #2 on: January 18, 2012, 06:44:13 pm »


               That wont work Amethyst Dragon, this should:

#include "x2_inc_itemprop"

int StartingConditional()
{
object oPC = GetPCSpeaker();
object oWeaponR = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
object oWeaponL = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC);
itemproperty ip;
 if(IPGetIsMeleeWeapon(oWeaponR))
 {
 ip = GetFirstItemProperty(oWeaponR);
  while(GetIsItemPropertyValid(ip))
  {
   if(GetItemPropertyType(ip) == ITEM_PROPERTY_ONHITCASTSPELL && (GetItemPropertySubType(ip) == 124 || GetItemPropertySubType(ip) == 127))
   {
   return TRUE;
   }
  ip = GetNextItemProperty(oWeaponR);
  }
 }
 if(IPGetIsMeleeWeapon(oWeaponL))
 {
 ip = GetFirstItemProperty(oWeaponL);
  while(GetIsItemPropertyValid(ip))
  {
   if(GetItemPropertyType(ip) == ITEM_PROPERTY_ONHITCASTSPELL && (GetItemPropertySubType(ip) == 124 || GetItemPropertySubType(ip) == 127))
   {
   return TRUE;
   }
  ip = GetNextItemProperty(oWeaponL);
  }
 }
return FALSE;
}


               
               

               


                     Modifié par ShaDoOoW, 18 janvier 2012 - 06:44 .
                     
                  


            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Stuck on conversation conditional check - help!
« Reply #3 on: January 18, 2012, 07:06:37 pm »


               GetItemPropertyType() does not return a spell constant. In this case it will return ITEM_PROPERTY_ONHITCASTSPELL, then you need to inspect the subtype to determine if it's Flame Weapon. Thus, you would need to replace(every similar instance in code):

if(GetItemPropertyType(ipLoopR)==SPELL_FLAME_WEAPON)

with:

if(GetItemPropertyType(ipLoopR)==ITEM_PROPERTY_ONHITCASTSPELL && GetItemPropertySubType(ipLoopR)==IP_CONST_ONHIT_CASTSPELL_ONHIT_FIREDAMAGE)

Hopefully this can help

EDIT: Nevermind, beaten by the punch


Kato
               
               

               


                     Modifié par Kato_Yang, 18 janvier 2012 - 07:07 .
                     
                  


            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Stuck on conversation conditional check - help!
« Reply #4 on: January 18, 2012, 09:50:28 pm »


               As you can see, I rarely check items for properties via scripting...hehe.
               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Stuck on conversation conditional check - help!
« Reply #5 on: January 19, 2012, 04:11:33 am »


               I thank everyone for their time and help.

Even though ShaDoOoW mentioned Amethyst's script would not work - it does!

I had copy and pasted the script for testing purposes before leaving for the day and returned to test it out. So, as it is working when I cast Flame Weapon on an equipped weapon, is the script that ShaDoOoW provided required?

What are the two differences between each script? Knowing that would certainly give me the best choice in what script to use, as to avoid any strange situations for the player.

Thanks,

FP!
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Stuck on conversation conditional check - help!
« Reply #6 on: January 19, 2012, 04:35:36 am »


               

Fester Pot wrote...

I thank everyone for their time and help.

Even though ShaDoOoW mentioned Amethyst's script would not work - it does!

I had copy and pasted the script for testing purposes before leaving for the day and returned to test it out. So, as it is working when I cast Flame Weapon on an equipped weapon, is the script that ShaDoOoW provided required?

What are the two differences between each script? Knowing that would certainly give me the best choice in what script to use, as to avoid any strange situations for the player.

Thanks,

FP!


ADs works just fine.  The function he used compared item property type, subtype, and whether the duration was temporary (the caster level was ignored).  ShaDoOoW's compares type and subtype only, but does also check for darkfire.

EDIT: Though it does look like AD's include can be simplified to x2_inc_itemprop
               
               

               


                     Modifié par WhiZard, 19 janvier 2012 - 04:42 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Stuck on conversation conditional check - help!
« Reply #7 on: January 19, 2012, 05:03:36 am »


               If you wanted AD version to also check for dark fire, It would be something like this. 

#include "x2_inc_spellhook"
int StartingConditional()
{
object oPC = GetPCSpeaker();
object oItemR = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
object oItemL = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC);
int nCasterLevel = 5; // just a sample caster level
itemproperty ipFlameWeapon = ItemPropertyOnHitCastSpell(124, nCasterLevel);
itemproperty ipDKFire = ItemPropertyOnHitCastSpell(IP_CONST_ONHIT_CASTSPELL_ONHIT_DARKFIRE, nCasterLevel);
// Check right hand first.

int nReturn;

if (GetIsObjectValid(oItemR))

   nReturn =IPGetItemHasProperty(oItemR, ipFlameWeapon, DURATION_TYPE_TEMPORARY)
           ||IPGetItemHasProperty(oItemR, ipDKFire, DURATION_TYPE_TEMPORARY);

else return FALSE;// no weapon in right hand = no weapon in left...no reason to continue the check

if (GetIsObjectValid(oItemL))

   nReturn = nReturn
           || IPGetItemHasProperty(oItemL, ipFlameWeapon, DURATION_TYPE_TEMPORARY)
           || IPGetItemHasProperty(oItemR, ipDKFire, DURATION_TYPE_TEMPORARY);
 
return nReturn;
}
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Stuck on conversation conditional check - help!
« Reply #8 on: January 19, 2012, 05:20:07 am »


               

Lightfoot8 wrote...

If you wanted AD version to also check for dark fire, It would be something like this. 


You can also disable the duration check by using -1 instead of DURATION_TYPE_TEMPORARY.  To account for darkfire, this method does a double loop through each item's item properties, while ShaDoOoW's checks multiple within the same loop.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Stuck on conversation conditional check - help!
« Reply #9 on: January 19, 2012, 02:05:04 pm »


                 If you're just checking for the flame weapon spell effect, wouldn't a check for that specifically work better?

int StartingConditional()
{
object oPC = GetPCSpeaker();
object oItemR = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
object oItemL = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC);

if (GetHasSpellEffect (SPELL_FLAME_WEAPON, oItemR) ||
    GetHasSpellEffect (SPELL_FLAME_WEAPON, oItemL)) return TRUE;

return FALSE;
}