Page 1 of 1

Prevent equipment pickup of mined Entity

Posted: Mon Mar 28, 2016 5:00 pm
by BarkerZA
Hello all,

I am busy attempting to create a mod that I need to prevent the player from picking up an item after it has been mined. I've left the appropriate code below to give some context.

Code: Select all

-- 1. Check if the player mined a lamp
-- 2. Check if lamp is in combined table
-- 3. If so, destroy pole entity and prevent lamp from being added to inventory 
-- 4. Add electric pole to inventory

game.on_event(defines.events.on_preplayer_mined_item, function(event)
   if (event.entity.name == "small-lamp") then
      for k,v in pairs(global.combined) do
         if (event.entity == v.light) then
            v.light.destroy()
            v.pole.destroy()
            game.get_player(1).character.insert({name="small-electric-pole", count =1})
            
         end
      end
   end
end)
Please bare in mind that I know I need to make it multiplayer friendly. Will get there eventually.

Re: Prevent equipment pickup of mined Entity

Posted: Tue Mar 29, 2016 10:03 am
by seronis
Look at the Bio Farm mod. When biofarms are built they spawn invisible power lines and a couple other entities as helper objects. The mod also cleans up those objects when you mine the biofarm itself. I'm assuming you need to prevent pickup of something for a similar reason (its a helper entity and not meant to be considered an actual separate object)