[Logged] Unitwrapper damage.dp-percent reliability (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Tech Support


KnightHawk75 -> [Logged] Unitwrapper damage.dp-percent reliability (6/13/2021 1:50:04 PM)

Typical UnitWrapper.damage table entries

{ startdp = '0', fires = 'NoFire', flood = 'NoFlooding', dp_percent = '50', dp = 0 }

Issue: Upon a repair no matter if via Lua or the GUI the dp_percent value stays at the value prior to the change.
This is not a problem with the GUI display, that % updates accurately.

Repo: (plot basic hanger and some some other unit that will damage it less that 100% per munition)
1. Have unit fire a shots at the hanger.
1. A unit takes damage let say to 40%.
2. One queries it via Lua

u = ScenEdit_GetUnit({guid="TheGuidHere"})
-->> { startdp = '0', fires = 'NoFire', flood = 'NoFlooding', dp_percent = '40', dp = 0 }

3. One repairs the unit fully (via the GUI or Lua.. does not matter in my testing).
4. One queries it again via Lua (the GUI shows correct 0% damage value).

u = ScenEdit_GetUnit({guid="TheGuidHere"})
-->> { startdp = '0', fires = 'NoFire', flood = 'NoFlooding', dp_percent = '40', dp = 0, dp_percent_now=0}

5. Have hanger unit take damage again, say of 25%.
6. One queries it again via Lua (the GUI shows correct 25% left value).

u = ScenEdit_GetUnit({guid="TheGuidHere"})
-->> { startdp = '0', fires = 'NoFire', flood = 'NoFlooding', dp_percent = '25', dp = 0}

Is this intentional?

Also when a trigger fires based on damage dp_percent_now will also appear with the % damage taken it would seem either 'that round' or in the amount that caused the trigger to well.. trigger. ;) Are there other cases where the percent_now variant will appear? I'm wondering cause as much as I would like to use _now as a workaround indicator I'm not sure it'll always be valid. In cases where trapping the second in which damage occurs both need to be added together (dp_percent for the existing and dp_percent_now for this cycle not yet included) in my experience.

I was thinking maybe it's the way it is to so someone could track differences without their own table, but in addition to the above complicating that, the _now variant will not show up on lua or gui invoked new 'damage' so that would not work in a full coverage sort of way. btw I'm not say _now should appear in that case just pointing out it doesn't - it does for lua invoked full repairs.

So I wonder can we get dp_percent to just update upon repairs to 0? Along with keeping the _now flag stuff untouched? Would that break\impact something I'm not thinking about?

If that can't be tweaked without other impact, then if I was to work around this issue I have a question. Is it ALWAYS the case that the something like the following first line will be true only when a repair has happened but no new damage has been taken yet.
if (u.damage.dp_percent_now ~=nil) and u.damage.dp_percent_now == 0.0 and u.damage.dp_percent > 0.0 then 
 --I've been repaired recently to 100%|0 damage, use dp_percent_now value as real dmg percentage.

elseif((u.damage.dp_percent_now ~=nil) and u.damage.dp_percent_now >0.0) and u.damage.dp_percent > 0.0 then
  --I've just been damaged this cycle\second add both together for real total 'this second'.
  --till it's incorporated into percent next cycle where dp_percent_now does not exist anymore.

elseif((u.damage.dp_percent_now ==nil) and u.damage.dp_percent > 0.0 then
  --Unit has damage, dp_percent is correct value for damage, including if It's been repaired to less than 100%.
  --check my external damage tracking table for last value to detect if new value is pos or neg change.
  --and if to do something and update the value.
... yada yada
  -- go update last value in our external damage tracking table for this unitguid. 
...yada yada

This seems to be the case and a workaround but, I don't know...what I don't know, in terms of when _percent_now shows up as 0.0 (and sticks around)- only case I have come across is 100% repair followed by no new damage yet.
Just wondering if there are other cases the devs might shed light on.

I'll provide a scenes if needed, this is more a is it really supposed to work this way sort of question when it comes to dp_percent not updating, cause I could see there being a reason, and just trying to find a workaround for it.

edited 6/14: I had 100% where I meant 0% for what the gui displays for damage, but I think anyone reading knew what I meant along with minor edit in verbiage for better clarity.

WSBot -> RE: Unitwrapper damage.dp-percent reliability (6/14/2021 2:50:16 PM)


michaelm75au -> RE: Unitwrapper damage.dp-percent reliability (6/19/2021 2:35:15 AM)

The 'dp_percent' represents the unit's last damage % and is used by the trigger to determine if it has changed from the last time it was checked.
This is also used to stop a damage trigger from firing again if a unit was repaired below the damage threshold.
If you do want to fire the trigger again once it it is repaired below the threshold, I will create a method in the wrapper to allow you to reset it (eg u.oldDamagePercent = 0)

The current damage percent was only showing if it differed from the old percent. I have changed this to always show the current damage percent as this is better especially if you want to clear the old damage percent.

KnightHawk75 -> RE: Unitwrapper damage.dp-percent reliability (6/19/2021 8:06:10 PM)

That would address it I think, as well as addressing the unmentioned threshold reached\fire-only-once issue.
Thanks! [&o]

Related but a different topic, is there anyway to trap any\all damage events on damage trigger (ie fire on _any_ damage amount, vs just 'over' X amount, where X is 1-99)? Then again the above solution you mention pretty much would solve what I was running into (wanting to trap all damage events small or large) when dmg >= 1 because I could now "reset" it. Thing is I was trying to solve for < 1.0 as well, as units can often take damage in < 1.0 increments. So I was just wondering if say a damage threshold setting of say 0 (if it was allowed) in the event setting would just fire on any\all damage that was > 0.0. I tried leaving the trigger setting unspecified\untouched for "0", but didn't seem work - I didn't try changing\creating the event via lua and setting it to 0. ;)

michaelm75au -> RE: Unitwrapper damage.dp-percent reliability (6/20/2021 1:11:37 AM)

I was actually thinking earlier of an option on the damage trigger to allow 'all' damage to trigger it. But this may slow the turn down with callouts to Lua if there are lot of damage caused in turn.

Page: [1]

Valid CSS!

Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI