Equip Slot Utilities
Version History
Build Version | Change Date | Change Type | Description |
---|---|---|---|
676042 | 2025-06-21 | stable | Current version |
Overview
The equipslotutil
module provides utilities for managing equipment slot identifiers and conversions between slot names and numerical IDs. This module is essential for networking equipment data and ensuring consistent slot handling across the game.
Usage Example
-- Initialize the equip slots (done once during world initialization)
local equipslotutil = require("equipslotutil")
equipslotutil.Initialize()
-- Convert slot name to ID for networking
local slot_id = equipslotutil.ToID("hands")
print("Hands slot ID:", slot_id)
-- Convert ID back to slot name
local slot_name = equipslotutil.FromID(slot_id)
print("Slot name:", slot_name)
-- Get total number of equipment slots
local total_slots = equipslotutil.Count()
print("Total equipment slots:", total_slots)
Functions
equipslotutil.Initialize()
Status: stable
Description:
Initializes the equipment slot system by processing the global EQUIPSLOTS
table and creating internal mappings. This function must be called once during world initialization, after MODs have finished loading and modifying the global equipment slots.
Parameters: None
Returns: None
Example:
-- Called once during world initialization
equipslotutil.Initialize()
Version History:
- Current implementation since build 676042
equipslotutil.ToID(eslot)
Status: stable
Description: Converts an equipment slot name to its corresponding numerical ID. This is primarily used for networking equipment data efficiently.
Parameters:
eslot
(string): The equipment slot name (e.g., "hands", "head", "body", "beard")
Returns:
- (number): The numerical ID corresponding to the slot name, or nil if the slot doesn't exist
Example:
local hands_id = equipslotutil.ToID("hands")
local head_id = equipslotutil.ToID("head")
-- Use IDs for networking or compact storage
Version History:
- Current implementation since build 676042
equipslotutil.FromID(eslotid)
Status: stable
Description:
Converts a numerical equipment slot ID back to its corresponding slot name. This is the inverse operation of ToID()
.
Parameters:
eslotid
(number): The numerical ID of the equipment slot
Returns:
- (string): The slot name corresponding to the ID, or nil if the ID is invalid
Example:
local slot_name = equipslotutil.FromID(1)
print("Slot 1 is:", slot_name) -- Might print "head" or another slot name
Version History:
- Current implementation since build 676042
equipslotutil.Count()
Status: stable
Description: Returns the total number of equipment slots available in the game. This count includes both vanilla and mod-added equipment slots.
Parameters: None
Returns:
- (number): The total number of equipment slots (maximum 63 slots supported)
Example:
local total_slots = equipslotutil.Count()
for i = 1, total_slots do
local slot_name = equipslotutil.FromID(i)
print("Slot", i, ":", slot_name)
end
Version History:
- Current implementation since build 676042
Implementation Details
Slot Ordering
The module uses a deterministic ordering for equipment slots based on orderedPairs()
iteration over the global EQUIPSLOTS
table. The order is then reversed to provide optimal priority ordering for deterministic checks.
Expected slot order: {"head", "hands", "body", "beard"}
Limitations
- Maximum slots: The system supports a maximum of 63 equipment slots
- Initialization required: All functions except
Initialize()
are only valid after initialization - Mod compatibility: Must be initialized after all mods have finished modifying
GLOBAL.EQUIPSLOTS
Networking Considerations
The numerical IDs generated by this module are designed for efficient networking and should remain consistent across all clients in a multiplayer game.
Related Modules
- Components: Equipment-related components use these slot utilities
- Inventory System: Inventory management relies on equipment slot identification
- Prefabs: Character and equipment prefabs utilize slot mappings