Need help with updating Picker

Place to get help with not working mods / modding interface.
Post Reply
Liquid5n0w
Inserter
Inserter
Posts: 40
Joined: Thu Feb 05, 2015 4:10 pm
Contact:

Need help with updating Picker

Post by Liquid5n0w »

Picker was one of my favorite mods in .13, and I've decided I want to make a go of updating to for 0.13.

viewtopic.php?f=93&t=14695&p=183809#p183809

I've done some of the basics like the info.json and removing defines and changing game to script. But it seems like it cannot insert an item into the hand to inventory. I suspect the only thing that needs to be changed is updating it for the new API, but I know nothing about Factorio modding, can someone point me in the right direction?

control.lua

Code: Select all

script.on_event(defines.events.on_tick, function(event)
  p = game.players[1]
  if p.cursor_stack.valid_for_read then
    if p.cursor_stack.name == "tool-picker" then
      pick, adv, pname = true, false, "tool-picker"
    elseif p.cursor_stack.name == "tool-picker-advanced" then
      pick, adv, pname = true, true, "tool-picker-advanced"
    else
      pick = false
    end
    if pick then
      -- Return the picker tool to inventory:
      qb = p.get_inventory(defines.inventory.player_quickbar)
      if qb.can_insert({name = pname, count = p.cursor_stack.count}) then
        qb.insert({name = pname, count = p.cursor_stack.count})
      else
        p.insert({name = pname, count = p.cursor_stack.count})
      end
      p.cursor_stack.clear()
      if p.selected then
        if adv or p.can_reach_entity(p.selected) then
          item = p.selected.name
          ip = game.item_prototypes[item]
          if ip then  -- If the item has a prototype, then it's something we can pick up.
            n = math.min(p.get_item_count(item), ip.stack_size)
            if n > 0 then
              -- Put items in the cursor stack:
              p.cursor_stack.set_stack({name=item, count=n})
              -- Remove an equal number from the main inventory:
              p.remove_item({name = item, count = n})
            else
              p.print("No "..item.." in inventory.")
            end
          end
        end
      else
        -- No entity under cursor; maybe the player doesn't know how to use the picker.
        p.print("Place cursor over an object before activating picker tool.")
      end
    end
  end
end)

Tinyboss
Fast Inserter
Fast Inserter
Posts: 205
Joined: Sun Nov 16, 2014 12:11 pm
Contact:

Re: Need help with updating Picker

Post by Tinyboss »

Liquid5n0w knows already, but in case anyone else comes across this, Picker is updated for .13 and and on the portal now.

Post Reply

Return to “Modding help”