Deleted2838758User Posted October 2, 2015 Posted October 2, 2015 (edited) I'm trying to create a scripted spell that allows the player to temper a spell Event OnEffectStart(Actor AkTarget, actor AkCaster) Caster = AkCaster ObjectReference AlteredWeapon = Caster.getEquippedWeapon() Float Magnitude = Self.GetMagnitude() Int i = 0 While (i < Material.Length) If AlteredWeapon.HasKeyword(Material[i]) if (Caster.GetItemCount(Ore[i]) >= 1) AlteredWeapon.setItemHealthPercent(Magnitude) advanceSkill("alteration", skillAdvancement * Magnitude) Else ; caster must have had no valid ore FailureSFX.play(caster) failureMSG.show() endIf Endif i += 1 EndWhile i = 0 AlteredWeapon = None EndEvent The only problem is that the "ObjectReference AlteredWeapon = Caster.getEquippedWeapon()" line doesn't work. I keep getting the message "cannot cast a weapon to a objectreference, types are incompatible" Edited October 2, 2015 by Guest
foamyesque Posted October 3, 2015 Posted October 3, 2015 Items in a container (e.g., in an actor's inventory, equipped or not) aren't object references (bar some exceptions not applicable here); they're the base forms. Hence, GetEquippedWeapon returns a type of Weapon, which is a subtype of Form, but not of ObjectReference, so you cannot cast the one to the other.
Deleted2838758User Posted October 3, 2015 Author Posted October 3, 2015 Items in a container (e.g., in an actor's inventory, equipped or not) aren't object references (bar some exceptions not applicable here); they're the base forms. Hence, GetEquippedWeapon returns a type of Weapon, which is a subtype of Form, but not of ObjectReference, so you cannot cast the one to the other.Oh wow, seems like this an extremely annoying limitation. Is there any work-around other than having to remove the item from the inventory before casting it into an Objectreference variable ?
foamyesque Posted October 3, 2015 Posted October 3, 2015 I'm not sure. Doing a chain cast [ObjectReference a = (b as Form) as ObjectReference] will compile, but I've not tested it in action. I would expect it to not work for what is needed; dropping it out of inventory, modifying it, and re-equipping it is how I believe mods like LOOT achieve similar effects.
Recommended Posts