Author Topic: Adding Custom Item Properties Via Script  (Read 379 times)

Legacy_zunath

  • Full Member
  • ***
  • Posts: 152
  • Karma: +0/-0
Adding Custom Item Properties Via Script
« on: July 25, 2011, 01:29:08 am »


               Hey all,

I've got a number of custom item properties added to my module. Their functionality works great and that's not my problem - just to be clear '<img'>

The issue is this:  I'm trying to add/replace these custom item properties via script to an item that is allowed to have them. However, the IPSafeAddItemProperty function only takes the ItemProperty data type. Obviously there's no ItemProperty constructor for my custom ones.

So this leads me to the question:  How can I add these custom item properties via script?

Thanks for any help!
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Adding Custom Item Properties Via Script
« Reply #1 on: July 25, 2011, 03:34:32 am »


               I am at a loss on how to answer this.  

Are they new item props or just an extention of the item props that are already in the game?  

can you give us an exsample of one of the new item props.  

If they are new item props and not just extinsions of the originals, NWNx would be the way to go.  That is if it gives acces to the structure for item props. (I don't know I do not use it).  

The other way to go would be to retrive the iProps from another item then apply it.

Really I would need more information on the iProp to give a better guess/advice.
               
               

               
            

Legacy_zunath

  • Full Member
  • ***
  • Posts: 152
  • Karma: +0/-0
Adding Custom Item Properties Via Script
« Reply #2 on: July 25, 2011, 03:56:22 am »


               I've checked on NWNX... nothing that gives you the ability to define new ItemProperty constructors.

But since you asked:

My combat system uses a lot of custom item properties for the firearms. Such as: Firepower, Magazine Size, Range, etc. These are all custom ones - not based off of any existing item properties.

I think the only solution is to put items with these new item property types in a secure location and reference them from script. IPWildShapeCopyItemProperties seems to be able to do this.

Pain in the ass but I've found no other way.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Adding Custom Item Properties Via Script
« Reply #3 on: July 25, 2011, 04:43:00 am »


               

zunath wrote...

I've checked on NWNX... nothing that gives you the ability to define new ItemProperty constructors.

But since you asked:

My combat system uses a lot of custom item properties for the firearms. Such as: Firepower, Magazine Size, Range, etc. These are all custom ones - not based off of any existing item properties.

I think the only solution is to put items with these new item property types in a secure location and reference them from script. IPWildShapeCopyItemProperties seems to be able to do this.

Pain in the ass but I've found no other way.


Like so, using nwnx_structs.

From itempropdef.2da, a snippet:


221    16842236    X_Damage_Immunity                 IPRP_DAMAGETYPE     2.3      5                  ****            5488          1093
222    16842237    X_On_Hit                          IPRP_ONHIT          ****     24                 ****            5512          1450
223    16842238    X_Save_Penalty                    IPRP_SAVEELEMENT    0        21                 ****            5513          1461
224    16842239    X_Save_Penalty_Specific           IPRP_SAVINGTHROW    0        21                 ****            5513          1462
225    16842240    X_Skill_Bonus                     SKILLS              0.12     25                 ****            5516          ****

from our include, nwnx_exalt:

const int ITEM_PROPERTY_INVIS_DAMAGE_IMMUNITY           = 221;
const int ITEM_PROPERTY_INVIS_ON_HIT                    = 222;
const int ITEM_PROPERTY_INVIS_SAVE_PENALTY              = 223;
const int ITEM_PROPERTY_INVIS_SAVE_PENALTY_SPECIFIC     = 224;
const int ITEM_PROPERTY_INVIS_SKILL_BONUS               = 225;
*snip*
itemproperty ItemPropertyInvisValueDecrease (int nAdjustment) {
    itemproperty ip = ItemPropertyTurnResistance(1);

    SetItemPropertyInteger(ip, 0, ITEM_PROPERTY_INVIS_VALUE_DECREASE);
    SetItemPropertyInteger(ip, 2, 21);          /* value adjustment cost table */
    SetItemPropertyInteger(ip, 3, nAdjustment);
    return ip;
}

itemproperty ItemPropertyInvisValueIncrease (int nAdjustment) {
    itemproperty ip = ItemPropertyTurnResistance(1);

    SetItemPropertyInteger(ip, 0, ITEM_PROPERTY_INVIS_VALUE_INCREASE);
    SetItemPropertyInteger(ip, 2, 25);          /* value adjustment cost table */
    SetItemPropertyInteger(ip, 3, nAdjustment);
    return ip;
}

itemproperty ItemPropertyInvisBonusFeat (int nFeat) {
    itemproperty ip = ItemPropertyBonusFeat(1);

    SetItemPropertyInteger(ip, 0, ITEM_PROPERTY_INVIS_BONUS_FEAT);
    SetItemPropertyInteger(ip, 1, nFeat);
    return ip;
}

itemproperty ItemPropertyInvisDamageBonus (int nDamageType, int nDamage) {
    itemproperty ip = ItemPropertyDamageBonus(nDamageType, 1);

    SetItemPropertyInteger(ip, 0, ITEM_PROPERTY_INVIS_DAMAGE_BONUS);
    SetItemPropertyInteger(ip, 2, 4);           /* damage bonus cost table */
    SetItemPropertyInteger(ip, 3, nDamage);
    return ip;
}

itemproperty ItemPropertyInvisImmunityMisc (int nImm) {
    itemproperty ip = ItemPropertyImmunityMisc(1);

    SetItemPropertyInteger(ip, 0, ITEM_PROPERTY_INVIS_IMMUNITY_MISC);
    SetItemPropertyInteger(ip, 1, nImm);
    return ip;
}

itemproperty ItemPropertyInvisMaterial (int nMaterial) {
    itemproperty ip = ItemPropertyTurnResistance(1);

    SetItemPropertyInteger(ip, 0, ITEM_PROPERTY_INVIS_MATERIAL);
    SetItemPropertyInteger(ip, 2, 28);          /* material cost table */
    SetItemPropertyInteger(ip, 3, nMaterial);
    return ip;
}

itemproperty ItemPropertyInvisQuality (int nQuality) {
    itemproperty ip = ItemPropertyTurnResistance(1);

    SetItemPropertyInteger(ip, 0, ITEM_PROPERTY_INVIS_QUALITY);
    SetItemPropertyInteger(ip, 2, 29);          /* quality cost table */
    SetItemPropertyInteger(ip, 3, nQuality);
    return ip;
}

itemproperty ItemPropertyInvisAdditional (int nAdditional) {
    itemproperty ip = ItemPropertyTurnResistance(1);

    SetItemPropertyInteger(ip, 0, ITEM_PROPERTY_INVIS_ADDITIONAL);
    SetItemPropertyInteger(ip, 2, 30);          /* additional property cost table */
    SetItemPropertyInteger(ip, 3, nAdditional);
    return ip;
}

itemproperty ItemPropertyInvisTrap (int nTrapLevel, int nTrapType) {
    itemproperty ip = ItemPropertyTrap(0, 0);

    SetItemPropertyInteger(ip, 0, ITEM_PROPERTY_INVIS_TRAP);
    SetItemPropertyInteger(ip, 1, nTrapLevel);
    SetItemPropertyInteger(ip, 2, 17);          /* trap cost table */
    SetItemPropertyInteger(ip, 3, nTrapType);
    return ip;
}


You can alter and apply item props with structs much more easily than normal, using a function like this:


itemproperty ItemPropertyDirect (int nType, int nSubType, int nCostTable, int nCostValue, int nParamTable, int nParamValue) {
    itemproperty ip = ItemPropertyAdditional(0);

    SetItemPropertyInteger(ip, 0, nType);
    SetItemPropertyInteger(ip, 1, nSubType);
    SetItemPropertyInteger(ip, 2, nCostTable);
    SetItemPropertyInteger(ip, 3, nCostValue);
    SetItemPropertyInteger(ip, 4, nParamTable);
    SetItemPropertyInteger(ip, 5, nParamValue);

    return ip;
}

At that point, you can apply it like a normal item property. For custom item properties, they are likely to require additional engine hacks to do what you want, unless you can code what you want in nwscript.

LMK if you have any questions.

Funky
               
               

               
            

Legacy_zunath

  • Full Member
  • ***
  • Posts: 152
  • Karma: +0/-0
Adding Custom Item Properties Via Script
« Reply #4 on: July 25, 2011, 04:53:30 am »


               Interesting. I saw those functions in my nwnx_structs include but wasn't sure how to use them. I guess they do do what I need. '<img'>

Thanks Funky, I'll give these a shot.

EDIT:  The item properties themselves don't do anything but they're referenced in my combat system (using NWNX_Events) so this will work great!
               
               

               


                     Modifié par zunath, 25 juillet 2011 - 03:54 .
                     
                  


            

Legacy_zunath

  • Full Member
  • ***
  • Posts: 152
  • Karma: +0/-0
Adding Custom Item Properties Via Script
« Reply #5 on: July 25, 2011, 05:48:56 am »


               Works as advertised! Much appreciated.