OptionalworldId: numberOptionalinternalServerPort: numberReadonly_Total amount of clients on the server
Readonly_Static spatial hash for destroyables — built once at startup since they never move.
Inverse observer index: entity characterId → clients that have it spawned. Maintained automatically by TrackedEntitySet in each client's spawnedEntities.
Networking layer - allows sending game data to the game client, lays on top of the H1Z1 protocol (on top of the actual H1Z1 packets)
Information from ServerItemDefinitions.json
Interactible options for items - See (ZonePacketHandlers.ts or datasources/ItemUseOptions)
Protected_Readonly_Determines which login server is used, Localhost by default.
Readonly_Handles all packets for H1Z1
Readonly_Readonly_Managers used for handling core functionalities
AI target map rebuilt every AI tick for spatial detection in JSMs.
OptionalaiOptionalchallengeOptionaldynamicReadonlygameOptionalinitialOptionalitemOptionalitemOptionalpathfindingOptionalprofileOptionalprojectileMANAGED BY CONFIGMANAGER - See defaultConfig.yaml for more information
import {
setImmediate,
} from 'node:timers/promises';
const res = await setImmediate('result');
console.log(res); // Prints 'result'
Optionalvalue: T
A value with which the promise is fulfilled.
Optionaloptions: TimerOptionsimport {
setTimeout,
} from 'node:timers/promises';
const res = await setTimeout(100, 'result');
console.log(res); // Prints 'result'
Optionaldelay: number
The number of milliseconds to wait before fulfilling the
promise. Default: 1.
Optionalvalue: T
A value with which the promise is fulfilled.
Optionaloptions: TimerOptionsOptionalrebootOptionalrecastOptionalweaponReadonlyworldStatic Readonly_Optional[captureThe Symbol.for('nodejs.rejection') method is called in case a
promise rejection happens when emitting an event and
captureRejections is enabled on the emitter.
It is possible to use events.captureRejectionSymbol in
place of Symbol.for('nodejs.rejection').
import { EventEmitter, captureRejectionSymbol } from 'node:events';
class MyClass extends EventEmitter {
constructor() {
super({ captureRejections: true });
}
[captureRejectionSymbol](err, event, ...args) {
console.log('rejection happened for', event, 'with', err, ...args);
this.destroy(err);
}
destroy(err) {
// Tear the resource down here.
}
}
Adds an item to a character's inventory.
The client adding the item.
The item to add.
The id of the container definition.
[character=client.character] - The character to add the item to.
#1467 (H14): recursively add a construction parent save-data node's whole
subtree of characterIds (slot maps + freeplace + expansions) to reachable.
Called per-foundation from saveWorld's build loop so the reachable set is
assembled incrementally rather than in a second synchronous walk.
Deletes multiple entities from the same dictionary in one optimised pass.
Cancels the currently playing emote for a character
The client whose emote should be cancelled
Clears a character's equipment slot.
The character to have their equipment slot cleared.
The equipment slot to clear.
OptionalsendPacket: boolean = true
Optional: Specifies whether to send a packet to other clients, default is true.
Returns true if the slot was cleared, false if the slot is invalid.
Clears all items from a character's inventory.
The client that'll have it's character's inventory cleared.
#1467 (H14): collect every characterId reachable from the construction save graph — each top-level foundation recursed through its slot maps, freeplace, and expansions, plus world-lootable. Pure; used by tests and the orphan backstop. At runtime saveWorld instead calls addReachableConstructionIds per foundation inside its (already-yielding) build loops, so this additive recursive walk shares the loops' yield cadence rather than running as a separate pass.
OptionaloverrideProjectileId: booleanOptionaleffectId: numberOptionaltimeToDisappear: numberRemoves a single item type from the inventory and spawns it on the ground
The character that should drop the item
The item object.
Optional: The number of items to drop on the ground, default 1.
The animation to play
Synchronously calls each of the listeners registered for the event named
eventName, in the order they were registered, passing the supplied arguments
to each.
Returns true if the event had listeners, false otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Returns an array listing the events for which the emitter has registered listeners.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
Optionalclient: ZoneClient2016#1467 (H14): return every player-construction entity live in the world dictionaries but NOT reachable from the save graph (an orphan that will be dropped on the next save). World-spawned construction lives in separate dictionaries and is intentionally not scanned. Yields periodically so a large server's scan never blocks the game tick in one synchronous burst.
Generates a new item with the specified itemDefinitionId and count.
The itemDefinitionId of the item to generate.
Optionalcount: number = 1
The count of the item.
OptionalforceMaxDurability: boolean = false
force the item to have his max durability.
The generated item, or undefined if the item definition is invalid.
Generates and returns an unused itemGuid.
The generated itemGuid.
Generates random equipment for a specific slot (Zombies only).
The ID of the slot.
The gender of the entity.
[excludedModels=[]] - The excluded equipment models.
The generated equipment.
Generates random equipment for the specified entity and slots (Zombies only). To be deprecated soon
The entity to generate equipment for.
The slots to generate equipment for.
[excludedModels=[]] - The excluded equipment models.
Picks a random drop spot inside the caller's grid cell (the playable 10x10 area spans -3720..3720, so each cell is 744 units) that avoids POIs, bases and vehicles. Ground height comes from the navmesh so drops land on walkable terrain, not inside buildings. Falls back to the caller's spot.
Returns a client object by either the characterId of the passed character, or the mountedCharacterId if the passed character is a BaseLootableEntity.
Either a Character or BaseLootableEntity to retrieve its accessing client.
Returns client or undefined.
Returns clients within radius of position using the char spatial map
(rebuilt every world tick) instead of scanning every character on the server.
Walks up a construction part's parent chain to the root foundation so an entire base (deck + expansions + their doors/shelters) can be treated as a single visibility unit. Returns the entity itself for non-construction entities or parts whose parent can't be resolved.
Gets the container definition for a given containerDefinitionId.
The id of the container definition to retrieve.
The container definition.
Gets the rewards for a given itemDefinitionId.
OptionalitemDefinitionId: number
The ID of the crate to retrieve rewards from.
The rewards.
Reverse-maps emote animationId -> emote itemDefinitionId from the loaded item definitions. Emote items are ITEM_TYPE 53, carrying PARAM1 = animationId and ACTIVATABLE_ABILITY_ID = the emote's activatable ability. Shared primitive for emote availability (skinItems.emotes) and the 0xa105 ability grants (see Character.getEmoteAvailability / pGetEmoteAbilities). Data-driven, no hardcoded item def ids.
Gets the firegroup definition for a given firegroupId.
The ID of the firegroup definition to retrieve.
The firegroup definition or undefined.
Gets the firemode definition for a given firemodeId.
The ID of the firemode definition to retrieve.
The firemode definition or undefined.
Returns all grid cells for a specific position and radius
Gets the max durability for a given itemDefinitionId.
OptionalitemDefinitionId: number
The ID of the item definition to retrieve.
The item definition or undefined.
Gets the item definition for a given itemDefinitionId.
OptionalitemDefinitionId: number
The ID of the item definition to retrieve.
The item definition or undefined.
Gets the first loadout slot that a specified item is able to go into.
The definition ID of an item to check.
OptionalloadoutId: number = LoadoutIds.CHARACTER
Optional: The loadoutId of the entity to get the slot for, default LoadoutIds.CHARACTER.
Returns the ID of the first loadout slot that an item can go into (occupied or not).
Gets a random reward for a given crate.
OptionalitemDefinitionId: number
The ID of the crate to retrieve rewards from.
Reward Item definition ID.
Gets the maximum value for a given resource.
The ID of the resource.
The maximum value of the resource (0 if undefined).
Generates a new transientId and maps it to a provided characterId.
The characterId to map the transientId to.
Returns vehicles within radius of position using the vehicle spatial map
(rebuilt every world tick) instead of scanning every vehicle on the server.
Gets the ammoId for a given weapon, resolved through the SELECTED firegroup/firemode. Multi-firegroup weapons (e.g. the crossbow) use different ammo per firegroup (0=wooden 112, 1=flaming 1434, 2=explosive 138); pass the weapon's current selection (weapon.currentFiregroupIndex/FiremodeIndex). Defaults to firegroup 0 / firemode 0, so single-firegroup weapons and generic callers behave exactly as before.
The itemDefinitionId of the weapon.
Selected firegroup index into the weapon def's FIRE_GROUPS (default 0).
Selected firemode index into the firegroup's FIRE_MODES (default 0).
The ammoId (0 if undefined).
Gets the clip size for a given weapon.
The itemDefinitionId of the weapon.
The clip size (0 if undefined).
Gets the weapon definition for a given weaponDefinitionId.
The ID of the weapon definition to retrieve.
The weapon definition or undefined.
OptionalitemDefinitionId: ItemsGets the maximum amount of ammo a clip can hold for a given weapon.
The itemDefinitionId of the weapon.
The maximum ammo (0 if undefined).
Gets the reload time in milliseconds for a given weapon.
The itemDefinitionId of the weapon.
The reload time in milliseconds (0 if undefined).
OptionalitemDefinitionId: numberChecks if an item with the specified itemDefinitionId is an armor.
The itemDefinitionId to check.
True if the item is an armor, false otherwise.
Optionalban: ClientBanChecks if an item with the specified itemDefinitionId is a boot.
The itemDefinitionId to check.
True if the item is a convey, false otherwise.
Optionalclient: ZoneClient2016Checks if an item with the specified itemDefinitionId is a construction type.
The itemDefinitionId to check.
True if the item is a generic type, false otherwise.
Checks if an item with the specified itemDefinitionId is a container.
The itemDefinitionId to check.
True if the item is a container, false otherwise.
Checks if an item with the specified itemDefinitionId is a convey.
The itemDefinitionId to check.
True if the item is a convey, false otherwise.
Checks if an item with the specified itemDefinitionId is footwear.
The itemDefinitionId to check.
True if the item is a boot, false otherwise.
Checks if an item with the specified itemDefinitionId is a gator shoe.
The itemDefinitionId to check.
True if the item is a convey, false otherwise.
Checks if an item with the specified itemDefinitionId is a generic item type.
The itemDefinitionId to check.
True if the item is a generic type, false otherwise.
Checks if an item with the specified itemDefinitionId is a helmet.
The itemDefinitionId to check.
True if the item is a helmet, false otherwise.
Checks if an item with the specified itemDefinitionId is stackable.
The itemDefinitionId to check.
True if the item is stackable, false otherwise.
Checks if an item with the specified itemDefinitionId is a weapon.
The itemDefinitionId to check.
True if the item is a weapon, false otherwise.
Checks if an item with the specified itemDefinitionId is a zed shoe.
The itemDefinitionId to check.
True if the item is a convey, false otherwise.
Returns the number of listeners listening for the event named eventName.
If listener is provided, it will return how many times the listener is found
in the list of the listeners of the event.
The name of the event being listened for
Optionallistener: (...args: any[]) => void
The event handler function
Returns a copy of the array of listeners for the event named eventName.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
Optionalitem: BaseItemAdds the listener function to the end of the listeners array for the
event named eventName. No checks are made to see if the listener has
already been added. Multiple calls passing the same combination of eventName
and listener will result in the listener being added, and called, multiple
times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The
emitter.prependListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
The name of the event.
The callback function
Adds a one-time listener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The
emitter.prependOnceListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
The name of the event.
The callback function
Adds the listener function to the beginning of the listeners array for the
event named eventName. No checks are made to see if the listener has
already been added. Multiple calls passing the same combination of eventName
and listener will result in the listener being added, and called, multiple
times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter, so that calls can be chained.
The name of the event.
The callback function
Adds a one-time listener function for the event named eventName to the
beginning of the listeners array. The next time eventName is triggered, this
listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter, so that calls can be chained.
The name of the event.
The callback function
Returns a copy of the array of listeners for the event named eventName,
including any wrappers (such as those created by .once()).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
OptionalinternalServerPort: numberReloads all packet handlers, structures, and commands for the entire server.
The client that called the function.
Removes an item from the account inventory.
The character to have their items removed.
The item to remove.
Optionalcount: number = 1
Optional: Specifies the amount of items that need to be removed, default is 1.
Returns true if the item was successfully removed, false if there was an error.
Removes all listeners, or those of the specified eventName.
It is bad practice to remove listeners added elsewhere in the code,
particularly when the EventEmitter instance was created by some other
component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter, so that calls can be chained.
OptionaleventName: string | symbolRemoves items from a specific item stack in a container.
The character to have their items removed.
Optionalitem: BaseItem
The item object.
Optionalcontainer: LoadoutContainer
The container that has the item stack in it.
Optionalcount: number
Optional: The number of items to remove from the stack, default 1.
Returns true if the items were successfully removed, false if there was an error.
Removes items from a specific item stack in the inventory, including containers and loadout.
The character to have their items removed.
The item object.
Optionalcount: number = 1
Optional: The number of items to remove from the stack, default 1.
OptionalupdateEquipment: boolean = true
Optional: Specifies whether to update the equipment, default is true.
Returns true if the items were successfully removed, false if there was an error.
Removes a specified amount of an item across all inventory containers / loadout (LOADOUT DISABLED FOR NOW).
The itemDefinitionId of the item(s) to be removed.
Optional: The number of items to remove, default 1.
Returns true if all items were successfully removed, false if there was an error.
Removes the specified listener from the listener array for the event named
eventName.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
removeListener() will remove, at most, one instance of a listener from the
listener array. If any single listener has been added multiple times to the
listener array for the specified eventName, then removeListener() must be
called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
time of emitting are called in order. This implies that any
removeListener() or removeAllListeners() calls after emitting and
before the last listener finishes execution will not remove them from
emit() in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
Because listeners are managed using an internal array, calling this will
change the position indexes of any listener registered after the listener
being removed. This will not impact the order in which listeners are called,
but it means that any copies of the listener array as returned by
the emitter.listeners() method will need to be recreated.
When a single function has been added as a handler multiple times for a single
event (as in the example below), removeListener() will remove the most
recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
Returns a reference to the EventEmitter, so that calls can be chained.
Removes an item from the loadout.
The character to have their items removed.
The loadout slot containing the item to remove.
OptionalupdateEquipment: boolean = true
Optional: Specifies whether to update the equipment, default is true.
Returns true if the item was successfully removed, false if there was an error.
OptionalrejectionFlag: CONNECTION_REJECTION_FLAGSOptionalclearChat: booleanOptionalammoCount: numberBy default EventEmitters will print a warning if more than 10 listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The emitter.setMaxListeners() method allows the limit to be
modified for this specific EventEmitter instance. The value can be set to
Infinity (or 0) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter, so that calls can be chained.
Deterministically sets the player's night-vision screen effect. enabled -> add "NIGHTVISION" (only while NV goggles are equipped in the EYES slot, matching /nv); !enabled -> always remove it (so it can never get stuck on). State is the presence of "NIGHTVISION" in character.screenEffects.
NV is a client TOGGLE ability, broken on the Dec-2016 build (its ability member is 0 -> the client never emits the packets). The dinput8 patch (h1emu-patch-2016) forces the member so the client emits Abilities.InitAbility 0xa101 on ACTIVATE and Abilities.UninitAbility 0xa103 on DEACTIVATE; the server maps InitAbility(1111272)->on and UninitAbility(1111272)->off, so P toggles NV correctly.
Spawns a single grid entity for a client if not already spawned and within range
Switches the loadout slot for a client.
The client to switch the loadout slot for.
The new loadout item.
Disconnects a client from the zone.
The client to be disconnected
Toggles night vision (the /nv effect): flips based on whether "NIGHTVISION" is currently active. Delegates to setNightVision. Used by the /nv command.
OptionalresourceType: numberValidates if an item can be equipped in the specified equipment slot.
The itemDefinitionId of the item to validate.
The equipment slot ID.
True if the item can be equipped in the slot, false otherwise.
Validates that a given itemDefinitionId can be equipped in a given loadout slot.
The definition ID of an item to validate.
The loadoutSlotId to have the item validated for.
The loadoutId of the entity to get the slot for.
Returns true/false if the item can go in a specified loadout slot.
Static_
Global dictionaries for all entities