Zombie Controller - ZenarchistCode/ZenModPack GitHub Wiki

What Is This?

This mod allows scripted control over zombie movements.

Its main purpose is to prevent script-spawned zombies from wandering off on adventures.

For example, when an airdrop or SurvivorMission or DynamicHelicopterCrash mod spawns zombies into the game, they have no boundary limit, so if a player is patient (or the zombies are spawned before a player even comes close) then the zombies can wander off over time sometimes hundreds of meters away, leaving the target location unbothered by zeds so the player can loot the airdrop/mission/heli/etc without a challenge.

This mod forces any zombie which is NOT spawned by the Central Loot Economy (ie. vanilla XML files) to have a 20 meter radius where they will return "home" to their spawn point if they wander beyond this distance.

You can adjust this in the config, example provided below.

You can also use script code to tell zombies where to go. I haven't done much testing with this feature, but in theory you should be able to make zombies walk wherever you want them to go (assuming the path is not particularly challenging - I have not got advanced pathfinding code like the InediaAI mod does for example - my pathfinding is very simple and designed for zombies spawned in open areas).

Here is an example of how to tell a zombie to walk to a location (ideally this location should be reasonably close by to where the zombie currently is, like within 100 meters):

void ZenStartMoveToTarget(vector pos, float minDist = 1, bool overridePreviousCommand = false) {}

ZombieBase zed = SomeKindOfZombie();
zed.ZenStartMoveToTarget("123 0 123"); // Will walk to within 1 meter of 123,0,123 (surface Y automatically calculated)

Enabling the parameter overridePreviousCommand=true will force the zombie to cancel any currently active animation (ie. attacking, jumping etc) - not recommended, leave it off in most cases.

The parameter minDist is the minimum distance to the target before the zombie is no longer controlled by this movement code and allowed to return to its vanilla behaviour. If not specified then the zombie needs to be within 1 meter of the given position before it's given back to vanilla control.

You can also override its default wander range if you need to:

void SetZenZombieWanderRange(float radius = 0, vector homePos = vector.Zero, float minimumReturnDistance = 0) {}

// radius = Distance from "homePos" it's allowed to wander (0 = use JSON config MaxWanderRange)
// homePos = The vector location it considers its base/home return point (vector.Zero = use current position)
// minimumReturnDistance = vector.Distance(homePos, GetPosition()) < this value before it's considered within range of "home"

Below is a JSON config explanation.

Config Explanation:

Config file: profiles/Zenarchist/ZenZombieController.json

{
    "CONFIG_VERSION": "1", // Don't touch
    "CheckTimerSeconds": 10, // Check zombie distance every X seconds
    "MaxWanderRange": 20.0, // If zombie exceeds this distance from its spawn point, return home kicks in
    "MinimumReturnDistance": 0.3, // Minimum PERCENTAGE distance to home X wander range (ie. 0.3 x 20 = return within 6 meters of spawn point)
    "DisableControllerAfterAggro": 1, // Once a zombie is aggro'ed by a player, disable this controller forever and allow vanilla to take over
    "MinutesToWaypointTimeout": 5, // If zombie cannot get to the next waypoint within 5 minutes, give up entirely and let vanilla take over
    "TeleportIfNoPlayersNearby": 1 // If no player is within 500 meters, just teleport the zombie back to its spawn point instead of walking
}

Master Config

To disable this mod set "ZenZombieController": 0 in %server_profile/Zenarchist/Utilities/ZenModPackConfig.json