Modding Help Run a command when interacting with an object?

Discussion in 'Starbound Modding' started by Noah Nebula, Oct 2, 2018.

  1. Noah Nebula

    Noah Nebula Sandwich Man

    I want this command to run and you press E on an object.

    /startquest '"Nebulanintro"'

    I know this would have to be a .lua script, but how do I do it?
  2. Noah Nebula

    Noah Nebula Sandwich Man

  3. The Avelon

    The Avelon Phantasmal Quasar

    Hmm... I'm not certain. You should probably be able to just attach a script to it like

    function init()
    if not player.hasQuest(QuestID) then
    If that kicks an error to your log about accessing global 'player' then objects don't have access to the player table (but I think they do). In which case the workaround would be having the object open a scriptpane which does for sure have access to the player table. Try this first though.
  4. Noah Nebula

    Noah Nebula Sandwich Man


    [Error] Exception while calling script init: (LuaException) Error code 2, [string "/scripts/nebulanQuestStarter.lua"]:2: attempt to index a nil value (global 'player')
    stack traceback:
    [C]: in metamethod '__index'
    [string "/scripts/nebulanQuestStarter.lua"]:2: in function <[string "/scripts/nebulanQuestStarter.lua"]:1>
  5. The Avelon

    The Avelon Phantasmal Quasar

    Okay, then what you need to do is have it open a UI window and attach your script to that. I'm not near a computer right now so I can't look at an object for reference, but any crafting table or container will have the line of code to associate the object interaction to a UI. Pick any of the interface UIs and strip it down to have no buttons, widgets, search fields, etc. Use a fully transparent image for your UI background so the player doesn't see anything popping up - there is one in the interface folder, campfire_shine I think, or just make one if that ends up not being 100% transparent.

    In the config file for your UI attach the script above, and add a pane dismissal to the bottom between the two END statements. I don't remember the syntax but you can find it in the doc/Lua folder or I use it in the Take All Hotkey mod. world.paneDismiss or something.

    That should do the trick.
    Noah Nebula likes this.

Share This Page