Itemweigher
Based on game build 714014 | Last updated: 2026-03-03
Overview
ItemWeigher is a lightweight component that manages a type property and dynamically updates entity tags (trophyscale_<type>) when that type changes. It also provides a callback mechanism (ondoweighinfn) for executing custom logic during a weighing-in operation. This component is typically attached to trophy scale entities to support dynamic visual/type updates and integrate with gameplay actions like weighing in a trophy.
Usage example
local inst = CreateEntity()
inst:AddComponent("itemweigher")
inst.components.itemweigher:SetOnDoWeighInFn(function(inst, target, doer)
print("Weighing in:", target:GetDescription(), "by", doer:GetName())
return true
end)
inst.components.itemweigher.type = "giraffe"
inst.components.itemweigher:DoWeighIn(some_target, player)
Dependencies & tags
Components used: None identified
Tags: Adds and removes tags in the form trophyscale_<type> (e.g., trophyscale_giraffe).
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
type | string or nil | nil | The current trophy scale type. Changing this property triggers tag updates via the ontype handler. |
ondoweighinfn | function or nil | nil | Callback function invoked by DoWeighIn. Takes (inst, target, doer) and returns a value (typically boolean or nil). |
Main functions
SetOnDoWeighInFn(fn)
- Description: Assigns the callback function used during a weighing-in operation. This function is called by
DoWeighIn. - Parameters:
fn(function) - A function accepting three arguments:inst(this component's entity),target(the item being weighed in), anddoer(the entity performing the weigh-in). Should return a value (often used to indicate success/failure). - Returns: Nothing.
DoWeighIn(target, doer)
- Description: Executes the stored weighing-in callback if it exists.
- Parameters:
target(Entity) - The item/entity being weighed in.doer(Entity) - The entity performing the weigh-in (e.g., a player).
- Returns: The return value of
ondoweighinfn, ornilif no callback is set. - Error states: Returns
nilifondoweighinfnisnil.
Events & listeners
- Listens to: None identified
- Pushes: None identified
Tag management side effect
- When
typeis assigned, theontypehandler automatically:- Removes the old tag
trophyscale_<old_type>(ifold_typeis notnil). - Adds the new tag
trophyscale_<type>(iftypeis notnil).
This occurs only during property assignment and is not exposed as an event listener or pusher.
- Removes the old tag