• If you have a mod, tool or prefab, please use the Resources section. Click Mods at the top of the forums.

How can I force a block or entity to trigger a game event whenever the block is destroyed?

gaveitatry

Refugee
I have a block set to activate an event when 'E' is pressed.

But I want the block to activate a different event when I destroy the block. Or to have a nearby entity to trigger that event when I destroy the block.

*****
For context, the block spawns entities and assigns them to a group whenever 'E' is pressed. And when the block is destroyed, I want it to trigger a different event that will do a RemoveEntities to the target_group that the entities are assigned to.

*****

I tried using AI to figure this out. It suggested that I create a block property "DropEvent" with the game event set as the value. That did not work. It also suggested that I have the entity act as a watchdog and assign it a buff that checks to see if the block still exists. It mentioned things like "HasBlockTag", "BlockNearby", "onBlockPlaced", and "onBlockDestroyed". But as far as I know, those things are purely fictional and don't exist.

*****

I am hoping to find a XML solution. I know nothing about Harmony. But I am willing to use Harmony as a last ditch effort if there is no other choice.
 
[SOLVED]

I think that I found a solution that works for me.

In addition to the block event "ActivateEvent", there is also a block event called "DamageEvent". That means if the block takes any damage, no matter how small, it will trigger a game event. However, this alone won't work. It needs to be paired with "DowngradeBlock". Why? Well if I don't use the "DowngradeBlock" and I destroy the block with one hit instead of just damaging it, the event won't activate. With "DowngradeBlock", I can safely destroy the block with one hit, trigger the event, and be left with some other block that replaced the original after it was downgraded.
 
Back
Top