is it possible to create an explosion upon an item's destruction?

Place to get help with not working mods / modding interface.
Post Reply
rhynex
Long Handed Inserter
Long Handed Inserter
Posts: 63
Joined: Tue Apr 17, 2018 9:55 am
Contact:

is it possible to create an explosion upon an item's destruction?

Post by rhynex »

as title asks.

I want to prevent or at least give side effects to player if player decides to attack the chest containing that specific item (it is not an entity).

background: lets assume you use item A and B in a recipe and create item "Dangerous". then player puts the item "Dangerous" to a chest. there is no recipe using "Dangerous" so players has to get rid of it expensively or keep it in storage. obviously a player can put it into a chest and then shoot it. I want player not to do this so I want an explosion (nuclear bomb like) upon destroying that "Dangerous" item. it can be similar to nuclear reactor explosion but it is not an entity, just a regular item.

is it possible?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: is it possible to create an explosion upon an item's destruction?

Post by DaveMcW »

Code: Select all

script.on_event(defines.events.on_entity_died, function(event) 
  if event.entity and event.entity.valid and event.entity.get_item_count("dangerous-item") > 0 then
    -- create explosion
  end
end)

rhynex
Long Handed Inserter
Long Handed Inserter
Posts: 63
Joined: Tue Apr 17, 2018 9:55 am
Contact:

Re: is it possible to create an explosion upon an item's destruction?

Post by rhynex »

awesome. thank you. I shall try this tonight.
Is there a mod you have in mind as an example so I can steal some code ? :D

Post Reply

Return to “Modding help”