Prevent equipment pickup of mined Entity

Place to get help with not working mods / modding interface.
BarkerZA
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sun Mar 27, 2016 9:30 pm
Contact:

Prevent equipment pickup of mined Entity

Post 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.
seronis
Fast Inserter
Fast Inserter
Posts: 225
Joined: Fri Mar 04, 2016 8:04 pm
Contact:

Re: Prevent equipment pickup of mined Entity

Post 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)
Post Reply

Return to “Modding help”