on_entity_damaged does not get called when healing

Place to get help with not working mods / modding interface.
Post Reply
Svip
Long Handed Inserter
Long Handed Inserter
Posts: 88
Joined: Sun Apr 29, 2018 6:19 am
Contact:

on_entity_damaged does not get called when healing

Post by Svip »

Short story; I am trying to build in a concept of hunger/satiety in the game. I figured using that negative damage numbers can heal would be a good solution for the concept of eating. Unfortunately, "on_entity_damaged" does not appear to get called, when the number is negative (i.e. healing), since I want to hook in to avoid it actually healing, as I'd rather it fills up the satiety meter.

Is there a way to act on when the character is healed?

I've tried using fuel_value, and using the "script" event for the raw fish capsule. That works, but it looks awkward in the tooltip, and there doesn't appear to be a way to hook into tooltips, which would make an alternative of a global table which stores all these values even more opaque.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2710
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: on_entity_damaged does not get called when healing

Post by FuryoftheStars »

I've nevered played around with this concept, but would on_player_used_capsule be useful here?

You can put the values of what it does in the description.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics

Svip
Long Handed Inserter
Long Handed Inserter
Posts: 88
Joined: Sun Apr 29, 2018 6:19 am
Contact:

Re: on_entity_damaged does not get called when healing

Post by Svip »

I realised I could put it in the description, but I would prefer a generalised approach (if possible), since I intend to add quite a few items that can be eaten.

Regardless, thank you for your suggestion. I was able to achieve the same effect, and now the tooltip works. Of course, I now have to do a bit of checking that it's the "right" capsule. But now, if a capsule has a damage effect of type "hunger" and a negative value, it is automatically understood as a satiety boosting item.

Svip
Long Handed Inserter
Long Handed Inserter
Posts: 88
Joined: Sun Apr 29, 2018 6:19 am
Contact:

Re: on_entity_damaged does not get called when healing

Post by Svip »

Apologies for double posting, but I feel like this is distinct enough to warrant another post, but not quite enough to warrant another topic.

After experimenting with above, there is one quirk that remains. Besides healing my "hunger"-bar, it also heals the character's health (which makes sense). But I don't want it to do that, or rather, I don't want it to heal it by the same amount. Now, I cannot simply subtract the amount for the character's health, because if the character is at full health, they shouldn't be losing health by eating.

At first, I wondered if resistances works against healing as well (they do not). I could go with the "on_entity_damaged" approach, and then simply remove the damage (since that event provides me with enough information to undo the damage), but that leads to two awkward problems; the tooltip now says damage, but also you get the damage effect when eaten, and considering what I have in mind for this mod, that's going to be rather annoying in the latter part of the game.

So while "on_player_used_capsule" works on the surface, the problem is I don't know how much the character was healed (I think I am going to advocate for a "on_entity_healed" event, but that's for a different topic), so I can only guess.

So my solution - at least the one I've conjectured up so far - is to save every 30 ticks, what the health was of each character. Then once the capsule event happens, I can revert to the correct health of the character. But I wonder; what are the odds that the player eats the capsule (fish), the character is healed, the tick event runs and thus updates the health to its condition after being healed, and then my capsule event runs, now having the wrong information to adjust the health by. Because when I check the health of my character in the capsule event, it is clear it takes place after the character was healed.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2710
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: on_entity_damaged does not get called when healing

Post by FuryoftheStars »

Afaik, the event should run on the same tick. I think the only one that can run in a different tick is on_entity_destroyed, but only in relation to register_on_entity_destroyed.

That said, without fully understanding your goals, etc, wouldn't it be easier to remove the healing property from the fish...?
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics

Svip
Long Handed Inserter
Long Handed Inserter
Posts: 88
Joined: Sun Apr 29, 2018 6:19 am
Contact:

Re: on_entity_damaged does not get called when healing

Post by Svip »

My main motivation was primarily to make a consistent tooltip look, while also storing the value on the item (thus allowing me to add more items in the data stage without altering my runtime stage). Though, I realised an alternative that works is to use fuel. You can essentially give a random item a fuel category and value.

So yes, there is an alternative solution to my problem. The only downside is that I cannot add a food value to an item that can also be burnt. But I can live with that drawback for now.
Attachments
20240522160134_1_crop.jpg
20240522160134_1_crop.jpg (47.41 KiB) Viewed 244 times

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2710
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: on_entity_damaged does not get called when healing

Post by FuryoftheStars »

Svip wrote:
Wed May 22, 2024 2:07 pm
My main motivation was primarily to make a consistent tooltip look [...]
Well, considering these would presumably be the only items in game with this type of value, you can add these to the description locale using "/n" to create line breaks as needed. This also supports formatting. :)
Svip wrote:
Wed May 22, 2024 2:07 pm
[...] while also storing the value on the item (thus allowing me to add more items in the data stage without altering my runtime stage).
I think you should be able to create a common file with the values and load it both from the data and control stages. Or use a hidden string setting where you've serialized it all together. I just don't know if this can also be loaded and used from a locale file. :? Oh! But you might be able to use the localised_description property instead (of the locale file)? It says it overwrites... I don't know if there's a way to (ab)use it to append instead so it can respect translations?
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics

Svip
Long Handed Inserter
Long Handed Inserter
Posts: 88
Joined: Sun Apr 29, 2018 6:19 am
Contact:

Re: on_entity_damaged does not get called when healing

Post by Svip »

I'll admit I am very pleased with using the fuel solution for now. This allows me to set the value for each item once.

Though, if I run into another obstacle here, I may have to change it for the table/description solution. My main problem here is ergonomics. For each item, I would essentially have to 1) write a common file with the table of the values in, 2) add to every description for each of these items the placeholder text, 3) load the common value during the data stage and add it to the items and 4) look up the common table during runtime. Compared to my current solution; 1) add the fuel value to the item during data, 2) read the fuel value during runtime.

Still, I appreciate your help and suggestions. I apologise if I come off as dismissive. Whilst I have not used your exact suggestions (besides the capsule event), your suggestions have inspired me!

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2710
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: on_entity_damaged does not get called when healing

Post by FuryoftheStars »

I've never tried doing what you're doing, so I'm just brainstorming. :)

Though my Artificial Tiles mod requires passing some info from data to control, because it's all dynamic and other mods can load their own data into it, I use a dummy tech as the pass-thru, not a common file.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics

Post Reply

Return to “Modding help”