Slingshotmods
Based on game build 714014 | Last updated: 2026-03-03
Overview
Slingshotmods is a server-authoritative component that manages a slingshot's attachable parts (band, frame, handle) via an internal container. It validates access (only the owner with the "walter_slingshot_modding" skill can open it), handles container creation, opening/closing, part transfer between slingshots, and persistence. It integrates with container, containerinstallableitem, equippable, inventoryitem, and skilltreeupdater components.
Usage example
local inst = CreateEntity()
inst:AddComponent("slingshotmods")
-- Optional: listen for custom events
inst:ListenForEvent("ms_slingshotmodsclosed", function(inst, data)
print("Slingshot UI closed by", data and data.doer or "system")
end)
Dependencies & tags
Components used: container, containerinstallableitem, equippable, inventoryitem, skilltreeupdater
Tags: Checks inventoryitem, equippable, skilltreeupdater; does not add or remove tags.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | (passed to constructor) | The entity instance this component is attached to. |
ismastersim | boolean | inferred from TheWorld.ismastersim | Whether this instance is server-authoritative. |
isloading | boolean? | nil | Set during loading to prevent premature validation. |
containerinst | Entity? | nil | The persistent container entity holding slingshot parts. |
opener | Entity? | nil | The entity that currently has the UI open. |
Main functions
CanBeOpenedBy(doer)
- Description: Checks if the given entity is permitted to open this slingshot's modding interface. Requires the "walter_slingshot_modding" skill and that
doeris the grand owner. - Parameters:
doer(Entity) - the entity attempting to open the UI. - Returns:
boolean—trueif allowed, otherwisefalse.
IsLoading()
- Description: Reports whether the component is currently loading saved data. Only valid on the master simulation.
- Parameters: None.
- Returns:
boolean—trueifisloadingis set, otherwisefalse. Returnsnilon clients.
HasPartName(name)
- Description: Checks if the internal container holds at least one item with the given prefab name (e.g.,
"slingshot_band","slingshot_frame"). - Parameters:
name(string) — the prefab name to search for. - Returns:
boolean?—trueif found,falseotherwise. Returnsnilif not on master or no container.
HasAnyParts()
- Description: Checks if the internal container holds any items.
- Parameters: None.
- Returns:
boolean?—trueif container exists and is not empty, otherwisefalseornil.
GetPartBuildAndSymbol(slot)
- Description: Retrieves the prefab, build, and symbol of the part in a specific slingshot slot.
- Parameters:
slot("band"|"frame"|"handle") — named slot identifier. - Returns:
string?, string?, string?— returnsprefab, swap_build, swap_symbolif part exists, otherwisenil.
CheckRequiredSkillsForPlayer(player)
- Description: Verifies that the player satisfies the skill requirements for all installed parts. Parts may declare a
REQUIRED_SKILLfield. - Parameters:
player(Entity) — the player entity to check. - Returns:
boolean—trueif all parts meet requirements (or no container/parts),falseif any part is missing required skill.
Open(opener)
- Description: Opens the slingshot modding UI for the specified entity. Creates the internal container if needed.
- Parameters:
opener(Entity) — the entity opening the UI. - Returns:
boolean—trueon success,falseif opening failed (e.g., not owner, container cannot open, not skill-qualified).
Close(opener)
- Description: Closes the modding UI. May be called with a specific opener to force-close for that entity only.
- Parameters:
opener(Entity?) — the opener to close; ifnil, closes for current opener only. - Returns:
boolean—trueif closed successfully,falseif UI wasn't open or opener mismatch.
OnUpdate(dt)
- Description: Callback used while the UI is open. Automatically closes the UI if the opener's state graph no longer has the
"moddingslingshot"tag (e.g., user cancelled or switched actions). - Parameters:
dt(number) — time since last update. - Returns: Nothing.
CreateContainer_Internal()
- Description: Instantiates and initializes the internal slingshot parts container prefab (
"slingshotmodscontainer"). Must only be called on master simulation. - Parameters: None.
- Returns: Nothing.
TransferPartsTo(other)
- Description: Moves all installed parts from this slingshot to another slingshot (same component type). Preserves part installations without uninstalling.
- Parameters:
other(SlingshotMods) — the target slingshot'sSlingshotmodscomponent. - Returns: Nothing.
DropAllPartsWithoutUninstalling()
- Description: Drops all parts from the container as items, skipping uninstall logic (useful for disassembly or debugging).
- Parameters: None.
- Returns: Nothing.
OnSave()
- Description: Serializes container contents for world save.
- Parameters: None.
- Returns:
table?, table?— returns{ parts = data }, refsif container has parts; otherwisenil.
OnLoad(data, newents)
- Description: Restores container contents from saved data.
- Parameters:
data(table) — saved data containing"parts"key;newents(table) — new entity map for restore. - Returns: Nothing.
Events & listeners
- Listens to:
ondropped— triggers automatic UI close via internaldoclosehandler.
- Pushes:
ms_slingshotmodsclosed— fired on the opener when the UI is fully closed on master simulation.