This page collects practical patterns for integrating HyCitizens into your own Hytale plugin. Each example is self-contained and focuses on a single common use case — combine them freely to build more complex NPC systems.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ElectroGamesDev/HyCitizens/llms.txt
Use this file to discover all available pages before exploring further.
Shop Keeper NPC
Create aCitizenData with an F-key command action that opens a shop when a player interacts with it. The CommandAction constructor accepts the command string, a flag for whether to run it as the server, an optional delay, the interaction trigger ("F_KEY", "LEFT_CLICK", or "BOTH"), and a chance percentage.
Cancelling Interactions Conditionally
Register aCitizenInteractListener via CitizensManager.addCitizenInteractListener() to intercept interactions before HyCitizens processes them. Call event.setCancelled(true) to suppress all commands and messages for that interaction. Listeners are called in registration order and stop as soon as one cancels the event.
Reacting to Citizen Death
Register aCitizenDeathListener via CitizensManager.addCitizenDeathListener() to react when a Citizen is killed. The event exposes the CitizenData and the optional PlayerRef of the killer. Calling event.setCancelled(true) prevents the default respawn logic from running.
Finding Nearby Citizens
CitizensManager.getCitizensNear() performs a simple 3-D distance check against each Citizen’s stored position and returns all Citizens within the given radius. The check uses the Citizen’s last known position (currentPosition) rather than querying the live entity transform, making it safe to call from any thread.
Respawning a Group of Citizens
CitizensManager.respawnCitizensInGroup() queues a full despawn-and-respawn cycle for every Citizen in the named group. Pass true for includeChildren to also affect sub-groups. The method returns the number of Citizens that were queued for respawn.
All
CitizensManager methods are thread-safe and can be called from any thread. Internally, operations that touch live world entities (spawning, despawning, position updates) are dispatched onto the world thread via World.execute().