1. Welcome to the official Starbound Mod repository, Guest! Not sure how to install your mods? Check out the installation guide or check out the modding help thread for more guides.
    Outdated Mods have been moved to their own category! If you update your mod please let a moderator know so we can move it back to the active section.
    Dismiss Notice

Quest Scope Hook 0.1

Run code inside the context of an invisible everlasting quest

  1. olsonpm
    This mod is meant to be used by other mods. It doesn't affect your game by
    itself. It's also fairly complex due to how the lua code works in starbound. If
    you feel this mod may help you but are having trouble understanding how it
    works, please file a github issue so I can help out.

    What is it?
    This mod enables dependent mods to write functions which will run during the
    init and update Lua Hooks of an everlasting invisible quest. Your function will
    thus have access to globals such as player which are available in quest contexts,
    which is the purpose of this mod.

    Why create it?
    I'm new to modding, but this seemed to be the easiest way for me to keep track
    of whether a player contained an item in their inventory. Because
    player_primary.lua doesn't have access to the player global, I use this mod in my
    Health Monitor to poll the inventory and send a message to the player if the
    health monitor is added or removed. It can then stop or start the low health
    effect accordingly.

    How to install it
    Like this

    How to use it
    This mod makes use of my Lua Hooks mod to expose hooks, so first you'll need
    to add an init script as explained on that repo.

    Assume the following
    - you have a mod named 'my-mod'
    - you patched the initscripts.json to add a script my-init-script.lua
    - you want to print "quest init ran!" when the invisible quest runs init()
    - and you want to print "quest update ran!" when the invisible quest runs update()

    You would achieve 3 & 4 by writing:

    -- /mods/my-mod/my-init-script.lua
    -- just some convenience variables
    local questScopeHooks = luaHooks.questScopeHook["/quests/scripts/questscopehook.lua"]
    local functionsToRun = {
      onQuestInit = questScopeHooks.onInit,
      onQuestUpdate = questScopeHooks.onUpdate
    -- now for the functions we want to call (assumptions 3 & 4)
    local willRunOnQuestInit = function()
      sb.logInfo("quest init ran!")
    -- this will spew a lot of lines in starbound.log!
    local willRunOnQuestUpdate = function()
      sb.logInfo("quest update ran!")
    -- and finally insert the functions into the hooks
    table.insert(functionsToRun.onQuestInit, willRunOnQuestInit)
    table.insert(functionsToRun.onQuestUpdate, willRunOnQuestUpdate)

    - I didn't know what dt value to put for the quest so I arbitrarily coded it to 30. If
    you feel this should be a different value then you should file an issue so I can
    understand why. I'm open to changing it.

    - Currently this only exposes the init() and update() methods of the quest. If you
    want more to be added just file an issue.
    Mod Pack Permissions:
    Anyone can use this mod in their mod compilation without the author's consent.
    Mod Assets Permissions:
    Anyone can alter/redistribute the mod's assets without the author's consent.