Jump to content

Script help: GetEnchantment() not working for player-made enchantments...?


steelfeathers

Recommended Posts

Okay, having another SKSE problem.

 

SKSE version 1.7.2 has a function called GetEnchantment() that can be called on Armor, Weapon, or ObjectReference. If it's called on an ObjectReference, it's only supposed to work if the enchantment is player made.

 

Here's the exact SKSE documentation:

  Quote

 

; Returns the player-made enchantment if there is one
Enchantment Function GetEnchantment() native

 

 

 

But here's the problem - IT DOESN'T WORK for objectreferences. Works fine for BaseObject armor and weapons, but it always returns null when I try to use it on a weapon/armor enchanted by the player.

 

Please help! I've got some really cool enchanting perks in my perk mod that just won't work without this function...

 

 

Here's a snippet of my code, so you can see what I'm doing. The debug message appears if I equip a "Ebony dagger of the inferno", but not if I enchant a sword with a fire enchantment. Aka, it's only working for enchantments that ARE NOT player-made.

 

 

  Quote
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
Utility.wait(0.5)

If ( akBaseObject as Weapon )
If ( (akBaseObject as Weapon).GetEnchantment().HasKeyword(MagicDamageFire) || akReference.GetEnchantment().HasKeyword(MagicDamageFire))
fireWpnEquip.Value = 1
debug.notification("Equipped weapons has a fire enchantment: " + fireWpnEquip.Value)
Endif

If ((akBaseObject as Weapon).GetEnchantment().HasKeyword(MagicDamageFrost) || akReference.GetEnchantment().HasKeyword(MagicDamageFrost))
frostWpnEquip.Value = 1
debug.notification("Equipped weapons has a frost enchantment: " + frostWpnEquip.Value)
Endif

If ( (akBaseObject as Weapon).GetEnchantment().HasKeyword(MagicDamageShock) || akReference.GetEnchantment().HasKeyword(MagicDamageShock))
shockWpnEquip.Value = 1
debug.notification("Equipped weapons has a shock enchantment " + shockWpnEquip.Value)
Endif
Endif
  Quote
EndEvent

 

 

Link to comment
Share on other sites

Let's say that you have enchanted an Ebony dagger with an enchantment that does fire damage. The problem is that you are calling the GetEnchantment function on akBaseObject, which is the base (unmodified) Ebony dagger that does not have an enchantment applied to it. Hence the lack of an enchantment.

 

You will probably have to make use of SKSE's WornObject script to get enchantments from equipped items. If the player-enchanted Ebony dagger was placed somewhere in the game world and not in a container or some character's inventory, then you could use the GetEnchantment function found in the ObjectReference script.

 

ObjectReferences tend to not be valid anymore once the ObjectReference is placed in a container or an NPC's inventory as the game engine "converts" most references to their base forms and increments the object count in the container instead of storing each reference. So if you pick up five unmodified Ebony daggers, then the game will essentially store them as:

 

- Ebony dagger (5 pcs)

 

instead of

 

- Ebony dagger

- Ebony dagger

- Ebony dagger

- Ebony dagger

- Ebony dagger

 

There are exceptions, which remain as valid ObjectReferences in containers, such as quest items and pre-enchanted items that are not fully charged. Player-enchanted items may also be valid ObjectReferences in containers.

Edited by mrpwn
Link to comment
Share on other sites

Thanks for the response, but if you look at my script, I check both akBaseItem (a non-player enchanted item) AND akReferenceItem, which I believe should be the one that holds a reference to an item created by the player. akReferenceItem always returns null.

 

I hope the thing about containers canceling out the objectreference sounds like it might be the problem, except that I can still do akReferenceItem.GetBaseObject() and get something. Does that mean the the objectreference hasn't been wiped out by being placed in my inventory?

Link to comment
Share on other sites

I missed the use of akReferenceItem when I had a quick look at the script.

 

The ObjectReference may still be valid then. The developers of SKSE may have mentioned the reason(s) for needing to implement the functions in the WornObject script in addition to the ones in the ObjectReference script, but I don't remember what those would be.

Link to comment
Share on other sites

The issue is not the function. The issue is that OnEquip will only pass an ObjectReference if the equipped item is persistent, which a player enchanted item is very unlikely to be.

 

For what you have done here there is really no need to use GetEnchantment. OnEquip fires for enchantments as well as items, so you can access the enchantment directly:

 

If(akBaseObject as enchantment)

;Code here.

Endif

 

In addition, I believe calling GetEquippedSpell when the player has an enchanted weapon equipped will return the enchantment. However I have not tested that yet. (It works for condition functions, but occasionally those wprk differently from their script function equivalent.)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...