I've been trying to follow these instructions to dynamically attach a script to weapons (in order to produce a durability mod) - I'm pretty well convinced that I do need to do attach a script to the object specifically and we need to store data on the object - (this may be simple).
I need the script on the object as I want to implement OnHit on the object itself (unless someone can come-up with a better solution)...
The script may only need to stay on the object long enough to trigger the OnHit - as I hope that DamageObject and GetItemHealthPercent is going to work - so we may be able to hard-code perhaps 30 aliases to support 15 actors each with 2 weapons/shields.
The problem I am having is getting the items into the aliases, I've tried things like the following with no joy:
(AliasesQuest.getAlias(AliasesRightHand) as ReferenceAlias).ForceRefTo((RightWeapon as ObjectReference))
Spoiler Scriptname ScarabDurabilityActorScript extends ReferenceAlias;=============== PROPERTIES ==========================================;Quest property AliasesQuest autoInt property AliasesRightHand autoInt property AliasesLeftHand auto;=============== VARIABLES ==========================================;Actor ThisWeapon RightWeaponWeapon LeftWeapon;=============== EVENTS ==========================================;Event OnInit() This = Self.GetActorReference() Debug.MessageBox("We have ScarabDurabilityActorScript running on: " + This ) Debug.Trace("We have ScarabDurabilityActorScript running on: " + This ) RightWeapon = This.GetEquippedWeapon(false) LeftWeapon = This.GetEquippedWeapon(true) Debug.MessageBox(This + " is armed with: "+ RightWeapon + "&" + LeftWeapon) Debug.Trace(This + " is armed with: "+ RightWeapon + "&" + LeftWeapon)EndEventEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference) if akBaseObject as Weapon Debug.Trace("This actor just equipped a weapon!") RightWeapon = This.GetEquippedWeapon(false) LeftWeapon = This.GetEquippedWeapon(true) (AliasesQuest.getAlias(AliasesRightHand) as ReferenceAlias).ForceRefTo((RightWeapon as ObjectReference)) (AliasesQuest.getAlias(AliasesLeftHand) as ReferenceAlias).ForceRefTo((LeftWeapon as ObjectReference)) endIfendEventEvent OnCombatStateChanged(Actor akTarget, int aeCombatState) if (aeCombatState == 0) Debug.MessageBox(This + " has left combat!") Debug.Trace(This + " has left combat!") elseif (aeCombatState == 1) Debug.MessageBox(This + " has entered combat! Armed with: "+ RightWeapon + "&" + LeftWeapon) Debug.Trace(This + " has entered combat! Armed with: "+ RightWeapon + "&" + LeftWeapon) Debug.MessageBox("Initiate Durability quest") elseif (aeCombatState == 2) Debug.MessageBox(This + "is searching...") Debug.Trace(This + "is searching...") endIfEndEvent
Compiler output:
Spoiler
C:\Program Files (x86)\Notepad++>"C:\Program Files (x86)\Steam\SteamApps\Common\
Skyrim\Papyrus Compiler\PapyrusCompiler.exe" ScarabDurabilityActorScript.psc -f=
"TESV_Papyrus_Flags.flg" -i="C:\Program Files (x86)\Steam\SteamApps\Common\Skyri
m\Data\Scripts\Source" -o="C:\Program Files (x86)\Steam\SteamApps\Common\Skyrim\
Data\Scripts"
Starting 1 compile threads for 1 files...
Compiling "ScarabDurabilityActorScript"...
C:\Program Files (x86)\Steam\SteamApps\Common\Skyrim\Data\Scripts\Source\ScarabD
urabilityActorScript.psc(30,88): cannot cast a weapon to a objectreference, type
s are incompatible
C:\Program Files (x86)\Steam\SteamApps\Common\Skyrim\Data\Scripts\Source\ScarabD
urabilityActorScript.psc(31,86): cannot cast a weapon to a objectreference, type
s are incompatible
No output generated for ScarabDurabilityActorScript.psc, compilation failed.
Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on ScarabDurabilityActorScript.psc
C:\Program Files (x86)\Notepad++>Pause
Press any key to continue . . .
Any thoughts?