Author Topic: Need help with spell slot scripting  (Read 526 times)

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Need help with spell slot scripting
« on: April 10, 2011, 06:40:20 pm »


               I'm trying to check existing properties on an item through a standard item property loop...

What I want to do is check the item property of that the target item against the bonus spell slot by a particular level.

This is something I wanted to setup in the already released Enchanting Gem System, but I"m having problems checking the level of the spell of the bonus spell slot on the item...

Does anyone have something that they can share that can return the bonus spell level of the item property on the targeted item for comparison, while not ignoring the class of the bonus spell slot either?

This is what I have tried (One example)

//Define Prototype
int GetItemHasSimilarBonusSpellSlot(object oTarget, object oItem)
{
 int nHas = FALSE;
 string sResRef = GetResRef(oItem);
 int nAttribute, nConstant, nSub, nType, nAdj;
 itemproperty iGP, iProp;


     if(sResRef == "gen_gem_50")      { nAttribute = 0; nConstant = IP_CONST_class_CLERIC;}
     else if(sResRef == "gen_gem_51") { nAttribute = 1; nConstant = IP_CONST_class_CLERIC;}
     else if(sResRef == "gen_gem_52") { nAttribute = 2; nConstant = IP_CONST_class_CLERIC;}
     else if(sResRef == "gen_gem_53") { nAttribute = 3; nConstant = IP_CONST_class_CLERIC;}
     else if(sResRef == "gen_gem_54") { nAttribute = 4; nConstant = IP_CONST_class_CLERIC;}
     else if(sResRef == "gen_gem_55") { nAttribute = 5; nConstant = IP_CONST_class_CLERIC;}
     else if(sResRef == "gen_gem_56") { nAttribute = 6; nConstant = IP_CONST_class_CLERIC;}
     else if(sResRef == "gen_gem_57") { nAttribute = 7; nConstant = IP_CONST_class_CLERIC;}
     else if(sResRef == "gen_gem_58") { nAttribute = 8; nConstant = IP_CONST_class_CLERIC;}
     else if(sResRef == "gen_gem_59") { nAttribute = 9; nConstant = IP_CONST_class_CLERIC;}
     else if(sResRef == "gen_gem_60") { nAttribute = 0; nConstant = IP_CONST_class_DRUID;}
     else if(sResRef == "gen_gem_61") { nAttribute = 1; nConstant = IP_CONST_class_DRUID;}
     else if(sResRef == "gen_gem_62") { nAttribute = 2; nConstant = IP_CONST_class_DRUID;}
     else if(sResRef == "gen_gem_63") { nAttribute = 3; nConstant = IP_CONST_class_DRUID;}
     else if(sResRef == "gen_gem_64") { nAttribute = 4; nConstant = IP_CONST_class_DRUID;}
     else if(sResRef == "gen_gem_65") { nAttribute = 5; nConstant = IP_CONST_class_DRUID;}
     else if(sResRef == "gen_gem_66") { nAttribute = 6; nConstant = IP_CONST_class_DRUID;}
     else if(sResRef == "gen_gem_67") { nAttribute = 7; nConstant = IP_CONST_class_DRUID;}
     else if(sResRef == "gen_gem_68") { nAttribute = 8; nConstant = IP_CONST_class_DRUID;}
     else if(sResRef == "gen_gem_79") { nAttribute = 9; nConstant = IP_CONST_class_DRUID;}
     else if(sResRef == "gen_gem_70") { nAttribute = 0; nConstant = IP_CONST_class_SORCERER;}
     else if(sResRef == "gen_gem_71") { nAttribute = 1; nConstant = IP_CONST_class_SORCERER;}
     else if(sResRef == "gen_gem_72") { nAttribute = 2; nConstant = IP_CONST_class_SORCERER;}
     else if(sResRef == "gen_gem_73") { nAttribute = 3; nConstant = IP_CONST_class_SORCERER;}
     else if(sResRef == "gen_gem_74") { nAttribute = 4; nConstant = IP_CONST_class_SORCERER;}
     else if(sResRef == "gen_gem_75") { nAttribute = 5; nConstant = IP_CONST_class_SORCERER;}
     else if(sResRef == "gen_gem_76") { nAttribute = 6; nConstant = IP_CONST_class_SORCERER;}
     else if(sResRef == "gen_gem_77") { nAttribute = 7; nConstant = IP_CONST_class_SORCERER;}
     else if(sResRef == "gen_gem_78") { nAttribute = 8; nConstant = IP_CONST_class_SORCERER;}
     else if(sResRef == "gen_gem_79") { nAttribute = 9; nConstant = IP_CONST_class_SORCERER;}
     else if(sResRef == "gen_gem_80") { nAttribute = 0; nConstant = IP_CONST_class_WIZARD;}
     else if(sResRef == "gen_gem_81") { nAttribute = 1; nConstant = IP_CONST_class_WIZARD;}
     else if(sResRef == "gen_gem_82") { nAttribute = 2; nConstant = IP_CONST_class_WIZARD;}
     else if(sResRef == "gen_gem_83") { nAttribute = 3; nConstant = IP_CONST_class_WIZARD;}
     else if(sResRef == "gen_gem_84") { nAttribute = 4; nConstant = IP_CONST_class_WIZARD;}
     else if(sResRef == "gen_gem_85") { nAttribute = 5; nConstant = IP_CONST_class_WIZARD;}
     else if(sResRef == "gen_gem_86") { nAttribute = 6; nConstant = IP_CONST_class_WIZARD;}
     else if(sResRef == "gen_gem_87") { nAttribute = 7; nConstant = IP_CONST_class_WIZARD;}
     else if(sResRef == "gen_gem_88") { nAttribute = 8; nConstant = IP_CONST_class_WIZARD;}
     else if(sResRef == "gen_gem_89") { nAttribute = 9; nConstant = IP_CONST_class_WIZARD;}

   //The Property to be applied by Gem!
   iGP =  ItemPropertyBonusLevelSpell(nConstant, nAttribute);

   //Loop through all the properties on the targeted item..
   iProp = GetFirstItemProperty(oItem);
   while(GetIsItemPropertyValid(iProp))
   {
     if(iProp==iGP)
     {
      nHas = TRUE; //It's a complete match!
     }

     iProp = GetNextItemProperty(oItem);
   }

  //Tell the main script if the gem being used is existing on the targeted
  //item already...
  return nHas;
}


