Adding properties to an item through scripting

I know I’ve asked about similar things before in another thread but I thought I would make a new one about this anyway.

I have an item where I want to put a few properties through scripting (the item needs to be empty at first since the properties may vary due to different circumstances). So I tried a few things and it was a bit odd. First I tried adding Haste through the following script, and that worked:

void main()
{
	
	object oPC = GetFirstPC();

	object oGenieToken = GetObjectByTag("genietok");
	
	itemproperty ipAdd = ItemPropertyHaste();

	AddItemProperty(DURATION_TYPE_PERMANENT, ipAdd, oGenieToken);
}

But then I also wanted to add bludgeoning damage like this:

void main()
{
	
	object oPC = GetFirstPC();

	object oGenieToken = GetObjectByTag("genietok");
	
	itemproperty ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_BLUDGEONING,IP_CONST_DAMAGEBONUS_1);

	AddItemProperty(DURATION_TYPE_PERMANENT, ipAdd, oGenieToken);
}

This second script doesn’t work for some reason. Any ideas how to make this second script work?

I found the solution! The problem was that I had made this item Base Item: Amulet and that somehow interfered with adding the damage bonus property. When changing the item to Base Item: Miscellaneous Small Object the scripting worked.

1 Like

hm, it might have something to do with the ItemActivation property on the item : Equipped and/or Inventory

I did the Active Only When In Inventory thing and I create the item in the PCs inventory beforehand, before adding the script.

1 Like

I found a possible problem with this kind of stuff.

When you use constant such as

IP_CONST_DAMAGETYPE_BLUDGEONING

and
IP_CONST_DAMAGEBONUS_1

Those value aren’t coming from the 2DA file but from a script that defines all constants : “nwnscript.nss”

Sometime they are on error or absent with their real value on the 2da files. What works is adding something with the 2da files values, if the constant in error in the “nwnscript.nss” then it won’t or it will add the value in the 2DA files that match the “hard value” of the constante.

1 Like

@Shallina - That’s interesting… Still, the ItemPropertyDamageBonus appears to require you to use the IP_CONST so… I haven’t looked in the 2da, though, if there’s some other solution to this.

In any way, for now it seems to work for me when using a Base Item: Miscellaneous Small Object instead of Base Item: Amulet.

I’m pretty sure that the real answer to this mystery is simply that certain object types do not support all item properties, so if you attempt to add an “illegal” item property, the action quietly fails.
You can check for this by opening an object of that type in the object editor and then looking at the list of item properties which you can add. If you can’t add a particular item property, then it won’t appear in the list of item properties. It’s my understanding that even a script can’t override that behaviour.
This makes sense when you think about it, because why would an amulet ever need to have a damage bonus added to it? It’s not a weapon and so it can’t be wielded. There is no reason why a “damage bonus” on an amulet would somehow transfer across to a weapon being wielded. It makes more sense to only allow a damage bonus on a weapon.
If you really wanted a damage bonus on whatever weapon the PC is wielding when a certain amulet is equipped, you could script the OnEquipItem event to do that, and the OnUnEquipItem event to remove it. It would be complicated since you have to account for unequipping the weapon and equipping a different weapon while still wearing the amulet, and you also have to account for missile weapons such as bows and for monk weapons like gloves, but it could probably be done if you have the time, patience and skill to put in the effort required.

3 Likes

@Melkior_Wiseman

good call/catch

 
details: ItemProps.2da is a table of itemproperties (that are allowed/disallowed) against itemtypes. The itemtype of an item can be found in BaseItems.2da under _PropColumn_

For an itemproperty to be allowed on an item, there should be a 1 in the field in ItemProps.2da

ipDamage →
    MiscSmall → allowed
    Amulet → not allowed

2 Likes

It’s the 2DA which govern it all.

Check that the constant value you are using is the correct value in the 2DA files.

If not try using the 2DA value instead of the const

1 Like