Possible to add scripts to objects dynamically?

Post » Thu Jun 21, 2012 6:37 am

Anyone have an idea how I could dynamically add scripts to items in game? I know it is possible with actors using spells and cloaks, but I can't seem to figure out how to do a similar thing with items.

For example, there are ten items strewn about the character, I want to add a script to each of them dynamically so that something happens when any of them are picked up. In the creation kit I could easily add a script to any item I want, but during run time I don't know what the ten items are so I need to add the script to the item on the fly once I have the object reference.

Hopefully this makes sense??
User avatar
john page
 
Posts: 3401
Joined: Thu May 31, 2007 10:52 pm

Post » Thu Jun 21, 2012 3:30 pm

You can use aliases for this, same as you can with NPCs. Have a quest, add aliases for your objects, and put scripts on the aliases. You can set up the aliases to be filled with your objects at run time in various ways, including using ForceRefTo().
User avatar
Juan Suarez
 
Posts: 3395
Joined: Sun Nov 25, 2007 4:09 am

Post » Thu Jun 21, 2012 8:13 am

Ok, I have never uses aliases before, is there a tutorial or example I can follow somewhere?

If I understand your answer correctly, I create an alias script that has somethine like this:
Event OnActivate(objectReference heWhoActivatedMe)    doSomeStuffendEvent
When my character enters a room with an item in it, some spell or technique is used to get the items object reference, then I set this item reference to my alias reference using itemReference.ForceRefTo(aliasReference). Then running the function aliasReference.Activate(player) will run the activation script above on the object?
User avatar
David Chambers
 
Posts: 3333
Joined: Fri May 18, 2007 4:30 am

Post » Thu Jun 21, 2012 1:36 pm

Well, the wiki has http://www.creationkit.com/Bethesda_Tutorial_Quest_Aliases and http://www.creationkit.com/Dynamically_Attaching_Scriptsand http://www.creationkit.com/Quest_Aliases, but I found http://www.youtube.com/user/doughamil very helpful as well.

Yes, to your second question. As to 'some spell or technique': aliases are filled when your quest is started, unless they're set to Specific reference: Forced: empty (which you'd fill later with ForceRefTo). So if you started your quest on entering the room (perhaps by using the StoryManager's ChangeLocation event to start the quest), you might be able to use FindMatchingReference (InLoadedArea Closest, or NearAlias Player) on the ReferenceAlias page to fill the alias. Otherwise you might look at the FindClosest... and FindRandom... papyrus methods, or use the parameters of an event, depending on what you're doing exactly.
User avatar
Amanda savory
 
Posts: 3332
Joined: Mon Nov 27, 2006 10:37 am

Post » Thu Jun 21, 2012 9:44 am

Thanks for the info, looks like I have some reading to do.
User avatar
Brian LeHury
 
Posts: 3416
Joined: Tue May 22, 2007 6:54 am


Return to V - Skyrim