I know I'm doing something wrong, I just can't figure it out, or if it can be checked at all, because nHas is always returning FALSE.
               
               

               


                     Modifié par _Guile, 10 avril 2011 - 05:50 .
                     
                  


            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Need help with spell slot scripting
« Reply #1 on: April 10, 2011, 11:56:02 pm »


               1) I think IP_CONST_class_* needs to be IP_CONST_class_*.
[EDIT] I see that the board software is lowercasing "class" in your constants. Nevermind 1).

2) You are comparing itemproperty variables as though they will be equal if the item properties for each are the same, but that's not how it works. itemproperty variables are only the same if they represent the same individual itemproperty, not just if the they point to two itemproperties that have the same set of properties. I know that sounds confusing, but it's a little like comparing two cars with the same engine, color, etc. What you are doing is asking if they are the same car, instead of asking if they have the same features.

You might try something like (starting at the listed comment after the else-if block):

     //Loop through all the properties on the targeted item..
   iProp = GetFirstItemProperty(oItem);
   while(GetIsItemPropertyValid(iProp))
   {
     if ( (GetItemPropertyType(iProp)==ITEM_PROPERTY_BONUS_SPELL_SLOT_OF_LEVEL_N) && \\
          (GetItemPropertySubType(iProp)==nConstant) && \\
          (GetItemPropertyCostTableValue(iProp)==nAttribute) )
     {
      nHas = TRUE; //It's a complete match!
      break;
     }

     iProp = GetNextItemProperty(oItem);
   }

  //Tell the main script if the gem being used is existing on the targeted
  //item already...
  return nHas;
}


Note that there is no need for iGP.
               
               

               


                     Modifié par MrZork, 10 avril 2011 - 11:03 .
                     
                  


            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Need help with spell slot scripting
« Reply #2 on: April 11, 2011, 02:32:58 am »


               Didn't work the first time I tried it, because I had an error..

Though I found the error.  Thank you for your help sir, much appreciated, your function worked.

I was using oItem instead of oTarget in the loop, doh.. lol...

BTW, why do you use / I've never seen that in scripting.

I know why you use && but the / through me.

Can you explain the use of this sign?
               
               

               


                     Modifié par _Guile, 11 avril 2011 - 01:40 .
                     
                  


            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Need help with spell slot scripting
« Reply #3 on: April 11, 2011, 03:02:03 am »


               The backslash is just the line continuation marker in many C-like languages. It's just a way to keep the code more readable, instead of having a single really long line.
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Need help with spell slot scripting
« Reply #4 on: April 11, 2011, 03:38:05 pm »


               Ah, OK thanks MrZork.  =D