Skip to content

Add npc:ask_item() complete with picker menu

Alex Gleason requested to merge npc_ask_item into master

Per #27 (closed), this addresses half the concern. Now a new function, npc:ask_item(callback) can be used to have an NPC spawn an item picker window, where the chosen item gets passed into the callback.

Example code:

local bunny = map:get_entity("bunny1")

function bunny:on_interaction()
  game:start_dialog("bunny.want_carrot", function()
    bunny:ask_item(function(item)
      if item and item:get_name() == "carrot"
        item:set_variant(0)
        game:start_dialog("bunny.thanks_for_carrot")
      elseif item then
        -- a non-carrot item is given
        game:start_dialog("bunny.no_thanks")
      end
    end)
  end)
end

Demo: voadi-npc-itempicker-demo

Merge request reports