 |
A settler before and after zombification. |
NPC Resurrection was one of the first advanced features added to Zombie Walkers way back in the beta days during version 0.4. The idea is simple, any human NPC hit by a zombie will become a zombie when they die. This is consistent with zombie lore in that the infection spreads from victim to victim. Some compromises in the implementation had to be made, which I'll discuss below, but overall I think it accomplished the goal and is actually a unique feature to this mod.
Implementation
The feral ghoul unarmed weapon was updated to cast a hidden spell on a victim that is hit. If the victim is human, it adds a RaiseAsZombiePerk to the actor. This perk registers for the onDying event of the Actor it is attached to and when that event is triggered does the work of converting the Actor to a zombie.
I did some research and experimentation to determine the best approach to zombify the Actor. Ideally I wanted the new zombie to resemble the Actor but behave like a feral ghoul. This became difficult however due to some limitations I ran into very quickly.
Race is tied to the Actor Base type and if changed affects ALL actors spawned from that base
This is a big one. Many NPCs, like Raiders, are spawned from Leveled Lists. Leveled List actors share a common base type which is tied to a race. This means changing the race on any one of these will change it for ALL of them. In the context of this mod, changing a Raider that was killed by a zombie into a zombie by setting the race would mean all Raiders spawned from that base type would become zombies (not what we want).
Due to this, the only actor types that you can safely change the race for are unique actors since they do not share their type with others. Unique actors are few and far between and many are marked protected/essential. However, these flags can be cleared by the Zombie Walkers holotape (or other mods) so I decided to handle unique actors differently so that at least unique actors would look like they did. For non-unique actors however, I would have to spawn a brand new actor and transfer inventory.
Why is race important? It controls many behaviors of an actor to make them more zombie like including their body part damage distribution, default voice, unarmed weapon, etc.
Functions to get facial features (hair, eyes, etc.) do not exist without F4SE
The problem with spawning a brand new actor is that they now look nothing like their old self (especially their face). This problem is compounded when methods to get facial features are absent from the CK. For example, I have not yet found a way to get their hairstyle and apply it to the new zombie actor replacing them.
Now I had to decide what to spawn. Do I spawn a bald, generic human or something else? I ended up spawning a Ghoul to replace them since they sort of look zombified anyway. I created both a male and female Ghoul NPC as a base that is assigned to the new ZombieGhoul race.
Humans/Ghouls use a different skeleton than Feral Ghouls and therefore can't use their animations
This one is unfortunately and is why the NPC zombies walk like boxers and punch like them too instead of clawing and biting. I experimented with trying to force the animations and while you can do that they just don't work. The NPC becomes a strange ball of flesh with parts where they shouldn't be.
Longer term, I'd like to revisit the animations at least to see what can be done in replacing and removing ones that do not look right. For example, it'd be nice to replace the walking with fists up combat movement with simple walking. It'd also be nice to eliminate some of the punching attacks, like the one they seem to do first that has them charging forward with a power punch.
At one point I considered trying to "fake" it and give NPC zombies a hidden knife to fight with so that it would look like they are slashing at least. Of course, this would require kill animations be disabled and I'm not even sure if it would work or exactly how it would look.
Transferring Items
For the non-unique Ghoul zombies, they spawn naked with no items. Therefore, I had to transfer all the items from the old actor over to them using
RemoveAllItems. This puts the items in the inventory so they are available for loot, but it does not equip items the old actor was wearing.
To equip items, I used
OnItemAdded in a script attached to the Ghoul NPC. Each item added was checked to see if it was one of a predefined list of keywords and if so it was equipped. This has problems though in that keywords are not consistently applied and many users have reported the occasional naked zombie as a result.
A better approach that I am going to explore is to use
OnItemUnequipped. This should be triggered by the old dead actor when items are unequipped as part of being transferred to the new actor. When triggered, I can then equip the item on the new actor (in theory).
A note regarding weapons
In the base game, weapons like guns are dropped when an actor is killed. These weapons are still associated with the actor and are cleaned up by the game when the actor is eventually disabled or the cell resets. However, there appears to be a bug with RemoveAllItems in that these weapons are NOT included in the inventory list that is transferred to the new actor. Therefore, that loot is lost when an actor is zombified.
To address this, I set the global property iDeathDropWeaponChance to 0 to avoid weapons actually being dropped. This results in actors with weapons still in their hands (sometimes at weird angles) and includes them in the inventory list for the item transfer.
Future
NPC Resurrection was one of the first advanced features implemented as I was initially learning to mod. I've been meaning to revisit it for some time but have been busy adding other features that I felt were missing. The biggest thing is I'd really like to venture into the realm of animations and figure out how to make them behave a little more like the Feral Ghouls in the game.
I'm working on a new feature for player permadeath which will feature the player's old character being turned into a zombie similar to how NPCs are. I'm already running into many of the same limitations, but this may finally force the revisit that I've been planning on so stay tuned as this feature may finally get some long overdue love.
4 comments: