Dynamically attaching scripts to Actors near the player

Post » Mon Jun 18, 2012 6:50 pm

Yeah, in oblivion I told my players not to start my Duke Patrick's Combat mods until after the tutorial, that part of the game was hell for many kinds of mods...


Actually.. people have reported that they didn't have issues with versions 2.30 and earlier, this specific issue only showed up in versions 2.40 and 2.50. 2.40 is exactly the version where I started using this method, but BEFORE that I actually already had a start game enabled quest with just the player alias, so I figured the problem isn't really in that after all. The difference is that from version 2.40 I started stopping and restarting the quest in order to update all other aliases, and that seems to cause the problem. So now I just made a quick fix not to update the quest until the main quest has progressed far enough that the player is no longer AI driven (and it also updates if that quest didn't start yet, in case users are using an alternate start mod) and that works.
User avatar
tannis
 
Posts: 3446
Joined: Sat Dec 09, 2006 11:21 pm

Post » Tue Jun 19, 2012 2:38 am

Thanks everybody!

You′ve made me realize I can use reference alias to target objects too! ( dooooooooors )hehehe

http://www.gamesas.com/topic/1352976-a-working-open-door-spell/
User avatar
Blessed DIVA
 
Posts: 3408
Joined: Thu Jul 13, 2006 12:09 am

Post » Mon Jun 18, 2012 6:22 pm

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?
User avatar
Kat Lehmann
 
Posts: 3409
Joined: Tue Jun 27, 2006 6:24 am

Post » Tue Jun 19, 2012 7:36 am

I think the problem is that RightWeapon and LeftWeapon are both base Forms (e.g. GetEquippedWeapon () doesn't return ObjectReferences)
and not ObjectReferences which point to objects in the game world.
User avatar
Gemma Archer
 
Posts: 3492
Joined: Sun Jul 16, 2006 12:02 am

Post » Tue Jun 19, 2012 9:29 am

Ahh yes, you are right!
ScriptName Weapon extends Form

Any ides on how to get a script to stick to an object?
User avatar
Tracy Byworth
 
Posts: 3403
Joined: Sun Jul 02, 2006 10:09 pm

Previous

Return to V - Skyrim