Questowner
Based on game build 714014 | Last updated: 2026-03-03
Overview
QuestOwner is a state-tracking component that enables an entity to participate in quest logic. It maintains boolean flags (questing and questcomplete), manages associated tags (via inst:AddTag/inst:RemoveTag), and provides hooks for custom behavior during quest start, abandon, and completion through optional callback functions. It also supports saving and loading quest state across sessions via OnSave and OnLoad.
Usage example
local inst = CreateEntity()
inst:AddComponent("questowner")
inst.components.questowner:SetOnBeginQuest(function(inst, doer)
print("Quest started for", inst.prefab)
return true, "Quest begun!"
end)
inst.components.questowner:SetOnAbandonQuest(function(inst, doer)
print("Quest abandoned by", doer and doer.prefab or "unknown")
return true
end)
inst.components.questowner:SetOnCompleteQuest(function(inst)
print("Quest completed for", inst.prefab)
end)
local success, msg = inst.components.questowner:BeginQuest(player)
if success then
inst.components.questowner:CompleteQuest()
end
Dependencies & tags
Components used: None identified
Tags: Adds questing and questcomplete based on state; removes both on component removal.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
on_begin_quest | function or nil | nil | Callback invoked when BeginQuest is called; should return (questing: boolean, message: string?). |
on_abandon_quest | function or nil | nil | Callback invoked when AbandonQuest is called; should return (quest_abandoned: boolean, message: string?). |
on_complete_quest | function or nil | nil | Callback invoked when CompleteQuest is called; takes (inst) as argument. |
questing | boolean | false | Whether the entity is currently on an active quest. |
questcomplete | boolean | false | Whether the quest has been successfully completed. |
Main functions
SetOnBeginQuest(callback)
- Description: Sets the callback to execute when a quest begins. This callback is invoked from
BeginQuest. - Parameters:
callback(function) - a function taking(inst, doer)and returning(questing: boolean, message: string?). - Returns: Nothing.
SetOnAbandonQuest(callback)
- Description: Sets the callback to execute when a quest is abandoned. This callback is invoked from
AbandonQuest. - Parameters:
callback(function) - a function taking(inst, doer)and returning(quest_abandoned: boolean, message: string?). - Returns: Nothing.
SetOnCompleteQuest(callback)
- Description: Sets the callback to execute when a quest is completed. This callback is invoked from
CompleteQuest. - Parameters:
callback(function) - a function taking(inst). - Returns: Nothing.
OnRemoveFromEntity()
- Description: Cleans up tags when the component is removed from an entity. Removes both
questingandquestcompletetags. - Parameters: None.
- Returns: Nothing.
CanBeginQuest(doer)
- Description: Checks whether the quest can be started by the specified doer. Uses
CanBeginFnif set (commented out in the current source); otherwise defaults totrue. - Parameters:
doer(entity) - the entity attempting to begin the quest. - Returns:
boolean-trueif allowed,falseotherwise. (Note:CanBeginFnis currently unused/commented out, so this always returnstrue.) - Error states: None identified.
BeginQuest(doer)
- Description: Attempts to begin the quest. Sets
questcompletetofalse, callson_begin_questif set, and updates internalquestingstate and tags accordingly. - Parameters:
doer(entity) - the entity triggering the quest start. - Returns:
(boolean, string?)—questingstate (trueif quest started), and optionally a message string. - Error states: If
on_begin_questreturns a falsyquestingvalue,self.questingremainsfalse.
CanAbandonQuest(doer)
- Description: Checks whether the quest can be abandoned. Uses
CanAbandonFnif set (commented out in the current source); otherwise defaults totrue. - Parameters:
doer(entity) - the entity attempting to abandon the quest. - Returns:
boolean—trueif allowed,falseotherwise. (Note:CanAbandonFnis currently unused, so this always returnstrue.) - Error states: None identified.
AbandonQuest(doer)
- Description: Attempts to abandon the current quest. Invokes the
on_abandon_questcallback if defined; otherwise setsquestingtofalsedirectly. - Parameters:
doer(entity) - the entity triggering the abandonment. - Returns:
(boolean?, string?)—quest_abandonedstatus and optional message. Returnsnilif no quest was active. - Error states: If
on_abandon_questis set and returnsquest_abandoned = false,self.questingis not changed.
CompleteQuest()
- Description: Marks the quest as completed. Sets
questingtofalse,questcompletetotrue, and invokeson_complete_questif defined. - Parameters: None.
- Returns: Nothing.
OnSave()
- Description: Serializes the component's quest state for saving to disk.
- Parameters: None.
- Returns:
{ questing: boolean, questcomplete: boolean }— a table containing current state values.
OnLoad(data)
- Description: Loads previously saved quest state from disk. Updates
questingandquestcompleteaccordingly and updates tags viaonquesting/onquestcomplete. - Parameters:
data(table ornil) — a previously returned table fromOnSave, ornilif no saved data exists. - Returns: Nothing.
Events & listeners
- Listens to: Internal setters
questingandquestcomplete(via metatable settersonquesting,onquestcomplete), which update tags automatically. - Pushes: No events are directly fired by this component.