 |
Using onHit event handler attached via quest alias to display player damage. |
Much of what I want to do with the Zombie Walkers mod involves scripting. Some of the scripting needs to happen when things are hit or killed which involves attaching scripts to Actors. Unfortunately, this isn't feasible or possible to directly attach scripts for the following reasons:
- attaching scripts to ALL humans would involve modifying a whole bunch of Actors in the CK (very very time consuming)
- attaching scripts to leveled list actors (like the Feral Ghouls) is NOT possible. The section is literally grayed out in the tool and a known limitation of the Creation Kit
- each Actor updated in the CK adds to the risk that a mod will conflict with others (and increases the mod size)
Fortunately, there are ways to dynamically attach scripts to Actors. :)
Magic Effects
The first involves applying a magic effect to an Actor. A magic effect is essentially a script that runs to do something to an actor and you can create your own custom types.
For example, early on in the mod I figured out that you can attach a spell to the unarmed feral ghoul attack. Spells can apply a custom magic effect to register for events like hit or death and respond. In my case, I used this approach to monitor an NPC for hit events and then when they died resurrect them as a zombie.
Unfortunately, you need to apply the magic effect in some fashion for this to work. There's no easy way to just apply a magic effect to all actor types. For my NPC resurrection, the effect is applied when an NPC is hit by a zombie (which makes sense for my mod), but what if we wanted to resurrect NPCs Walking Dead style where a previous scratch/bite is not required?
Hidden Quest Aliases
Another, more flexible approach to dynamically attaching scripts to actors is via a hidden quest. Quests can be created that are never visible to the player and have pretty advanced functionality associated with them.
One such piece of functionality has to do with quest aliases. Aliases are basically references to objects in the game world that dynamically "bind" to a quest through a set of rules. When the quest begins, the first thing it does is bind all it's quest aliases. If any quest aliases are marked as required and cannot be bound for some reason, then the quest will fail to start.
 |
ReferenceAlias for Zombie closest to the Payer that binds ZombieScript to the Zombie |
Quest aliases are defined in the Creation Kit using the UI above and have different options like specifying a Unique Actor (like the Player) or Find Matching Reference which searches the area for a match closest to some reference point. Once an alias is bound/filled, any scripts you have defined in the Papyrus Scripts section are bound to that reference and can be used to register for events on the Actor.
You can define multiple aliases "Closest To" Player and each will bind to a different Zombie as long as the "Allow Reuse in Quest" checkbox is NOT checked. Each alias is unique, so once the closest Zombie is bound, the next alias searching for closest will select the next closest, and so on.
Current uses in Zombie Walkers
NPC Resurrection is using the Magic Effect to resurrect NPCs when they die by monitoring the onHit event.
Sleep Interruption is using the Quest Alias on the Player to register for sleep events to randomly trigger a settlement attack or spawn zombies nearby and wake up the player early.
The Zombie Walkers Holotape is automatically added via the hidden quest initialization script. It uses a timer to check if the player has received the pipboy (from the vault 111 quest) before assigning since the Player inventory may reset before then.
Possible Future uses in Zombie Walkers
- update NPC Resurrection by adding a Walking Dead style mode that resurrects NPCs regardless of how they died by registering for onDeath.
- enhance melee using on onHit event handler to possible do more damage and stagger/knockdown?
- add optional headshots only mode where zombies respawn if they die and their head was not crippled/dismembered.
- add configuration options for various things like zombie damage resistance
I'm sure plenty more options will reveal themselves in the future, but I wanted to give a flavor of the types of things that these approaches enable for the Zombie Walkers mod.
References
For the quest alias magic, I found some excellent resources that basically steered me in this direction so I wanted to list a couple of them here.
Note: some functions references in the articles above like RegisterForUpdate and RegisterForSingleUpdate are not present anymore in the CK and have been replaced in with Timers.
0 comments: