OK so I've made some custom item properties which, after some issues, are now working nicely. However, I realised there're no functions to add them through script. Is there any way this would be possible (I'm guessing no but hoping someone might know better). Can you modify the subcomponents of an itemprop type as you might with a vector or other struct, perhaps? Maybe a long shot but it would be really handy to be able to this.
Adding a Custom Item Property Through Script
Débuté par
The Fred
, août 13 2010 11:21
#1
Posté 13 août 2010 - 11:21
#2
Posté 13 août 2010 - 02:25
use tag based scripting i_XXX_hc to run the script on hit, else you're on to 2da editing I'm afraid to add new item properties
#3
Posté 13 août 2010 - 03:23
You can also combine the tag-based scripts into a single script, depending on your module settings. See the 'x2_it_example' file.
#4
Posté 13 août 2010 - 09:38
The problem is not creating the property (that did indeed require 2da editing but I've done that) or making the property do something (I didn't use tagbased scripting but I did use the item events), but actually adding it to an item through script - for example, if I wanted to add the property to an item through crafting or whatever. The item properties themselves are mostly for display purposes at the moment.
#5
Posté 13 août 2010 - 09:57
Is the property you are looking to add only for specific items or are you looking to be able to add it to any item?
For item specific use the tag system and require an int for the property to work then through a script you can add the int and the item proiperty will work.
For item specific use the tag system and require an int for the property to work then through a script you can add the int and the item proiperty will work.
#6
Posté 14 août 2010 - 01:14
OK, what I'm trying to do at the moment is this. I'm implementing (my own version of) the Taint rules (from Heroes of Horror, I think), and certain items are supposed to be able to absorb taint (stopping it from affecting you). So, I've made a custom item property (taint absorption) with a subtype which represents the number of points of taint the item can still absorb (e.g. Tain Absorption: 3). When it does absorb some taint, I want to lower that, which I would normally do by checking the subtype, removing the property, working out the new subtype, and then adding a new property with that subtype.
The issue is that I can't create the new property in script, because there's no ItemPropertyTaintAbsorption() function (obviously). What I'm wondering is if it's possible to create a custom item property somehow (I know it might be a long shot but I thought it'd be worth asking).
This issue I can probably deal with by using item charges (though that means I can't have charged items with taint absorption - not that I'm likely to want them, mind), but there are other instances in which I'd like to be able to add a property to an item, too.
The issue is that I can't create the new property in script, because there's no ItemPropertyTaintAbsorption() function (obviously). What I'm wondering is if it's possible to create a custom item property somehow (I know it might be a long shot but I thought it'd be worth asking).
This issue I can probably deal with by using item charges (though that means I can't have charged items with taint absorption - not that I'm likely to want them, mind), but there are other instances in which I'd like to be able to add a property to an item, too.
#7
Posté 14 août 2010 - 05:41
You want a custom propety to be added to an item here you go :
Create the property :
You have 2 solutions, both can be better than the other depending on the effect you are doing.
First a tag based scripting that can activate a script on the heartbat, or on the on hit or on the get damaged or on the get spell casted at event or any event you want.
You need to store a LocalVar somewhere to know when the item is equiped or not that you set with tag based scripting, and then you use a "if" statement on your event or heartbat script with that local var. Then you can fire a custom script or function that is doing your effect.
The second possibility is 2DA editing. You edit the 2DA corresponding of what you wanna do, set your custom spell in it, and then you can attach a custom effect to an item. That the technical superior solution but you can't do everything unlike the other solution. This solution is the one to pick each time it's possible over the other one.
Using the property :
Now you want to put an existing property (custom or not ) on an item.
Tag based scripted with a local var to know if the item has the property or not. This one could work but you have to be cautious when using it, beceause you'll have to check for the property each time it's supposed to be activated. It can quickly becommes heavy, especially if it's an on hit property.
Second solution check the craft script for the OC or SOZ or MOTB and see how it's done.
check property function :
// adds an item property to the specified item
// Only temporary and permanent duration types are allowed.
void AddItemProperty(int nDurationType, itemproperty ipProperty, object oItem, float fDuration=0.0f);
For custom effect, the ipProperty will be the one you defined in the 2DA for exemple.
// removes an item property from the specified item
void RemoveItemProperty(object oItem, itemproperty ipProperty);
Some custom effect can not be done with the 2DA editing. Those that can change behaviors on event that aren't directly linked to the item. For those those one you'll need to work with tag based and event scripting.
In your case I would do all the absorb taint possible with the 2DA editing method. And then Affect them or remove them with the 2 functions mentionned just above.
But you could do it with event scripting as well. Event scripting are more powerfull but I believe more costy for the computer. So I think it's better to use it only when 2da editing is not enought.
Create the property :
You have 2 solutions, both can be better than the other depending on the effect you are doing.
First a tag based scripting that can activate a script on the heartbat, or on the on hit or on the get damaged or on the get spell casted at event or any event you want.
You need to store a LocalVar somewhere to know when the item is equiped or not that you set with tag based scripting, and then you use a "if" statement on your event or heartbat script with that local var. Then you can fire a custom script or function that is doing your effect.
The second possibility is 2DA editing. You edit the 2DA corresponding of what you wanna do, set your custom spell in it, and then you can attach a custom effect to an item. That the technical superior solution but you can't do everything unlike the other solution. This solution is the one to pick each time it's possible over the other one.
Using the property :
Now you want to put an existing property (custom or not ) on an item.
Tag based scripted with a local var to know if the item has the property or not. This one could work but you have to be cautious when using it, beceause you'll have to check for the property each time it's supposed to be activated. It can quickly becommes heavy, especially if it's an on hit property.
Second solution check the craft script for the OC or SOZ or MOTB and see how it's done.
check property function :
// adds an item property to the specified item
// Only temporary and permanent duration types are allowed.
void AddItemProperty(int nDurationType, itemproperty ipProperty, object oItem, float fDuration=0.0f);
For custom effect, the ipProperty will be the one you defined in the 2DA for exemple.
// removes an item property from the specified item
void RemoveItemProperty(object oItem, itemproperty ipProperty);
Some custom effect can not be done with the 2DA editing. Those that can change behaviors on event that aren't directly linked to the item. For those those one you'll need to work with tag based and event scripting.
In your case I would do all the absorb taint possible with the 2DA editing method. And then Affect them or remove them with the 2 functions mentionned just above.
But you could do it with event scripting as well. Event scripting are more powerfull but I believe more costy for the computer. So I think it's better to use it only when 2da editing is not enought.
Modifié par Shallina, 14 août 2010 - 06:03 .
#8
Posté 14 août 2010 - 09:25
The problem is not the implementation of the itemproperty but creating the variable.
For example, if I want to add a +5 enchantment bonus to a sword, I use this:
But how would I add a custom property? It's looking like it's not possible, I was just hoping there was something I've missed.
For example, if I want to add a +5 enchantment bonus to a sword, I use this:
itemproperty iPlus5 = ItemPropertyEnchancementBonus(5);
AddItemProperty(DURATION_TYPE_PERMANENT, oPlus5, oSword);
But how would I add a custom property? It's looking like it's not possible, I was just hoping there was something I've missed.
#9
Posté 14 août 2010 - 09:40
You need to edit that 2da file and put a reference to your custom spell. Then you can add it via script.
itemproperty ItemPropertyCastSpell(int nSpell, int nNumUses);
or
// Creates an item property that (when applied to a weapon item) causes a spell to be cast
// when a successful strike is made, or (when applied to armor) is struck by an opponent.
// - nSpell uses the IP_CONST_ONHIT_CASTSPELL_* constants
itemproperty ItemPropertyOnHitCastSpell(int nSpell, int nLevel);
And you need to define your custom property as a spell in the correct 2da file.
Then you'll pass the ref number of the spell in parameter. I have created custom spell that I have attached to item for the BGremake. The spell that increase the stats by 1 permanently for the tome of stats increase for exemple.
itemproperty ItemPropertyCastSpell(int nSpell, int nNumUses);
or
// Creates an item property that (when applied to a weapon item) causes a spell to be cast
// when a successful strike is made, or (when applied to armor) is struck by an opponent.
// - nSpell uses the IP_CONST_ONHIT_CASTSPELL_* constants
itemproperty ItemPropertyOnHitCastSpell(int nSpell, int nLevel);
And you need to define your custom property as a spell in the correct 2da file.
Then you'll pass the ref number of the spell in parameter. I have created custom spell that I have attached to item for the BGremake. The spell that increase the stats by 1 permanently for the tome of stats increase for exemple.
Modifié par Shallina, 14 août 2010 - 09:42 .
#10
Posté 15 août 2010 - 11:31
The property is a passive property rather than an active (i.e. spell-like) one, however, like an enchancement, AC or damage bonus, for example. So rather than define a new spell, I've defined a new property, which I can add to items just fine in the toolset. What I'm wondering is if there's any way to add it through script.
#11
Posté 15 août 2010 - 11:37
itemproperty ItemPropertyOnHitCastSpell(int nSpell, int nLevel);
#12
Posté 16 août 2010 - 02:58
In this case at least, it's a defensive property, not an OnHit one.
#13
Posté 16 août 2010 - 03:28
IF it's a spell you'll have to use tag based scripting and event scripting. By default I don't think NWN2 is supporting those thing.
#14
Posté 16 août 2010 - 07:53
The problem is not making the item do what I want it to do, rather making it look like it has a property. Afaik, it's not possible to make custom properties which do things, but you can create a custom, display-only property (which I what I've done) and then use event-based scripting (tagbased or not) or whatever to do the actual stuff. So I can make an item do something interesting, like giving a Protection from Evil or other spell effect while equipped, and I can make it look in its description as though this is a new custom property. However, what I'm tying to do is actually add the item property through script e.g. by using AddItemProperty - the only problem is that that takes an itemprop variable which I can't create.
To be honset it's looking like it's not possible, I was just hoping someone else might know otherwise.
To be honset it's looking like it's not possible, I was just hoping someone else might know otherwise.
#15
Posté 17 août 2010 - 11:18
doesn't the int default to the row in the 2da?
or you could define it by editing nwscript.ncs?
or you could define it by editing nwscript.ncs?
#16
Posté 17 août 2010 - 11:23
Shallina wrote...
IF it's a spell you'll have to use tag based scripting and event scripting. By default I don't think NWN2 is supporting those thing.
Just a note, by default NWN2 DOES support these things (they are turned on).
#17
Posté 17 août 2010 - 03:23
WyrinDnjargo wrote...
doesn't the int default to the row in the 2da?
or you could define it by editing nwscript.ncs?
Alack, AddItemProperty() doesn't take an int, it takes an itemproperty variable, which is kind of the problem (because of course I do have an int for my custom property, defined in the 2da as you say, and this works fine with GetItemPropertytype()).
I don't really know about editing nwscript.
#18
Posté 17 août 2010 - 03:25
My thoughts were that the itemproperty type is probably just a kind of struct, so just as you can do something like this:
with a vector, you might be able to hand-edit, so to speak, an itemproperty. Failing that, might one be able to copy an itemproperty from an one item to another? Then you could create an item which stores all your custom properties on it (kind of like a property bank).
vector vVector;
vVector.x = 3.0;
with a vector, you might be able to hand-edit, so to speak, an itemproperty. Failing that, might one be able to copy an itemproperty from an one item to another? Then you could create an item which stores all your custom properties on it (kind of like a property bank).
#19
Posté 02 septembre 2010 - 04:46
OK the item property bank idea seems to be working, believe it or not. I'll post up the script if anyone wants it.
#20
Posté 04 décembre 2010 - 03:54
Hi I am actually interested in the script and the procedure you used to add the item properties in the 2da's. Is there a tutorial or any information on how this can be done? If you can point me anywhere or provide some basic information I'd appreciate it.
#21
Posté 06 décembre 2010 - 02:49
OK well it's far from fresh in my memory, but basically I created an item with all my custom properties on it and placed it in a hidden location in the module. Then I have some functions which search through its properties to find one which matches the property you want and copies it.
I'll rumage around in my module and see if I can find it later.
I'll rumage around in my module and see if I can find it later.





Retour en haut






