Simutil
Based on game build 722832 | Last updated: 2026-04-17
Overview
simutil.lua defines a collection of standalone utility functions used throughout the game codebase. It handles spatial queries (finding entities, players, safe spawn points), vision checks (lighting, storm, darkness), entity erosion effects, and asset atlas lookups for inventory, minimap, and UI icons. It also manages global map icon registration. This file does not define a class; its functions are called directly or accessed globally. It relies heavily on TheWorld, TheSim, and AllPlayers globals.
Usage example
-- Functions are typically available globally after loading
local x, y, z = FindSafeSpawnLocation(0, 0, 0)
local closest = FindClosestPlayerToInst(inst, 10, true)
RegisterGlobalMapIcon(inst, "my_icon")
-- Check vision conditions
if CanEntitySeeInDark(player) then
print("Player can see in dark")
end
-- Find pickupable items
local item = FindPickupableItem(player, 5, false, nil, nil, nil, false)
Dependencies & tags
External dependencies:
dbui_no_package/debug_skins_data/hooks-- Loaded conditionally ifCAN_USE_DBUIis true for skin debugging.
Components used:
inventory-- Checks capacity and item acceptance in pickup logic.burnable-- Checks burning/smoldering state to exclude items.floater-- Triggers erosion effect on entities.playervision-- Checks night/goggle vision capabilities.stormwatcher-- Checks storm levels for vision obstruction.miasmawatcher-- Checks miasma presence for vision obstruction.playerspawner-- Retrieves safe spawn points.nightlightmanager-- Finds night lights for Charlie spawn logic.walkableplatform-- Checks platform status for camera shake.inventoryitem,trap,bait,container,bundlemaker,armor,weapon,tool,equippable,sewing,erasablepaper,pickable-- Various checks for item pickup logic and filtering.
Tags:
pickable,_inventoryitem-- Used for filtering pickupable items.lunacyarea-- Excluded from Charlie spawn spots.canseeindark,nightvision,goggles-- Vision capability checks.INLIMBO,NOCLICK,fire,structure,donotautopick,minesprung,mineactive,catchable,cursed,paired,bundle,heatrock,deploykititem,boatbuilder,singingshell,archive_lockbox,simplebook,furnituredecor,flower,gemsocket,irreplaceable,knockbackdelayinteraction,event_trigger,spider,light-- Exclusion tags for pickup logic.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
| None | No properties are defined. |
Main functions
CalledFrom()
- Description: Returns a formatted string indicating the source file and line number of the caller, used for deprecation warnings.
- Parameters: None
- Returns: String describing the call site (e.g.,
@mod/main.lua:10 in function). - Error states: None.
GetWorld()
- Description: Deprecated wrapper for
TheWorld. Prints a warning before returning the global world instance. - Parameters: None
- Returns:
TheWorldentity instance. - Error states: None.
GetPlayer()
- Description: Deprecated wrapper for
ThePlayer. Prints a warning before returning the local player instance. - Parameters: None
- Returns:
ThePlayerentity instance. - Error states: None.
FindEntity(inst, radius, fn, musttags, canttags, mustoneoftags)
- Description: Finds the first entity within
radiusofinstthat matches tag filters and optional functionfn. Excludesinstitself and invisible entities. - Parameters:
inst-- Reference entity for positionradius-- Search radiusfn-- Optional filter functionfn(entity, inst)musttags-- Table of tags entity must havecanttags-- Table of tags entity must not havemustoneoftags-- Table of tags entity must have at least one of
- Returns: Entity instance or
nilif none found. - Error states: None (guards against nil/invalid
inst).
FindClosestEntity(inst, radius, ignoreheight, musttags, canttags, mustoneoftags, fn)
- Description: Finds the closest entity to
instwithinradiusmatching tag filters. Optionally ignores height difference. - Parameters:
inst-- Reference entity for positionradius-- Search radiusignoreheight-- Boolean to ignore Y-axis distancemusttags,canttags,mustoneoftags-- Tag filter tablesfn-- Optional filter functionfn(entity, inst)
- Returns:
entity, distance_sqornil, nil. - Error states: None.
FindClosestPlayerInRangeSq(x, y, z, rangesq, isalive)
- Description: Finds the closest player to coordinates within squared range. Optionally filters by alive status.
- Parameters:
x, y, z-- World coordinatesrangesq-- Squared search radiusisalive-- Boolean to filter for alive/dead players (nil for any)
- Returns:
player, distance_sqornil, nil. - Error states: None.
FindClosestPlayerInRange(x, y, z, range, isalive)
- Description: Wrapper for
FindClosestPlayerInRangeSqaccepting linear range. - Parameters:
x, y, z-- World coordinatesrange-- Search radiusisalive-- Boolean to filter for alive/dead players
- Returns:
player, distance_sqornil, nil. - Error states: None.
FindClosestPlayer(x, y, z, isalive)
- Description: Finds the closest player to coordinates regardless of distance.
- Parameters:
x, y, z-- World coordinatesisalive-- Boolean to filter for alive/dead players
- Returns:
player, distance_sqornil, nil. - Error states: None.
FindClosestPlayerToInst(inst, range, isalive)
- Description: Finds the closest player to an entity instance within range.
- Parameters:
inst-- Reference entityrange-- Search radiusisalive-- Boolean to filter for alive/dead players
- Returns:
player, distance_sqornil, nil. - Error states: Errors if
instis nil or invalid (accessesinst.Transform).
FindClosestPlayerOnLandInRangeSq(x, y, z, rangesq, isalive)
- Description: Finds closest player within range who is currently on valid ground.
- Parameters:
x, y, z-- World coordinatesrangesq-- Squared search radiusisalive-- Boolean to filter for alive/dead players
- Returns:
player, distance_sqornil, nil. - Error states: None.
FindClosestPlayerToInstOnLand(inst, range, isalive)
- Description: Finds the closest player on valid ground to an entity instance within range.
- Parameters:
inst-- Reference entityrange-- Search radiusisalive-- Boolean to filter for alive/dead players
- Returns:
player, distance_sqornil, nil. - Error states: Errors if
instis nil or invalid (accessesinst.Transform).
FindPlayersInRangeSqSortedByDistance(x, y, z, rangesq, isalive)
- Description: Returns a table of players within squared range, sorted by distance (closest first).
- Parameters:
x, y, z-- World coordinatesrangesq-- Squared search radiusisalive-- Boolean to filter for alive/dead players
- Returns: Table of player instances.
- Error states: None.
FindPlayersInRangeSortedByDistance(x, y, z, range, isalive)
- Description: Wrapper for
FindPlayersInRangeSqSortedByDistanceaccepting linear range. - Parameters:
x, y, z-- World coordinatesrange-- Search radiusisalive-- Boolean to filter for alive/dead players
- Returns: Table of player instances.
- Error states: None.
FindPlayersInRangeSq(x, y, z, rangesq, isalive)
- Description: Returns a table of players within squared range (unsorted).
- Parameters:
x, y, z-- World coordinatesrangesq-- Squared search radiusisalive-- Boolean to filter for alive/dead players
- Returns: Table of player instances.
- Error states: None.
FindPlayersInRange(x, y, z, range, isalive)
- Description: Wrapper for
FindPlayersInRangeSqaccepting linear range. - Parameters:
x, y, z-- World coordinatesrange-- Search radiusisalive-- Boolean to filter for alive/dead players
- Returns: Table of player instances.
- Error states: None.
IsAnyPlayerInRangeSq(x, y, z, rangesq, isalive)
- Description: Checks if any player exists within squared range.
- Parameters:
x, y, z-- World coordinatesrangesq-- Squared search radiusisalive-- Boolean to filter for alive/dead players
- Returns: Boolean.
- Error states: None.
IsAnyPlayerInRange(x, y, z, range, isalive)
- Description: Wrapper for
IsAnyPlayerInRangeSqaccepting linear range. - Parameters:
x, y, z-- World coordinatesrange-- Search radiusisalive-- Boolean to filter for alive/dead players
- Returns: Boolean.
- Error states: None.
IsAnyOtherPlayerNearInst(inst, rangesq, isalive)
- Description: Checks if any player other than
instis within squared range. - Parameters:
inst-- Reference entity (usually a player)rangesq-- Squared search radiusisalive-- Boolean to filter for alive/dead players
- Returns: Boolean.
- Error states: Errors if
instis nil or invalid.
FindSafeSpawnLocation(x, y, z)
- Description: Finds a safe location to spawn an item, preferring near players or world spawn points to avoid ocean loss.
- Parameters:
x, y, z-- Preferred coordinates (optional)
- Returns:
x, y, zcoordinates. - Error states: None.
FindNearbyLand(position, range)
- Description: Finds a valid land position near
positionusing a fan search. - Parameters:
position-- Vector3 start positionrange-- Search radius (default8)
- Returns: Vector3 offset or
nil. - Error states: None.
FindNearbyOcean(position, range)
- Description: Finds a valid ocean position near
positionusing a fan search. - Parameters:
position-- Vector3 start positionrange-- Search radius (default8)
- Returns: Vector3 offset or
nil. - Error states: None.
GetRandomInstWithTag(tag, inst, radius)
- Description: Returns a random entity with
tagwithinradiusofinst. - Parameters:
tag-- String or table of tagsinst-- Reference entityradius-- Search radius
- Returns: Entity instance or
nil. - Error states: Errors if
instis nil or invalid.
GetClosestInstWithTag(tag, inst, radius)
- Description: Returns the closest entity with
tagwithinradiusofinst. - Parameters:
tag-- String or table of tagsinst-- Reference entityradius-- Search radius
- Returns: Entity instance or
nil. - Error states: Errors if
instis nil or invalid.
DeleteCloseEntsWithTag(tag, inst, radius)
- Description: Removes all entities with
tagwithinradiusofinst. - Parameters:
tag-- String or table of tagsinst-- Reference entityradius-- Search radius
- Returns: None.
- Error states: Errors if
instis nil or invalid.
AnimateUIScale(item, total_time, start_scale, end_scale)
- Description: Animates the scale of a UI widget over time using a coroutine.
- Parameters:
item-- UI widget withUITransformtotal_time-- Duration in secondsstart_scale-- Starting scale valueend_scale-- Ending scale value
- Returns: None.
- Error states: Errors if
itemlacksUITransformorStartThread.
ShakeAllCameras(mode, duration, speed, scale, source_or_pt, maxDist)
- Description: Triggers camera shake on all connected players.
- Parameters:
mode-- Shake modeduration-- Shake durationspeed-- Shake speedscale-- Shake intensitysource_or_pt-- Source entity or positionmaxDist-- Max distance for effect
- Returns: None.
- Error states: None.
ShakeAllCamerasWithFilter(filterfn, mode, duration, speed, scale, source_or_pt, maxDist)
- Description: Triggers camera shake on players matching
filterfn. - Parameters:
filterfn-- Functionfn(player)returning booleanmode, duration, speed, scale, source_or_pt, maxDist-- Shake parameters
- Returns: None.
- Error states: None.
ShakeAllCamerasOnPlatform(mode, duration, speed, scale, platform)
- Description: Triggers camera shake on players standing on a specific walkable platform.
- Parameters:
mode, duration, speed, scale-- Shake parametersplatform-- Platform entity
- Returns: None.
- Error states: None.
FindValidPositionByFan(start_angle, radius, attempts, test_fn)
- Description: Searches for a valid position by fanning out angles from a start point.
- Parameters:
start_angle-- Starting angle in radiansradius-- Search distanceattempts-- Number of angle attempts (default8)test_fn-- Functionfn(offset)returning boolean
- Returns:
offset, check_angle, deflectedornil. - Error states: None.
FindWalkableOffset(position, start_angle, radius, attempts, check_los, ignore_walls, customcheckfn, allow_water, allow_boats)
- Description: Finds a walkable offset from
position, checking ground, teleportation, and line of sight. - Parameters:
position-- Vector3 start positionstart_angle-- Starting angle in radiansradius-- Search distanceattempts-- Number of attemptscheck_los-- Boolean to check line of sightignore_walls-- Boolean to ignore walls in pathfindingcustomcheckfn-- Optional extra validation functionallow_water-- Boolean to allow ocean tilesallow_boats-- Boolean to allow boat platforms
- Returns:
offset, check_angle, deflectedornil. - Error states: None.
FindSwimmableOffset(position, start_angle, radius, attempts, check_los, ignore_walls, customcheckfn, allow_boats)
- Description: Finds a swimmable ocean offset from
position. - Parameters:
position-- Vector3 start positionstart_angle-- Starting angle in radiansradius-- Search distanceattempts-- Number of attemptscheck_los-- Boolean to check line of sightignore_walls-- Boolean to ignore wallscustomcheckfn-- Optional extra validation functionallow_boats-- Boolean to allow boat platforms
- Returns:
offset, check_angle, deflectedornil. - Error states: None.
FindCharlieRezSpotFor(inst)
- Description: Finds a safe resurrection spot for Charlie (darkness monster), preferring near night lights.
- Parameters:
inst-- Reference entity
- Returns:
x, y, zcoordinates. - Error states: Errors if
instis nil and bothnightlightmanagerandplayerspawnercomponents are unavailable (accessesinst.Transformwithout nil guard in fallback).
FindPickupableItem(owner, radius, furthestfirst, positionoverride, ignorethese, onlytheseprefabs, allowpickables, worker, extra_filter, inventoryoverride)
- Description: Searches for an item on the ground that the
ownercan pick up into their inventory. - Parameters:
owner-- Player or entity with inventoryradius-- Search radiusfurthestfirst-- Boolean to search furthest items firstpositionoverride-- Vector3 to search from instead of owner posignorethese-- Table of entities to ignoreonlytheseprefabs-- Table of allowed prefabs/productsallowpickables-- Boolean to include pickable bushes/flowersworker-- Worker entity for ignore logicextra_filter-- Optional functionfn(worker, v, owner)inventoryoverride-- Optional inventory component to check
- Returns:
entity, ispickableornil, nil. - Error states: None (guards against missing inventory).
CanEntitySeeInDark(inst)
- Description: Checks if
insthas the ability to see in darkness (night vision or goggles). - Parameters:
inst-- Entity to check
- Returns: Boolean.
- Error states: None.
CanEntitySeeInStorm(inst)
- Description: Checks if
insthas the ability to see during storms (goggles). - Parameters:
inst-- Entity to check
- Returns: Boolean.
- Error states: None.
CanEntitySeePoint(inst, x, y, z)
- Description: Checks if
instcan see a specific point based on light, storms, and ink status. - Parameters:
inst-- Observer entityx, y, z-- Target coordinates
- Returns: Boolean.
- Error states: None.
CanEntitySeeTarget(inst, target)
- Description: Checks if
instcan see a target entity. - Parameters:
inst-- Observer entitytarget-- Target entity
- Returns: Boolean.
- Error states: None.
SpringCombatMod(amount, forced)
- Description: Applies Spring season combat damage multiplier.
- Parameters:
amount-- Base damage valueforced-- Boolean to force application regardless of season
- Returns: Modified damage value.
- Error states: None.
SpringGrowthMod(amount, forced)
- Description: Applies Spring season growth rate multiplier.
- Parameters:
amount-- Base duration/valueforced-- Boolean to force application regardless of season
- Returns: Modified value.
- Error states: None.
TemporarilyRemovePhysics(obj, time)
- Description: Disables collision mask for
objtemporarily, restoring it aftertime. - Parameters:
obj-- Entity with Physics componenttime-- Duration in seconds
- Returns: None.
- Error states: Errors if
objlacksPhysicscomponent.
ErodeAway(inst, erode_time)
- Description: Visually erodes
instover time and then removes it from the world. - Parameters:
inst-- Entity to erodeerode_time-- Duration in seconds (default1)
- Returns: None.
- Error states: Errors if
instlacksAnimStatecomponent.
ErodeCB(inst, erode_time, cb, restore)
- Description: Visually erodes
instover time, calls callbackcb, and optionally restores animation. - Parameters:
inst-- Entity to erodeerode_time-- Duration in secondscb-- Callback functionfn(inst)restore-- Boolean to reset erosion params after finish
- Returns: None.
- Error states: Errors if
instlacksAnimStatecomponent.
ApplySpecialEvent(event)
- Description: Sets the global world special event, resetting tech levels if not active.
- Parameters:
event-- Event string identifier
- Returns: None.
- Error states: None.
ApplyExtraEvent(event)
- Description: Adds an extra world event to the active list.
- Parameters:
event-- Event string identifier
- Returns: None.
- Error states: None.
RegisterInventoryItemAtlas(atlas, imagename)
- Description: Registers an atlas path for a specific inventory image name.
- Parameters:
atlas-- Atlas path stringimagename-- Image name string
- Returns: None.
- Error states: None.
GetInventoryItemAtlas(imagename, no_fallback)
- Description: Retrieves the atlas path for an inventory image, checking caches and default XMLs.
- Parameters:
imagename-- Image name stringno_fallback-- Boolean to skip fallback atlas check
- Returns: Atlas path string or
nil. - Error states: None.
GetMinimapAtlas(imagename)
- Description: Retrieves the atlas path for a minimap image.
- Parameters:
imagename-- Image name string
- Returns: Atlas path string or
nil. - Error states: None.
RegisterScrapbookIconAtlas(atlas, imagename)
- Description: Registers an atlas path for a scrapbook icon.
- Parameters:
atlas-- Atlas path stringimagename-- Image name string
- Returns: None.
- Error states: None.
GetScrapbookIconAtlas(imagename)
- Description: Retrieves the atlas path for a scrapbook icon.
- Parameters:
imagename-- Image name string
- Returns: Atlas path string or
nil. - Error states: None.
RegisterSkilltreeBGAtlas(atlas, imagename)
- Description: Registers an atlas path for a skill tree background.
- Parameters:
atlas-- Atlas path stringimagename-- Image name string
- Returns: None.
- Error states: None.
GetSkilltreeBG(imagename)
- Description: Retrieves the atlas path for a skill tree background.
- Parameters:
imagename-- Image name string
- Returns: Atlas path string or
nil. - Error states: None.
RegisterSkilltreeIconsAtlas(atlas, imagename)
- Description: Registers an atlas path for a skill tree icon.
- Parameters:
atlas-- Atlas path stringimagename-- Image name string
- Returns: None.
- Error states: None.
GetSkilltreeIconAtlas(imagename)
- Description: Retrieves the atlas path for a skill tree icon.
- Parameters:
imagename-- Image name string
- Returns: Atlas path string or
nil. - Error states: None.
UnregisterGlobalMapIcon(inst)
- Description: Removes
instfrom the global map icon registry. - Parameters:
inst-- Entity instance
- Returns: None.
- Error states: Prints warning if
instwas not registered.
RegisterGlobalMapIcon(inst, name)
- Description: Adds
instto the global map icon registry for fast lookup. - Parameters:
inst-- Entity instancename-- Optional name override (defaults to prefab)
- Returns: None.
- Error states: Prints warning if
instis already registered.
FindClosestMapIconInRangeSq(name, x, y, z, rangesq, restricted_doer)
- Description: Finds the closest registered map icon of
namewithin squared range. - Parameters:
name-- Icon name/prefabx, y, z-- Search coordinatesrangesq-- Squared search radiusrestricted_doer-- Optional player to check restrictions against
- Returns: Entity instance or
nil. - Error states: None.
FindClosestMapIconInRange(name, x, y, z, range, restricted_doer)
- Description: Wrapper for
FindClosestMapIconInRangeSqaccepting linear range. - Parameters:
name-- Icon name/prefabx, y, z-- Search coordinatesrange-- Search radiusrestricted_doer-- Optional player to check restrictions against
- Returns: Entity instance or
nil. - Error states: None.
FindClosestMapIcon(name, x, y, z, restricted_doer)
- Description: Finds the closest registered map icon of
nameregardless of distance. - Parameters:
name-- Icon name/prefabx, y, z-- Search coordinatesrestricted_doer-- Optional player to check restrictions against
- Returns: Entity instance or
nil. - Error states: None.
DeclareLimitedCraftingRecipe(recipename)
- Description: Registers a recipe as limited for crafting station serialization.
- Parameters:
recipename-- String recipe identifier
- Returns: None.
- Error states: Errors if recipe is already declared.
Events & listeners
Listens to:
onremove--RegisterGlobalMapIconattaches a listener toinstto automatically unregister the icon when the entity is removed.
Pushes:
- None identified.