Player Common
Based on game build 722832 | Last updated: 2026-04-21
Overview
player_common.lua defines the Player Prefab factory function MakePlayerCharacter for creating player character entities in Don't Starve Together. The file contains a local fns table with helper functions that are attached to player instances during construction, along with configuration constants such as DEFAULT_PLAYER_COLOUR, DANGER_ONEOF_TAGS, and DANGER_NOPIG_ONEOF_TAGS, plus an external module reference BEEFALO_COSTUMES from yotb_costumes. This module is used by character-specific prefab files (e.g., wilson.lua) to create complete player entities with all standard components, lifecycle management, HUD interface controls, character swapping, ghost mode handling, and event listeners for environmental hazards, combat actions, audio cues, and visual effects. Character-specific variations are applied through postinit extensions that build upon this shared base.
Usage example
-- This file is used by character prefab files to create player entities
-- Example from wilson.lua:
return MakePlayerCharacter("wilson", customprefabs, customassets, common_postinit, master_postinit)
-- The functions defined in this file are attached to player instances:
local player = ThePlayer
-- Check if player is near danger (hounded waves)
local is_dangerous = player:IsNearDanger(true)
-- Enable/disable boat camera for player
player:EnableBoatCamera(true)
-- Enable loading protection during transitions
player:EnableLoadingProtection()
-- Call component functions on a player entity
player.components.health:SetMaxHealth(150)
player.components.sanity:SetMax(200)
Dependencies & tags
External dependencies:
easing-- used for camera shake falloff calculationsscreens/playerhud-- PlayerHud screen class for HUD activationprefabs/player_common_extensions-- ex_fns table with extended player functionsprefabs/skilltree_defs-- skill tree definitionsutil/sourcemodifierlist-- SourceModifierList for camera distance bonusesyotb_costumes-- BEEFALO_COSTUMES table for Year of the Beefalo event
Components used:
health-- manages health, invincibility, and penalty trackingsanity-- manages sanity state and lunacy enablinginventory-- manages item storage, equipping, and droppinglocomotor-- manages movement, strafing, and predictioncombat-- manages attack behavior and damageburnable-- manages burning and smoldering statestemperature-- manages temperature statemoisture-- manages wetness statetalker-- manages speech and talker offsetfrostybreather-- manages frosty breath visual offsetplayer_classified-- networked classified component for player statedebuffable-- manages debuff application and removalseamlessplayerswapper-- manages character transformation swappingattuner-- manages attunement to resurrectorsleader-- manages follower relationshipspetleash-- manages pet spawning and despawningmaprevealable-- manages minimap icon and revealgrogginess-- manages grogginess speed modifierssandstormwatcher-- manages sandstorm speed modifiersmoonstormwatcher-- manages moonstorm speed modifiersmiasmawatcher-- manages miasma speed modifierscarefulwalker-- manages careful walking speed modifierschannelcaster-- manages channel casting stateskinner-- manages character skin modesrider-- manages mounting and dismountingage-- manages player age trackingbuilder-- manages recipe learning and buildingtrader-- manages item acceptance and tradingplayervision-- manages night vision and colour cubesareaaware-- manages area tile watchingplayerspeedmult-- manages speed multipliersembarker-- manages embarkation speedboatcannonuser-- manages boat cannon classified referencehudindicatable-- manages HUD indicator tracking functionspawnfader-- manages spawn fade effectsrevivablecorpse-- manages corpse revival (game mode dependent)touchstonetracker-- manages touchstone usage trackingdrownable-- manages drowning statesheltered-- manages shelter statestormwatcher-- manages storm watchingacidlevel-- manages acid levelbloomer-- manages bloom effectscolouradder-- manages colour effectsbirdattractor-- manages bird attractionwisecracker-- manages wisecrack dialoguedistancetracker-- manages distance trackingcatcher-- manages catching behaviorplayerlightningtarget-- manages lightning targetingeater-- manages eating behavior (game mode dependent)foodaffinity-- manages food affinitygrue-- manages grue soundspinnable-- manages pinnable stateworkmultiplier-- manages work speed multipliersslipperyfeet-- manages slippery feet behaviorsleepingbaguser-- manages sleeping bag usagecolourtweener-- manages colour tweeningcursable-- manages curse applicationstageactor-- manages stage actingexperiencecollector-- manages experience collectionjoustuser-- manages jousting behaviorluckuser-- manages luck-based eventsaura-- manages aura effectsplayeravatardata-- manages avatar dataconstructionbuilderuidata-- manages construction builder UI datainkable-- manages ink effectscookbookupdater-- manages cookbook updatesplantregistryupdater-- manages plant registry updatesskilltreeupdater-- manages skill tree updateswalkableplatformplayer-- manages walkable platform behaviorspellbookcooldowns-- manages spellbook cooldownsavengingghost-- manages avenging ghost behaviorghostlyelixirable-- manages ghostly elixir behaviorhealthsyncer-- manages health sync (Lava Arena mode)playerinspectable-- manages player inspection popupdamagetyperesist-- manages damage type resistancedamagetypebonus-- manages damage type bonusesplanardamage-- manages planar damageplanardefense-- manages planar defensewintertreegiftable-- manages winter tree gifting (Winter's Feast event)spooked-- manages spooked state (Hallowed Nights event)spectatorcorpse-- manages spectator corpse (game mode dependent)hudindicatorwatcher-- manages HUD indicator watchingplayerhearing-- manages player hearingraindomewatcher-- manages rain dome watchingstrafer-- manages strafing behaviorvaultmusiclistener-- manages vault music listening (caves)playercontroller-- manages player controllerplayeractionpicker-- manages player action pickingplayervoter-- manages player votingplayermetrics-- manages player metrics
Tags:
player-- added on entity creationscarytoprey-- added on entity creationcharacter-- added on entity creationlightningtarget-- added on entity creationwaterplant_upgradeuser-- added on entity creationmast_upgradeuser-- added on entity creationchest_upgradeuser-- added on entity creationusesvegetarianequipment-- added on entity creationghostlyelixirable-- added on entity creationtrader-- added in pristine statedebuffable-- added in pristine statestageactor-- added in pristine state_health-- added/removed for replication optimization_hunger-- added/removed for replication optimization_sanity-- added/removed for replication optimization_builder-- added/removed for replication optimization_combat-- added/removed for replication optimization_moisture-- added/removed for replication optimization_sheltered-- added/removed for replication optimization_rider-- added/removed for replication optimizationnotarget-- added during loading protectionspawnprotection-- added during loading protectionplayer_<userid>-- added when user ID is assignedglobalmapicon_player-- set via maprevealable componentnoplayerindicator-- checked for HUD trackinghiding-- checked for HUD trackingmonster-- checked for danger detectionpig-- checked for danger detectioncompanion-- checked for danger detectionshadowcreature-- checked for danger detectionprey-- checked for battle cry stringshostile-- checked for battle cry stringswerepig-- checked for battle cry stringsplayerghost-- checked for ghost mode and statusreviver-- checked for revival itemsnoreviverhealthpenalty-- checked for revival penaltystronggrip-- checked for wet tool droppingstickygrip-- checked for wet tool droppingfrozen-- checked for fire melt eventsstructure-- checked for fire startingwildfireprotected-- checked for fire startingteeteringplatform-- checked for teetering statelunacyarea-- checked for lunacy enablingumbrella-- checked for umbrella replacementcave-- checked for vault music listenermultiplayer_portal-- checked for teleport on loadflying-- checked for pet spawn effectsirreplaceable-- checked for despawn droppingNOCLICK-- added during spawn fadingspiderwhisperer-- checked for spider dangerspiderdisguise-- checked for spider dangerspider-- checked for spider dangerghost-- checked for aura damagenoauradamage-- checked for aura damageflying-- checked for pet spawn effectsbedroll-- checked for sleeping statetent-- checked for sleeping state
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
USE_MOVEMENT_PREDICTION | boolean | true | Flag enabling movement prediction on clients |
DEFAULT_PLAYER_COLOUR | table | {1, 1, 1, 1} | Default RGBA colour table for players |
DANGER_ONEOF_TAGS | table | {"monster", "pig", "_combat"} | Tags used for danger detection |
DANGER_NOPIG_ONEOF_TAGS | table | {"monster", "_combat"} | Tags for danger detection excluding pigs |
TALLER_TALKER_OFFSET | Vector3 | Vector3(0, -700, 0) | Offset for taller character talkers (riding/ghost) |
DEFAULT_TALKER_OFFSET | Vector3 | Vector3(0, -400, 0) | Offset for default talkers |
TALLER_FROSTYBREATHER_OFFSET | Vector3 | Vector3(.3, 3.75, 0) | Offset for taller frosty breather (riding) |
DEFAULT_FROSTYBREATHER_OFFSET | Vector3 | Vector3(.3, 1.15, 0) | Offset for default frosty breather |
BEEFALO_COSTUMES | table | — | Table of Year of the Beefalo costume data from yotb_costumes |
max_range | number | TUNING.MAX_INDICATOR_RANGE * 1.5 | Maximum range for player indicator tracking |
BLACKOUT_COLOURCUBES | table | — | Colour cube paths for blackout vision effect |
inst.playercolour | table | DEFAULT_PLAYER_COLOUR | Player colour used if not set properly |
inst.ghostenabled | boolean | GetGhostEnabled() | Whether ghost mode is enabled for this player |
inst.userid | string | "" | User ID assigned on ownership |
inst.name | string | — | Player name from Network |
inst.isplayer | boolean | true | Flag marking entity as a player |
inst.jointask | task | — | Task for OnPlayerJoined callback |
inst.activatetask | task | — | Task for ActivatePlayer callback |
inst._scalesource | table | nil | Table tracking transform scale modifiers by source |
inst._animscalesource | table | nil | Table tracking animation scale modifiers by source |
inst.cameradistancebonuses | SourceModifierList | — | SourceModifierList for camera distance bonuses |
inst._isrezattuned | boolean | — | Whether player is attuned to resurrector |
inst._sleepinghandsitem | entity | nil | Temporarily unequipped hand item during sleep |
inst._sleepingactiveitem | entity | nil | Temporarily hidden active item during sleep |
inst.last_death_position | Vector3 | nil | Position where player last died |
inst.last_death_shardid | string | nil | Shard ID where player last died |
inst.hasRevivedPlayer | boolean | — | Whether player has revived another player |
inst.hasKilledPlayer | boolean | — | Whether player has killed another player |
inst.hasAttackedPlayer | boolean | — | Whether player has attacked another player |
inst.hasStartedFire | boolean | — | Whether player has started a fire |
inst.migration | table | nil | Migration data for shard transfers |
inst.migrationpets | table | nil | Pets to migrate with player |
inst.wormlight | entity | nil | Wormlight spell entity |
inst.HUD | screen | — | Player HUD screen instance |
inst.player_classified | entity | — | Classified component entity for networked state |
inst.ondetachclassified | function | — | Callback for classified detachment |
inst._serverpauseddirtyfn | function | — | Callback for server pause state changes |
inst._sharksoundparam | net_float | — | Networked shark sound parameter |
inst._winters_feast_music | net_event | — | Networked Winter's Feast music event |
inst._hermit_music | net_event | — | Networked Hermit music event |
inst._underleafcanopy | net_bool | — | Networked canopy zone state |
inst._lunarportalmax | net_event | — | Networked lunar portal max event |
inst._shadowportalmax | net_event | — | Networked shadow portal max event |
inst._skilltreeactivatedany | net_event | — | Networked skill tree activation event |
inst._wormdigestionsound | net_bool | — | Networked worm digestion sound state |
inst._parasiteoverlay | net_bool | — | Networked parasite overlay state |
inst._blackout | net_bool | — | Networked blackout vision state |
inst._buffsymbol | net_hash | — | Networked health bar buff symbol |
inst._piratemusicstate | net_bool | — | Networked pirate music state |
inst.yotb_skins_sets | net_shortint | — | Networked YOTB skin set unlocks |
inst.skeleton_prefab | string | "skeleton_player" | Prefab name for player skeleton |
inst.footstepoverridefn | function | ex_fns.FootstepOverrideFn | Footstep sound override function |
inst.foleyoverridefn | function | ex_fns.FoleyOverrideFn | Foley sound override function |
inst.foleysound | string | nil | Character-specific foley sound |
inst.overrideskinmode | string | "normal_skin" | Override skin mode for character states |
inst.overrideskinmodebuild | string | — | Override skin mode build |
inst.deathclientobj | table | nil | Death client object for networked death |
inst.deathcause | string | nil | Cause of player death |
inst.deathpkname | string | nil | Name of killer if killed by player |
inst.deathbypet | boolean | nil | Whether death was caused by pet |
inst.isseamlessswapsource | boolean | nil | Flag for seamless swap source player |
inst.isseamlessswaptarget | boolean | nil | Flag for seamless swap target player |
inst.delayclientdespawn | boolean | nil | Flag to delay client despawn during swap |
inst.delayclientdespawn_attempted | boolean | nil | Flag marking despawn attempt on host |
inst.loadingprotection | boolean | nil | Flag for loading protection state |
inst._PICKUPSOUNDS | table | PICKUPSOUNDS | Deprecated pickup sounds table for mods |
inst.PostActivateHandshake | function | ex_fns.PostActivateHandshake | Post-activation handshake function |
inst.OnPostActivateHandshake_Client | function | ex_fns.OnPostActivateHandshake_Client | Client post-activation callback |
inst.OnPostActivateHandshake_Server | function | ex_fns.OnPostActivateHandshake_Server | Server post-activation callback |
inst._PostActivateHandshakeState_Client | number | POSTACTIVATEHANDSHAKE.NONE | Client handshake state |
inst._PostActivateHandshakeState_Server | number | POSTACTIVATEHANDSHAKE.NONE | Server handshake state |
inst.SetClientAuthoritativeSetting | function | ex_fns.SetClientAuthoritativeSetting | Sets client authoritative setting |
inst.SynchronizeOneClientAuthoritativeSetting | function | ex_fns.SynchronizeOneClientAuthoritativeSetting | Synchronizes single client setting |
inst.ApplySkinOverrides | function | ApplySkinOverrides | Applies skin mode overrides |
inst.SaveForReroll | function | SaveForReroll | Saves data for character reroll |
inst.LoadForReroll | function | LoadForReroll | Loads data for character reroll |
inst.OnSleepIn | function | OnSleepIn | Callback when sleeping in bedroll/tent |
inst.OnWakeUp | function | OnWakeUp | Callback when waking up |
inst._OnSave | function | OnSave | Internal save callback (assigned from original OnSave) |
inst._OnPreLoad | function | OnPreLoad | Internal pre-load callback (assigned from original OnPreLoad) |
inst._OnLoad | function | OnLoad | Internal load callback (assigned from original OnLoad) |
inst._OnNewSpawn | function | OnNewSpawn | Internal new spawn callback (assigned from original OnNewSpawn) |
inst._OnDespawn | function | OnDespawn | Internal despawn callback (assigned from original OnDespawn) |
inst.OnSave | function | OnSave | Overridden save function |
inst.OnPreLoad | function | OnPreLoad | Overridden pre-load function |
inst.OnLoad | function | OnLoad | Overridden load function |
inst.OnNewSpawn | function | OnNewSpawn | Overridden new spawn function |
inst.OnDespawn | function | OnDespawn | Overridden despawn function |
inst.ChangeToMonkey | function | ChangeToMonkey | Transform to monkey character |
inst.ChangeFromMonkey | function | ChangeBackFromMonkey | Transform back from monkey character |
inst.IsActing | function | ex_fns.IsActing | Check if player is acting on stage |
inst.EnableLoadingProtection | function | fns.EnableLoadingProtection | Enable loading protection |
inst.DisableLoadingProtection | function | fns.DisableLoadingProtection | Disable loading protection |
inst.AttachClassified | function | AttachClassified | Attach classified component |
inst.DetachClassified | function | DetachClassified | Detach classified component |
inst.OnRemoveEntity | function | OnRemoveEntity | Entity removal callback |
inst.CanExamine | function | nil | Can be overridden for examination |
inst.ActionStringOverride | function | nil | Can be overridden for action strings |
inst.CanUseTouchStone | function | CanUseTouchStone | Check touchstone usability |
inst.GetTemperature | function | GetTemperature | Get current temperature |
inst.IsFreezing | function | IsFreezing | Check if freezing |
inst.IsOverheating | function | IsOverheating | Check if overheating |
inst.GetMoisture | function | GetMoisture | Get current moisture |
inst.GetMaxMoisture | function | GetMaxMoisture | Get max moisture |
inst.GetMoistureRateScale | function | GetMoistureRateScale | Get moisture rate scale |
inst.GetStormLevel | function | GetStormLevel | Get storm level |
inst.IsInMiasma | function | fns.IsInMiasma | Check if in miasma |
inst.IsInAnyStormOrCloud | function | fns.IsInAnyStormOrCloud | Check if in storm or cloud |
inst.IsCarefulWalking | function | IsCarefulWalking | Check if careful walking |
inst.IsChannelCasting | function | fns.IsChannelCasting | Check if channel casting |
inst.IsChannelCastingItem | function | fns.IsChannelCastingItem | Check if channel casting item |
inst.IsTeetering | function | fns.IsTeetering | Check if teetering |
inst.EnableMovementPrediction | function | EnableMovementPrediction | Enable/disable movement prediction |
inst.EnableBoatCamera | function | fns.EnableBoatCamera | Enable/disable boat camera |
inst.EnableTargetLocking | function | ex_fns.EnableTargetLocking | Enable target locking |
inst.ShakeCamera | function | fns.ShakeCamera | Shake camera effect |
inst.SetGhostMode | function | SetGhostMode | Set ghost mode state |
inst.IsActionsVisible | function | IsActionsVisible | Check if actions visible |
inst.CanSeeTileOnMiniMap | function | ex_fns.CanSeeTileOnMiniMap | Check tile visibility on minimap |
inst.CanSeePointOnMiniMap | function | ex_fns.CanSeePointOnMiniMap | Check point visibility on minimap |
inst.GetSeeableTilePercent | function | ex_fns.GetSeeableTilePercent | Get seeable tile percentage |
inst.MakeGenericCommander | function | ex_fns.MakeGenericCommander | Make generic commander |
inst.CommandWheelAllowsGameplay | function | ex_fns.CommandWheelAllowsGameplay | Check command wheel gameplay |
inst.IsHUDVisible | function | fns.IsHUDVisible | Check if HUD visible |
inst.ShowActions | function | fns.ShowActions | Show/hide actions |
inst.ShowCrafting | function | fns.ShowCrafting | Show/hide crafting UI |
inst.ShowHUD | function | fns.ShowHUD | Show/hide HUD |
inst.ShowPopUp | function | fns.ShowPopUp | Show/hide popup |
inst.ResetMinimapOffset | function | fns.ResetMinimapOffset | Reset minimap offset |
inst.CloseMinimap | function | fns.CloseMinimap | Close minimap |
inst.SetCameraDistance | function | fns.SetCameraDistance | Set camera distance |
inst.AddCameraExtraDistance | function | fns.AddCameraExtraDistance | Add camera distance bonus |
inst.RemoveCameraExtraDistance | function | fns.RemoveCameraExtraDistance | Remove camera distance bonus |
inst.SetCameraZoomed | function | fns.SetCameraZoomed | Set camera zoomed state |
inst.SetAerialCamera | function | fns.SetAerialCamera | Set aerial camera mode |
inst.SnapCamera | function | fns.SnapCamera | Snap camera to default |
inst.ScreenFade | function | fns.ScreenFade | Screen fade effect |
inst.ScreenFlash | function | fns.ScreenFlash | Screen flash effect |
inst.SetBathingPoolCamera | function | fns.SetBathingPoolCamera | Set bathing pool camera target |
inst.YOTB_unlockskinset | function | fns.YOTB_unlockskinset | Unlock YOTB skin set |
inst.YOTB_issetunlocked | function | fns.YOTB_issetunlocked | Check YOTB skin set unlocked |
inst.YOTB_isskinunlocked | function | fns.YOTB_isskinunlocked | Check YOTB skin unlocked |
inst.IsNearDanger | function | fns.IsNearDanger | Check if near danger |
inst.SetGymStartState | function | fns.SetGymStartState | Set gym start state |
inst.SetGymStopState | function | fns.SetGymStopState | Set gym stop state |
inst.SwapAllCharacteristics | function | fns.SwapAllCharacteristics | Swap characteristics to new instance |
inst.ApplyScale | function | fns.ApplyScale | Apply transform scale |
inst.ApplyAnimScale | function | fns.ApplyAnimScale | Apply animation scale |
inst.TargetForceAttackOnly | function | fns.TargetForceAttackOnly | Check if target requires force attack |
inst.additional_OnFollowerRemoved | function | nil | Additional follower removed callback |
inst.additional_OnFollowerAdded | function | nil | Additional follower added callback |
inst.CustomSetSkinMode | function | nil | Custom skin mode setter (Wurt) |
inst.starting_inventory | table | nil | Starting inventory items |
Main functions
IsNearDanger(inst, hounded_ok)
- Description: Checks if the player is near dangerous entities or conditions including hounds, burning/smoldering state, hostile monsters, pigs, and shadow creatures when sane. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instance to check for nearby dangerhounded_ok-- Boolean indicating whether hound attacks should be ignored in danger calculation
- Returns: boolean -- true if danger is detected, false otherwise
TargetForceAttackOnly(inst, target)
- Description: Determines if mouseover Attack command should be hidden unless Force Attacking, specifically for shadow creatures that are not hostile to the player. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instancetarget-- Target entity to test for force attack requirement
- Returns: boolean -- true if target should only be attackable via force attack
SetGymStartState(inst)
- Description: Configures player entity for gym mode by setting no-faced transform, hiding inventory, closing popups, and showing actions. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instance entering gym state
- Returns: None
SetGymStopState(inst)
- Description: Restores player entity from gym mode by setting four-faced transform, showing inventory, and showing actions. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instance leaving gym state
- Returns: None
YOTB_unlockskinset(inst, skinset)
- Description: Unlocks a YOTB (Year of the Beefalo) skin set for the player if the event is active, sets the skin bit, announces the pattern, and pushes learn blueprint event. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instanceskinset-- Skin set identifier to unlock
- Returns: None
YOTB_issetunlocked(inst, skinset)
- Description: Checks if a specific YOTB skin set is unlocked for the player during the event. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instanceskinset-- Skin set identifier to check
- Returns: boolean or nil -- true if the skin set bit matches, nil if YOTB event is not active
YOTB_isskinunlocked(inst, skin)
- Description: Checks if a specific YOTB skin is unlocked by iterating through costume sets and checking set unlock status. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instanceskin-- Specific skin identifier to check
- Returns: boolean or nil -- true if skin is found in an unlocked set, nil if YOTB event is not active
YOTB_getrandomset(inst)
- Description: Assigns a random YOTB skin set to the player if no sets are currently unlocked. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instance
- Returns: None
IsInMiasma(inst)
- Description: Checks if the player is currently in a miasma cloud. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instance
- Returns: boolean or nil -- true if condition is met, nil if player_classified is not available
IsInAnyStormOrCloud(inst)
- Description: Checks if the player is in any storm (sandstorm at full level) or miasma cloud. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instance
- Returns: boolean or nil -- true if condition is met, nil if player_classified is not available
IsChannelCasting(inst)
- Description: Checks if the player is currently channel casting. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instance
- Returns: boolean or nil -- true if condition is met, nil if player_classified is not available
IsChannelCastingItem(inst)
- Description: Checks if the player is currently channel casting an item. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instance
- Returns: boolean or nil -- true if condition is met, nil if player_classified is not available
OnStartChannelCastingItem(inst, item)
- Description: Internal callback applied when starting channel casting, adjusting grogginess, sandstorm, moonstorm, miasma, and careful walking multipliers, then starts strafing. Returns early if item has channelcastable component with strafing enabled. Registered as channelcaster component callback.
- Parameters:
inst-- Player entity instanceitem-- Item being channel cast
- Returns: None
- Error states: None
OnStopChannelCastingItem(inst)
- Description: Internal callback to restore default speed modifiers when stopping channel casting and stops strafing. Registered as channelcaster component callback.
- Parameters:
inst-- Player entity instance
- Returns: None
IsTeetering(inst)
- Description: Checks if the player is standing on a teetering platform. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instance
- Returns: boolean -- true if current platform has teeteringplatform tag
OnChangeArea(inst, area)
- Description: Enables or disables lunacy based on whether the area has lunacyarea tag. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instancearea-- Area entity with tags
- Returns: None
OnAlterNight(inst)
- Description: Enables lunacy during alter night when both night and alterawake world states are active. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instance
- Returns: None
OnStormLevelChanged(inst, data)
- Description: Enables lunacy when moonstorm is active with level greater than 0. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instancedata-- Storm level change data with stormtype and level
- Returns: None
OnRiftMoonTile(inst, on_rift_moon)
- Description: Enables lunacy when player is on rift moon tile. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instanceon_rift_moon-- Boolean indicating if on rift moon tile
- Returns: None
OnFullMoonEnlightenment(inst, isfullmoon)
- Description: Enables lunacy during full moon if lunar rifts are enabled via riftspawner component. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instanceisfullmoon-- Boolean indicating if it is full moon
- Returns: None
OnItemRanOut(inst, data)
- Description: Internal callback to auto-equip a replacement tool if the equipped item ran out and a matching item exists in inventory. Registered as itemranout event listener.
- Parameters:
inst-- Player entity instancedata-- Item expiry data with equipslot and prefab
- Returns: None
OnUmbrellaRanOut(inst, data)
- Description: Internal callback to auto-equip a replacement umbrella if the equipped umbrella ran out and another umbrella exists in inventory. Registered as umbrellaranout event listener.
- Parameters:
inst-- Player entity instancedata-- Umbrella expiry data with equipslot
- Returns: None
ArmorBroke(inst, data)
- Description: Internal callback to auto-equip a replacement armor if the equipped armor broke and a matching armor exists in inventory, respecting keeponfinished flag. Registered as armorbroke event listener.
- Parameters:
inst-- Player entity instancedata-- Armor break data with armor reference
- Returns: None
EnableBoatCamera(inst, enable)
- Description: Pushes enableboatcamera event with enable state. Available on player entity instances created by this prefab.
- Parameters:
inst-- Entity instanceenable-- Boolean to enable or disable boat camera
- Returns: None
CommonSeamlessPlayerSwap(inst)
- Description: Clears name and userid, removes player components if present, and pushes seamlessplayerswap event. Available on player entity instances created by this prefab.
- Parameters:
inst-- Entity instance being swapped
- Returns: None
CommonSeamlessPlayerSwapTarget(inst)
- Description: Pushes seamlessplayerswaptarget event. Available on player entity instances created by this prefab.
- Parameters:
inst-- Entity instance that is swap target
- Returns: None
LocalSeamlessPlayerSwap(inst)
- Description: Calls CommonSeamlessPlayerSwap, sets isseamlessswapsource flag, and enables delayclientdespawn flags. Available on player entity instances created by this prefab.
- Parameters:
inst-- Local entity instance being swapped
- Returns: None
LocalSeamlessPlayerSwapTarget(inst)
- Description: Calls CommonSeamlessPlayerSwapTarget and sets isseamlessswaptarget flag. Available on player entity instances created by this prefab.
- Parameters:
inst-- Local entity instance that is swap target
- Returns: None
MasterSeamlessPlayerSwap(inst)
- Description: Calls CommonSeamlessPlayerSwap and schedules entity removal after network tick changes to ensure client receives new spawn first. Available on player entity instances created by this prefab.
- Parameters:
inst-- Master simulation entity instance being swapped
- Returns: None
MasterSeamlessPlayerSwapTarget(inst)
- Description: Calls CommonSeamlessPlayerSwapTarget. Available on player entity instances created by this prefab.
- Parameters:
inst-- Master simulation entity instance that is swap target
- Returns: None
EnableLoadingProtection(inst)
- Description: Sets loadingprotection flag, adds notarget and spawnprotection tags, sets health invincible, and disables physics. Available on player entity instances created by this prefab.
- Parameters:
inst-- Entity instance to protect
- Returns: None
DisableLoadingProtection(inst)
- Description: Clears loadingprotection flag, enables physics immediately, and schedules removal of notarget/spawnprotection tags and invincibility after 1.5 seconds. Available on player entity instances created by this prefab.
- Parameters:
inst-- Entity instance to remove protection from
- Returns: None
IsHUDVisible(inst)
- Description: Returns whether the HUD is visible via player_classified netvar. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instance
- Returns: boolean -- value of ishudvisible netvar
- Error states: Errors if inst.player_classified is nil (direct member access on nil with no guard)
ShowActions(inst, show)
- Description: Shows or hides action buttons. Only executes on master sim. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instanceshow-- boolean -- whether to show actions
- Returns: None
ShowCrafting(inst, show)
- Description: Shows or hides crafting UI. Only executes on master sim. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instanceshow-- boolean -- whether to show crafting UI
- Returns: None
ShowHUD(inst, show)
- Description: Shows or hides the player HUD. Only executes on master sim. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instanceshow-- boolean -- whether to show HUD
- Returns: None
ShowPopUp(inst, popup, show, ...)
- Description: Shows a popup dialog to the client via RPC. Only executes on master sim when userid exists. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instancepopup-- Popup table with code and mod_name fieldsshow-- boolean -- whether to show popup...-- Additional arguments passed to RPC
- Returns: None
ResetMinimapOffset(inst)
- Description: Forces minimap center netvar to be dirty. Should only be used when necessary. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instance
- Returns: None
CloseMinimap(inst)
- Description: Forces minimap close netvar to be dirty. Should only be used when necessary. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instance
- Returns: None
SetCameraDistance(inst, distance)
- Description: Sets the camera distance via netvar. Only executes on master sim. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instancedistance-- number -- camera distance value, defaults to 0 if nil
- Returns: None
AddCameraExtraDistance(inst, source, distance, key)
- Description: Adds a camera distance bonus modifier. Updates cameraextramaxdist netvar. Only executes on master sim when cameradistancebonuses exists. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instancesource-- string -- source identifier for the modifierdistance-- number -- distance value to addkey-- string -- key for the modifier
- Returns: None
RemoveCameraExtraDistance(inst, source, key)
- Description: Removes a camera distance bonus modifier. Updates cameraextramaxdist netvar. Only executes on master sim when cameradistancebonuses exists. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instancesource-- string -- source identifier for the modifierkey-- string -- key for the modifier
- Returns: None
SetCameraZoomed(inst, iszoomed)
- Description: Sets the camera zoomed state via netvar. Only executes on master sim. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instanceiszoomed-- boolean -- whether camera is zoomed
- Returns: None
SetAerialCamera(inst, isaerial)
- Description: Sets the aerial camera mode via netvar. Only executes on master sim. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instanceisaerial-- boolean -- whether camera is in aerial mode
- Returns: None
SnapCamera(inst, resetrot)
- Description: Snaps the camera by forcing camerasnap netvar to be dirty. Only executes on master sim. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instanceresetrot-- boolean -- whether to reset rotation
- Returns: None
ShakeCamera(inst, mode, duration, speed, scale, source_or_pt, maxDist)
- Description: Shakes the camera with normalized values for network transmission. Applies distance-based falloff if source_or_pt and maxDist provided. Only executes shake on master sim, applies to TheCamera on client. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instancemode-- number -- shake mode identifierduration-- number -- shake duration in secondsspeed-- number -- shake speedscale-- number -- shake scale/intensitysource_or_pt-- entity or Vector3 -- source entity or position for distance calculationmaxDist-- number -- maximum distance for falloff calculation
- Returns: None
ScreenFade(inst, isfadein, time, iswhite)
- Description: Triggers screen fade effect via netvars. Time is normalized for net_smallbyte with iswhite flag encoded. Only executes on master sim. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instanceisfadein-- boolean -- whether this is a fade intime-- number -- fade duration, truncated to max 31iswhite-- boolean -- whether fade is white (adds 32 to time value)
- Returns: None
ScreenFlash(inst, intensity)
- Description: Triggers screen flash effect via netvar. Normalizes intensity for net_tinybyte. Pushes screenflash event if HUD exists. Only executes on master sim. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instanceintensity-- number -- flash intensity, normalized to 0-7 range
- Returns: None
SetBathingPoolCamera(inst, target)
- Description: Sets the bathing pool camera target. Only executes on master sim. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instancetarget-- entity -- target entity for bathing pool camera
- Returns: None
ApplyScale(inst, source, scale)
- Description: Applies or removes transform scale from a source. Maintains _scalesource table for multiple sources and calculates cumulative scale. Only executes on master sim. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instancesource-- string -- source identifier for the scale modifierscale-- number -- scale multiplier, 1 means no change
- Returns: None
ApplyAnimScale(inst, source, scale)
- Description: Applies or removes animation state scale from a source. Maintains _animscalesource table for multiple sources and calculates cumulative scale. Only executes on master sim. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instancesource-- string -- source identifier for the anim scale modifierscale-- number -- scale multiplier, 1 means no change
- Returns: None
OnDebuffAdded(inst, name, debuff)
- Description: Internal callback called when a debuff is added. Sets buff symbol if debuff name is elixir_buff. Registered as debuffable component ondebuffadded handler.
- Parameters:
inst-- Player entity instancename-- string -- debuff namedebuff-- table -- debuff data with prefab field
- Returns: None
OnDebuffRemoved(inst, name, debuff)
- Description: Internal callback called when a debuff is removed. Clears buff symbol if debuff name is elixir_buff. Registered as debuffable component ondebuffremoved handler.
- Parameters:
inst-- Player entity instancename-- string -- debuff namedebuff-- table -- debuff data
- Returns: None
SetSymbol(inst, symbol)
- Description: Sets the buff symbol netvar if value changed. Only executes on master sim. Available on player entity instances created by this prefab.
- Parameters:
inst-- Player entity instancesymbol-- string or number -- symbol identifier
- Returns: None
SetInstanceFunctions(inst)
- Description: Attaches various helper functions to the player instance for movement, camera, visibility, and state checks. Broken out separately due to Lua upvalue limits.
- Parameters:
inst-- Entity - The player instance to attach functions to
- Returns: None
ShouldTrackfn(inst, viewer)
- Description: Determines if a player should be tracked by HUD indicators based on validity, tags, distance, frustum check, and line of sight.
- Parameters:
inst-- Entity - The entity being trackedviewer-- Entity - The viewer entity checking visibility
- Returns: boolean - true if should track, false otherwise
OnChangeCanopyZone(inst, underleaves)
- Description: Callback that updates the networked _underleafcanopy variable when canopy zone changes.
- Parameters:
inst-- Entity - The player instanceunderleaves-- boolean - Whether player is under leaf canopy
- Returns: None
OnResetBeard(inst, ismonkey)
- Description: Resets beard component bits based on monkey transformation state (0 for monkey, 3 for normal).
- Parameters:
inst-- Entity - The player instanceismonkey-- boolean - Whether player is in monkey form
- Returns: None
SwapAllCharacteristics(inst, newinst)
- Description: Transfers all components with TransferComponent method to new instance, copies death data if dead, and teleports new instance to source position. Used for monkey transformation.
- Parameters:
inst-- Entity - The source player instancenewinst-- Entity - The target player instance to transfer to
- Returns: None
- Error states: Errors if inst.components.health is nil when checking IsDead()
ChangeToMonkey(inst)
- Description: Triggers monkey transformation via seamlessplayerswapper component if available.
- Parameters:
inst-- Entity - The player instance to transform
- Returns: None
ChangeBackFromMonkey(inst)
- Description: Triggers transformation back to main character via seamlessplayerswapper component if available.
- Parameters:
inst-- Entity - The monkey instance to transform back
- Returns: None
OnPirateMusicStateDirty(inst)
- Description: Pushes playpiratesmusic event to ThePlayer when pirate music state changes.
- Parameters:
inst-- Entity - The player instance
- Returns: None
onfinishseamlessplayerswap(inst, data)
- Description: Plays transformation music when seamless player swap completes (wonkey transform or detransform).
- Parameters:
inst-- Entity - The player instancedata-- table - Event data containing oldprefab field
- Returns: None
OnFollowerRemoved(inst, follower)
- Description: Calls additional_OnFollowerRemoved if defined on the instance.
- Parameters:
inst-- Entity - The leader player instancefollower-- Entity - The follower being removed
- Returns: None
OnFollowerAdded(inst, follower)
- Description: Calls additional_OnFollowerAdded if defined on the instance.
- Parameters:
inst-- Entity - The leader player instancefollower-- Entity - The follower being added
- Returns: None
fn()
- Description: Inner prefab creation function that builds the complete player entity with all components, assets, events, and network variables. Called when prefab is spawned.
- Parameters: None
- Returns: Entity - The created player instance
MakePlayerCharacter(name, customprefabs, customassets, common_postinit, master_postinit, starting_inventory)
- Description: Factory function that creates the player character prefab with all standard components and configuration. Returns a Prefab object for registration.
- Parameters:
name-- string -- Character prefab namecustomprefabs-- table -- Optional custom prefab dependenciescustomassets-- table -- Optional custom assetscommon_postinit-- function -- Optional common postinit callbackmaster_postinit-- function -- Optional master postinit callbackstarting_inventory-- table -- Deprecated starting inventory (set via master_postinit)
- Returns: Prefab - The player character prefab object
Events & listeners
Listens to:
gotnewitem— Triggered when player receives a new item, plays pickup soundequip— Triggered when player equips an item, plays equip sounditemranout— Triggered when item runs outumbrellaranout— Triggered when umbrella runs outarmorbroke— Triggered when armor breakspicksomething— Audio event for picking up itemsdropitem— Audio event for dropping itemsactionfailed— Speech event for failed actionswonteatfood— Speech event for refusing foodworking— Speech event for working with toolsonstartedfire— Temperamental event for starting fireonattackother— PVP event for attacking othersonareaattackother— PVP event for area attackskilled— PVP event for killinglearncookbookrecipe— Cookbook event for learning recipeslearncookbookstats— Cookbook event for learning statsoneat— Cookbook event for eatinglearnplantstage— Plant registry event for learning plant stageslearnfertilizer— Plant registry event for learning fertilizerstakeoversizedpicture— Plant registry event for oversized crop pictureschangearea— Enlightenment event for area changesstormlevel— Enlightenment event for storm level changeson_RIFT_MOON_tile— Enlightenment event for rift moon tileson_LUNAR_MARSH_tile— Enlightenment event for lunar marsh tilesmurdered— Merm murder event for fish repel checkonstage— Stageplay event for being on stagestartstageacting— Stageplay event for starting actingstopstageacting— Stageplay event for stopping actingms_closepopups— Generic popup close eventgotnewattunement— Attunement event for gaining new attunementattunementlost— Attunement event for losing attunementcancelmovementprediction— Movement prediction cancellation eventserverpauseddirty— Server pause state change eventonremove— Entity removal event for classified detachmentsetowner— Triggers OnSetOwner callback when owner is setlocal_seamlessplayerswap— Triggers LocalSeamlessPlayerSwap for client-side swaplocal_seamlessplayerswaptarget— Triggers LocalSeamlessPlayerSwapTarget for client-side swap targetmaster_seamlessplayerswap— Triggers MasterSeamlessPlayerSwap for server-side swapmaster_seamlessplayerswaptarget— Triggers MasterSeamlessPlayerSwapTarget for server-side swap targetlocalplayer._winters_feast_music— Triggers OnWintersFeastMusic on non-dedicated clientslocalplayer._lunarportalmax— Triggers OnLunarPortalMax on non-dedicated clientslocalplayer._shadowportalmax— Triggers OnShadowPortalMax on non-dedicated clientslocalplayer._hermit_music— Triggers OnHermitMusic on non-dedicated clientssharksounddirty— Triggers OnSharkSound when shark sound parameter changeswormdigestionsounddirty— Triggers OnWormDigestionSound when worm digestion sound changesfinishseamlessplayerswap— Triggers onfinishseamlessplayerswap when swap completespiratemusicstatedirty— Triggers OnPirateMusicStateDirty when pirate music state changesparasiteoverlaydirty— Triggers OnParasiteOverlayDirty when parasite overlay changeshealthbarbuffsymboldirty— Triggers OnHealthbarBuffSymbolDirty when buff symbol changesblackoutdirty— Triggers OnBlackoutDirty when blackout state changesdeath— Triggers OnPlayerDeath callbackmakeplayerghost— Triggers OnMakePlayerGhost if ghost enabledrespawnfromghost— Triggers OnRespawnFromGhost if ghost enabledghostdissipated— Triggers OnPlayerDied if ghost enabledrespawnfromcorpse— Triggers OnRespawnFromPlayerCorpse if revivablecorpse component existsplayerdied— Triggers OnMakePlayerCorpse or OnPlayerDied depending on ghost settingsspooked— Triggers OnSpooked during Hallowed Nights eventstartfiredamage— Triggers OnStartFireDamage when fire damage beginsstopfiredamage— Triggers OnStopFireDamage when fire damage endsburnt— Triggers OnBurntHands when hands are burntonchangecanopyzone— Triggers OnChangeCanopyZone when canopy zone changes
Pushes:
on_enter_might_gym— Pushed when entering gym statems_closepopups— Pushed to close popups when entering gym stateyotb_learnblueprint— Pushed when YOTB skin set is unlockedrespawnfromghost— Pushed when player respawns from ghost via reviver itemfiremelt— Pushed on frozen items when fire damage startsstopfiremelt— Pushed on frozen items when fire damage stopsplayerdeactivated— Pushed when player is deactivatedplayeractivated— Pushed when player is activatedfinishseamlessplayerswap— Pushed when seamless player swap completesplayerentered— Pushed when player enters worldms_playerjoined— Master sim event for player joiningenablemovementprediction— Pushed to enable/disable movement predictioncancelmovementprediction— Pushed to cancel movement prediction when entering ghost stateenableboatcamera— Pushed to enable/disable boat cameraseamlessplayerswap— Pushed for seamless player swap initiationseamlessplayerswaptarget— Pushed for seamless player swap targetplayerexited— Pushed when player exits worldms_playerleft— Master sim event for player leavingplayer_despawn— Pushed in OnDespawn when player is despawningms_newplayerspawned— Pushed in OnNewSpawn when player spawns, passes inst as datascreenflash— Pushed in fns.ScreenFlash when intensity >= 0 and HUD existsisfeasting— Pushed in OnWintersFeastMusic if inst is ThePlayerstartflareoverlay— Pushed in OnLunarPortalMax and OnShadowPortalMax with optional color tableplayhermitmusic— Pushed in OnHermitMusic if inst is ThePlayerplaypiratesmusic— Pushed in OnPirateMusicStateDirty if inst is ThePlayerparasitethralllevel— Pushed in OnParasiteOverlayDirty with _parasiteoverlay valueclienthealthbuffdirty— Pushed in OnHealthbarBuffSymbolDirty with _buffsymbol valuenewskillpointupdated— Pushed when player initialization completesms_playerspawn— Pushed to TheWorld when player spawnsinvincibletoggle— Pushed when health invincibility togglessanitydelta— Pushed when sanity changesgosane— Pushed when player becomes sanegoinsane— Pushed when player becomes insanegoenlightened— Pushed when player becomes enlighteneddismounted— Pushed when player dismountsstopconstruction— Pushed when construction stopsondropped— Pushed when inventory item is droppedonownerdropped— Pushed on container items when owner dropsstartstrafing— Pushed when strafing startsstopstrafing— Pushed when strafing stopsusereviver— Pushed when reviver item is usedstopfiremelt— Pushed on frozen items when fire damage stops