Project Zomboid

Project Zomboid

Not enough ratings
Safehouse Delay Protection
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
5.207 KB
27 Jul @ 8:48am
27 Jul @ 8:57am
2 Change Notes ( view )

Subscribe to download
Safehouse Delay Protection

Description
Note: Unfortunately, I was not able to get the mod to work as intended. The delay is not being applied correctly after players disconnect. I’m sharing this detailed explanation in hopes that another developer can identify the problem and help make it work.

Mod Name: Safehouse Delay Protection
Compatibility: Project Zomboid Build 41.78.16
Category: Server-side / PvP / Safehouse Logic

Purpose
This mod adds a configurable random delay before reactivating safehouse protection after the last member of the safehouse logs off the server. It is designed to work alongside the vanilla setting:

DisableSafehouseWhenPlayerConnected=true

That vanilla option disables safehouse protection while any member is online. This mod only activates when all members are offline and aims to prevent "combat logging" or "tactical logout" abuse in PvP environments.

How It Works

Every 10 in-game minutes, the mod checks all registered safehouses on the server.

If it finds a safehouse with no online members, it starts a countdown using a random delay (in seconds) defined by two sandbox values: MinDelayMinutes and MaxDelayMinutes.

If any member logs back in before the timer ends, the countdown is cancelled, and protection remains disabled (as per the vanilla setting).

If no one reconnects and the timer finishes, the mod reactivates the safehouse protection by calling setRespawnAllowed(true).

Configuration Parameters

Defined in the file sandbox-options/SafehouseDelayOptions.lua:

MinDelayMinutes: minimum time before protection is reactivated

MaxDelayMinutes: maximum time before protection is reactivated

The function getRandomDelay() picks a random value in this range and converts it to seconds.

Mod Folder Structure

SafehouseDelayProtection/
├── mod.info
├── workshop.txt
├── media/
│ └── lua/
│ ├── server/
│ │ └── SafehouseDelay_Server.lua
│ └── shared/
│ └── SafehouseDelay_Config.lua
└── sandbox-options/
  └── SafehouseDelayOptions.lua

Core Logic

Main logic is located in SafehouseDelay_Server.lua, which is server-side only.

The event Events.EveryTenMinutes calls checkSafehouses().

That function iterates through SafeHouse.getSafehouseList() and checks each safehouse.

It determines if members are online by using getPlayerByOnlineID(id).

If no members are found, it logs the current timestamp plus the delay as the scheduled time for protection to be reactivated.

If the current time matches or exceeds that timestamp, the protection is turned back on using setRespawnAllowed(true).

Optional: This timestamp can be stored in ModData to persist through server restarts.

Vanilla Dependency

The server must have the following setting enabled in servertest.ini:

DisableSafehouseWhenPlayerConnected=true

Without this, the mod is unnecessary since the vanilla game will already keep safehouses protected even with members online.

Known Limitations

In the current version, the timer does not persist between server restarts. If the server is restarted during the countdown, protection is reactivated immediately. This can be fixed by storing the data in ModData.

The mod only controls reactivation of protection via safehouse API. It does not block container access, door interactions, or griefing.

No in-game UI or notifications are provided to players at this time.

Testing Recommendations

Set the sandbox delay to short values, like 1–2 minutes.

Start the server with DisableSafehouseWhenPlayerConnected=true.

Join a safehouse with a test player.

Disconnect the player and observe the server console/log for delay messages.

Reconnect before the delay ends to test if the timer is canceled.

Wait until the delay expires to confirm the protection is reactivated.

Future Improvements

Persist timer using ModData to survive server restarts

Admin UI for adjusting delay settings in-game

Player-facing notifications or countdown messages

Enhanced logging or integration with server admin logs

If you’re a developer reading this and can spot why the timer or delay isn’t applying correctly, feel free to improve or fork this. I hope it serves as a good starting point or foundation for solving this important PvP issue.

Workshop ID: 3535954743
Mod ID: SafehouseDelayProtection