Page 1 of 1

Function referencing to entity health %

Posted: Mon Nov 16, 2020 1:35 am
by AyleeJenn
TL;DR
A function that references to hull status % and allows an action/trigger/effect/etc to happen based on the entity's hull status %

What ?
The addition of a function in the game's programming that allows something to happen when any entity's health status is at a certain value. That way modders can make things happen when an entity's health bar is at a certain level.
Why ?
It lets modders do more cool things based on hull status bar of any entity. For example, if something damages a factory, it would actually look like a damaged factory, with smoking or burning buildings. Or a building or vehicle, when damaged could trail smoke and fire if its hull drops below fifty percent. Or you could make a cool boss fight with it.

Re: Function referencing to entity health %

Posted: Mon Nov 16, 2020 6:41 am
by darkfrei

Re: Function referencing to entity health %

Posted: Mon Nov 16, 2020 11:10 am
by eradicator
defines.events.on_entity_damaged

Re: Function referencing to entity health %

Posted: Mon Nov 16, 2020 3:40 pm
by AyleeJenn
Excellent! Thank you for the link and for guiding me to the right place. I can see that this function already exists. (And I should have seen it :oops: thereby making a classic case for "search first". So, I am trying to own up to it :oops: )

Eradicator: Thank you very much for pointing out the "defines.events.on_entity_damaged". I appreciate it. I know about the on_entity_damaged function but that only works on the event that an entity is damaged. What I need is a function that reads an entity's health and then allows for something to happen based on the value of entity health that the function reads. In other words, I need the function to work also when an entity is not getting damage and simply at a certain health level.

Re: Function referencing to entity health %

Posted: Mon Nov 16, 2020 4:31 pm
by Deadlock989
AyleeJenn wrote: Mon Nov 16, 2020 3:40 pm Eradicator: Thank you very much for pointing out the "defines.events.on_entity_damaged". I appreciate it. I know about the on_entity_damaged function but that only works on the event that an entity is damaged. What I need is a function that reads an entity's health and then allows for something to happen based on the value of entity health that the function reads. In other words, I need the function to work also when an entity is not getting damage and simply at a certain health level.
Nothing like that exists I'm afraid. You would be reduced to polling in on_tick / on_nth_tick.

In vanilla, health can change either (a) as a result of damage or (b) as a result of healing. The former has an event so you can check when damage is taken, what the new health level is, and do whatever you like from there. The latter is much more difficult because it can come (a) from an entity's natural healing_per_tick (b) from the action of repair kits (c) from the application of a fish made of antimatter that flies 0cm through the air (d) from literally any script in any mod that manipulates health properties directly.

Re: Function referencing to entity health %

Posted: Mon Nov 16, 2020 7:26 pm
by AyleeJenn
Deadlock989,

thank you very much for the additional information and clarification. I am sad to hear that the function I requested does not exist, afterall. But at the very least it lends credence to my function-request. I hope a function like I requested is included someday. It would help, I feel. :?

Thank you also for the detailed explanation on how things work :shock: I had a vague feeling it would be like that and from what I understood thus *far* reading through your messages makes a lot of sense. It may only have taken you mere seconds to write up your message but it helped me understands things a *ton*. Thank you for that.

Re: Function referencing to entity health %

Posted: Mon Nov 16, 2020 8:00 pm
by Deadlock989
I think partly there is a terminology issue here. You keep saying "function" but I think what you mean is "event". There already is a function that can return entity health as a percentage - that is why the thread got marked as "Already exists". It sounds like what you want is an event that is triggered when an entity's health passes some threshold. I am not sure that is ever likely to happen because it sounds expensive but also all the many, many ways it could happen (e.g. nothing to stop a script in another mod just setting an entity's health directly without even invoking "damage" or "healing"). Not up to me though obviously.

If you are looking to apply damage effects and things like that, your best bet is to use the damage event and have the effects time out and disappear naturally after a set period of time. This is the approach the game takes in general to trauma-related things like corpses, craters, scorch marks, smoke, fire, particle effects etc.

It would be kind of nice to have alternative graphics sets for entities that represented different health states but on the other hand modders have enough work to do creating new entities what with base animations, shadows, working visualisations, light effects, destroyed remnants, water reflections ... it has to stop somewhere and I personally don't bother with all of those already, especially the remnants and reflections.

Re: Function referencing to entity health %

Posted: Mon Nov 16, 2020 8:33 pm
by AyleeJenn
Ahhh, okay. Yes! I agree. There was definitely a terminology issue here. And that is my bad :oops: You read my messages right despite me using the wrong language. What I tried to say was "event" not function :? I am sorry for the confusion. But that one is entirely on me. I apologize. Thank you for offering corrections :) I appreciate it.

Thank you also for explaining the difference and how the game handles things and what the best bet is on creating something like damage effects. Your message response was very helpful for me to read and I am grateful you took the time out of your day to write it for me. Much appreciated!!!

I feel I have much better understanding now of not only the game but also the terminology (function/event :? , sorry again :oops: ). It feels nice to be able to try and do my own homework and look into things and research and try to understand things on my own but also being able to come here and just ask when I am unsure.

I appreciate you and everyone being so helpful. It honestly feels great.