Page 1 of 1

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

Posted: Mon Jan 20, 2020 11:33 am
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?

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

Posted: Mon Jan 20, 2020 12:21 pm
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)

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

Posted: Tue Jan 21, 2020 1:31 pm
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