Event Handlers – Arma 3 Talk

From Bohemia Interactive Community
Jump to navigation Jump to search
(→‎HandleDamage: Supplied partial test script and my thoughts on the results, and hoping for feedback.)
(Scrubbed the conversation I'm having with myself since I have figured out exactly what's going on, and will set about editing the documentation soon.)
Line 28: Line 28:
-- I wouldn't put any definite numbers if I were you. It needs to be tested not only with units and as far as I remember for vehicles you can get EH triggered for damages < 0.5. I personally think copy paste from "Hit" EH where it explains sensitivity  would be sufficient.
-- I wouldn't put any definite numbers if I were you. It needs to be tested not only with units and as far as I remember for vehicles you can get EH triggered for damages < 0.5. I personally think copy paste from "Hit" EH where it explains sensitivity  would be sufficient.


::I'm not seeing ''Dammage EH'' triggering for less than 0.5 on Pawnees, Hunters and others, but sure, without confirmation (it'll be in the code somewhere), figures are tough to justify. I agree; a copy-paste of the note in ''Hit EH'' would be a start (I noticed that after my last comment here). At least it gives a clue to expect less than obvious behaviour.
::I'm not seeing ''Dammage EH'' triggering for less than 0.5 on Pawnees, Hunters and others, but sure, without confirmation (it'll be in the code somewhere), figures are tough to justify. I agree; a copy-paste of the note in ''Hit EH'' would be a start (I noticed that after my last comment here). At least it gives a clue to expect less than obvious behaviour. [[User:Fred Gandt|Fred Gandt]] ([[User talk:Fred Gandt|talk]]) 13:42, 4 March 2014 (CET)
::*Speaking of which...
<pre>v addEventHandler ["HandleDamage", {
    _v = _this select 0;
    if (alive _v) then {
        _s = _this select 1;
        if (_s == "") then {
            _s = "vehicle";
        };
        if (_s == "?") then {
            _s = "thingummybob";
        };
        hintSilent format ["Total damage: %1\nHit damage: %2\nSection: The %3", damage _v, _this select 2, _s];
        if (damage _v > 0) then {
            _v setDamage 0;
        };
    } else {
        hintSilent "Something else that doesn't matter out of context.";
    };
}];</pre>
::Assuming ''v'' is a vehicle like a Pawnee in perfect condition, and assuming it just got hit by a 6.5mm round, wouldn't we expect a hint reading something like
<pre>Total damage: 0.000947657
Hit damage: 0.284657
Section: The tail rotor</pre>
::And then find that all the damage has been repaired?
::Well we don't!
<pre>if (damage _v > 0) then {
    _v setDamage 0;
};</pre>
::does it's job exactly as we should expect, but <pre style="display:inline;margin:0px;padding:3px 3px 2px 5px;">hintSilent format ["Total damage: %1\nHit damage: %2\nSection: The %3", damage _v, _this select 2, _s];</pre> produces something like
<pre>Total damage: 0
Hit damage: 0.284657
Section: The tail rotor</pre>
::The hit damage, section and <pre style="display:inline;margin:0px;padding:3px 3px 2px 5px;">_v setDamage 0;</pre> are all as they should be, but somehow the value for <pre style="display:inline;margin:0px;padding:3px 3px 2px 5px;">damage _v</pre> in the hint is zero - even when the <pre style="display:inline;margin:0px;padding:3px 3px 2px 5px;">if (damage _v > 0)</pre> returns true!
::I've tried a dozen different methods (this one is the simplest for demonstration), and none avoid the issue. Even <pre style="display:inline;margin:0px;padding:3px 3px 2px 5px;">_foo = damage _v</pre> and using _foo in the hint, or <pre style="display:inline;margin:0px;padding:3px 3px 2px 5px;">_v setVariable ["foo", damage _v, true]</pre> and getting the value for the hint don't work.
::I even tried spawning scripts, calling functions, waiting until, sleeping, and using two EHs, but nothing.
 
::Very strange behaviour. [[User:Fred Gandt|Fred Gandt]] ([[User talk:Fred Gandt|talk]]) 13:42, 4 March 2014 (CET)
:::Although I'm getting to the bottom of it... [[User:Fred Gandt|Fred Gandt]] ([[User talk:Fred Gandt|talk]]) 08:08, 5 March 2014 (CET)
 
==HandleDamage==
10 shots at a scripted Pawnee from a 6.5mm MX at close range resulted in the following to [[diag_log]]:
<pre style="height:100px">
"Event: 0 || Total Damage: 0 || Hit Damage: 0.00104039 || Section: The vehicle"
"Event: 1 || Total Damage: 0.00104039 || Hit Damage: 0 || Section: The fuel"
"Event: 2 || Total Damage: 0.00104039 || Hit Damage: 0 || Section: The hull"
"Event: 3 || Total Damage: 0.00104039 || Hit Damage: 0 || Section: The engine"
"Event: 4 || Total Damage: 0.00104039 || Hit Damage: 0.650052 || Section: The avionics"
"Event: 5 || Total Damage: 0.00104039 || Hit Damage: 0 || Section: The tail rotor"
"Event: 6 || Total Damage: 0.00104039 || Hit Damage: 0 || Section: The main rotor"
"Event: 7 || Total Damage: 0.00104039 || Hit Damage: 0 || Section: The glass1"
"Event: 8 || Total Damage: 0.00104039 || Hit Damage: 0.0114876 || Section: The glass2"
"Event: 9 || Total Damage: 0.00104039 || Hit Damage: 0.00114631 || Section: The vehicle"
"Event: 10 || Total Damage: 0.00114631 || Hit Damage: 0 || Section: The fuel"
"Event: 11 || Total Damage: 0.00114631 || Hit Damage: 0.0123528 || Section: The hull"
 
"Event: 12 || Total Damage: 0.00114631 || Hit Damage: 0.00237226 || Section: The vehicle"
"Event: 13 || Total Damage: 0.00237226 || Hit Damage: 0 || Section: The fuel"
"Event: 14 || Total Damage: 0.00237226 || Hit Damage: 0.10704 || Section: The hull"
"Event: 15 || Total Damage: 0.00237226 || Hit Damage: 0.0281299 || Section: The engine"
 
"Event: 16 || Total Damage: 0.00237226 || Hit Damage: 0.00250229 || Section: The vehicle"
"Event: 17 || Total Damage: 0.00250229 || Hit Damage: 0 || Section: The fuel"
"Event: 18 || Total Damage: 0.00250229 || Hit Damage: 0.117041 || Section: The hull"
"Event: 19 || Total Damage: 0.00250229 || Hit Damage: 0.0281299 || Section: The engine"
"Event: 20 || Total Damage: 0.00250229 || Hit Damage: 0.650052 || Section: The avionics"
"Event: 21 || Total Damage: 0.00250229 || Hit Damage: 0 || Section: The tail rotor"
"Event: 22 || Total Damage: 0.00250229 || Hit Damage: 0.0770749 || Section: The main rotor"
 
"Event: 23 || Total Damage: 0.00250229 || Hit Damage: 0.00289331 || Section: The vehicle"
"Event: 24 || Total Damage: 0.00289331 || Hit Damage: 0 || Section: The fuel"
"Event: 25 || Total Damage: 0.00289331 || Hit Damage: 0.194735 || Section: The hull"
"Event: 26 || Total Damage: 0.00289331 || Hit Damage: 0.0281299 || Section: The engine"
"Event: 27 || Total Damage: 0.00289331 || Hit Damage: 0.678438 || Section: The avionics"
"Event: 28 || Total Damage: 0.00289331 || Hit Damage: 0 || Section: The tail rotor"
"Event: 29 || Total Damage: 0.00289331 || Hit Damage: 0.0770749 || Section: The main rotor"
"Event: 30 || Total Damage: 0.00289331 || Hit Damage: 0.101878 || Section: The glass1"
"Event: 31 || Total Damage: 0.00289331 || Hit Damage: 0.00289331 || Section: The vehicle"
"Event: 32 || Total Damage: 0.00289331 || Hit Damage: 0 || Section: The fuel"
"Event: 33 || Total Damage: 0.00289331 || Hit Damage: 0.205623 || Section: The hull"
"Event: 34 || Total Damage: 0.00289331 || Hit Damage: 0.0281299 || Section: The engine"
"Event: 35 || Total Damage: 0.00289331 || Hit Damage: 0.714742 || Section: The avionics"
"Event: 36 || Total Damage: 0.00289331 || Hit Damage: 0 || Section: The tail rotor"
"Event: 37 || Total Damage: 0.00289331 || Hit Damage: 0.0770749 || Section: The main rotor"
"Event: 38 || Total Damage: 0.00289331 || Hit Damage: 0.133224 || Section: The glass1"
"Event: 39 || Total Damage: 0.00289331 || Hit Damage: 0.00289343 || Section: The vehicle"
"Event: 40 || Total Damage: 0.00289331 || Hit Damage: 0 || Section: The fuel"
"Event: 41 || Total Damage: 0.00289331 || Hit Damage: 0.205623 || Section: The hull"
"Event: 42 || Total Damage: 0.00289331 || Hit Damage: 0.0281299 || Section: The engine"
"Event: 43 || Total Damage: 0.00289331 || Hit Damage: 0.728024 || Section: The avionics"
 
"Event: 44 || Total Damage: 0.00289331 || Hit Damage: 0.00289496 || Section: The vehicle"
"Event: 45 || Total Damage: 0.00289496 || Hit Damage: 0 || Section: The fuel"
"Event: 46 || Total Damage: 0.00289496 || Hit Damage: 0.205623 || Section: The hull"
"Event: 47 || Total Damage: 0.00289496 || Hit Damage: 0.0281299 || Section: The engine"
"Event: 48 || Total Damage: 0.00289496 || Hit Damage: 0.728024 || Section: The avionics"
"Event: 49 || Total Damage: 0.00289496 || Hit Damage: 0 || Section: The tail rotor"
"Event: 50 || Total Damage: 0.00289496 || Hit Damage: 0.0770749 || Section: The main rotor"
"Event: 51 || Total Damage: 0.00289496 || Hit Damage: 0.153542 || Section: The glass1"
"Event: 52 || Total Damage: 0.00289496 || Hit Damage: 0.00297711 || Section: The vehicle"
"Event: 53 || Total Damage: 0.00297711 || Hit Damage: 0 || Section: The fuel"
"Event: 54 || Total Damage: 0.00297711 || Hit Damage: 0.205623 || Section: The hull"
"Event: 55 || Total Damage: 0.00297711 || Hit Damage: 0.0281299 || Section: The engine"
"Event: 56 || Total Damage: 0.00297711 || Hit Damage: 0.789819 || Section: The avionics"
 
"Event: 57 || Total Damage: 0.00297711 || Hit Damage: 0.00305546 || Section: The vehicle"
"Event: 58 || Total Damage: 0.00305546 || Hit Damage: 0 || Section: The fuel"
"Event: 59 || Total Damage: 0.00305546 || Hit Damage: 0.205623 || Section: The hull"
"Event: 60 || Total Damage: 0.00305546 || Hit Damage: 0.0281299 || Section: The engine"
"Event: 61 || Total Damage: 0.00305546 || Hit Damage: 0.789819 || Section: The avionics"
"Event: 62 || Total Damage: 0.00305546 || Hit Damage: 0.11719 || Section: The tail rotor"
"Event: 63 || Total Damage: 0.00305546 || Hit Damage: 0.00320863 || Section: The vehicle"
"Event: 64 || Total Damage: 0.00320863 || Hit Damage: 0 || Section: The fuel"
"Event: 65 || Total Damage: 0.00320863 || Hit Damage: 0.243171 || Section: The hull"
"Event: 66 || Total Damage: 0.00320863 || Hit Damage: 0.0281299 || Section: The engine"
"Event: 67 || Total Damage: 0.00320863 || Hit Damage: 0.789819 || Section: The avionics"
"Event: 68 || Total Damage: 0.00320863 || Hit Damage: 0.196099 || Section: The tail rotor"
 
"Event: 69 || Total Damage: 0.00320863 || Hit Damage: 0.00333869 || Section: The vehicle"
"Event: 70 || Total Damage: 0.00333869 || Hit Damage: 0 || Section: The fuel"
"Event: 71 || Total Damage: 0.00333869 || Hit Damage: 0.337828 || Section: The hull"
 
"Event: 72 || Total Damage: 0.00333869 || Hit Damage: 0.00335816 || Section: The vehicle"
"Event: 73 || Total Damage: 0.00335816 || Hit Damage: 0 || Section: The fuel"
"Event: 74 || Total Damage: 0.00335816 || Hit Damage: 0.353946 || Section: The hull"
"Event: 75 || Total Damage: 0.00335816 || Hit Damage: 0.0281299 || Section: The engine"
"Event: 76 || Total Damage: 0.00335816 || Hit Damage: 0.789819 || Section: The avionics"
"Event: 77 || Total Damage: 0.00335816 || Hit Damage: 0.196099 || Section: The tail rotor"
"Event: 78 || Total Damage: 0.00335816 || Hit Damage: 0.0770749 || Section: The main rotor"
"Event: 79 || Total Damage: 0.00335816 || Hit Damage: 0.153542 || Section: The glass1"
"Event: 80 || Total Damage: 0.00335816 || Hit Damage: 0.0419028 || Section: The glass2"
 
"Event: 81 || Total Damage: 0.00335816 || Hit Damage: 0.0046321 || Section: The vehicle"
 
"Event: 82 || Total Damage: 0.0046321 || Hit Damage: 0.00590047 || Section: The vehicle"
"Event: 83 || Total Damage: 0.00590047 || Hit Damage: 0.0949282 || Section: The fuel"
"Event: 84 || Total Damage: 0.00590047 || Hit Damage: 0.448627 || Section: The hull"
</pre>
 
* The "Event" number is obtained by a simple counter.
* "Total Damage" from [[damage]] _v.
* "Hit Damage" from the EH _this select 2.
* And "Section" from _this select 1 where and empty string is populated with "vehicle".
* The empty lines were added manually in [[arma.RPT]] between shots.
 
If I weren't half asleep I'd say what can be read by anyone who cares to. I think the documentation could do with more notes!
 
I'm going to add more checks including [[diag_frameno]] and see if a more accurate definition of what is really going on can be put together. There's some real wacky stuff going on in this. [[User:Fred Gandt|Fred Gandt]] ([[User talk:Fred Gandt|talk]]) 16:12, 5 March 2014 (CET)
 
The first stark contradiction to note is that the damage reported for each section '''is cumulative''' and that although the sections are reported in sequence, the sequence loop point and length is apparently indeterminate. Nailing reliability may be a problem. Perhaps we need to ask BI to add an ID as ''_this select -1'' that can be used to establish which event belongs to which ''block'' (I'm hoping either tickTime or frameno will help, but haven't got there yet). I'm way past bed time and will talk rubbish if I continue. [[User:Fred Gandt|Fred Gandt]] ([[User talk:Fred Gandt|talk]]) 17:10, 5 March 2014 (CET)
 
* This (following script) reveals what I assumed; that each "event" is directly linked to the frame it occurs in. It appears that (and this is guesstimation) the cycle through the selections is organised dependant on the available space before the frame ends (probably linked to estimated framerate). tickTime can and does change during single frames, but every "event" (group of triggers) starts with a report about the vehicle (not selection/section) during a new frame. My assumption is that high FPS would result in fewer triggers per "event" and lower FPS would result more triggers per "event". The cycling and looping through the selections/sections doesn't appear to be as simple as a repeating pattern, so much as determined on the fly for ''best'' results (whatever the engine thinks those are).
 
Suffice to say, there's more to this than the documentation or Celery's forum post explains.
 
<pre>
eha = [];
lkfn = 0;
v addEventHandler ["HandleDamage", {
    _v = _this select 0;
    if (alive _v) then {
        _s = _this select 1;
        if (_s == "") then {_s = "vehicle";};
        if (_s == "?") then {_s = "thingummybob";};
        _fn = diag_frameno;
        if (_fn != lkfn) then {
            {
                diag_log _x;
            } forEach eha;
            diag_log "//";
            lkfn = _fn;
            eha = [];
        };
        eha set [count eha, format ["tickTime: %1 || Frame Number: %2 || Total Damage: %3 || Hit Damage: %4 || Section: The %5", diag_tickTime, _fn, damage _v, _this select 2, _s]];
    } else {
        _v removeAllEventHandlers "HandleDamage";
        hintSilent "Vehicle is dead!";
    };
};
</pre>
 
So assuming ''v'' is a vehicle, and it gets shot a lot, check out the result to see for yourselves (whoever reads this), then please discuss with me how we can improve the documentation to cover this complexity without baffling noobs or contradicting veterans. [[User:Fred Gandt|Fred Gandt]] ([[User talk:Fred Gandt|talk]]) 22:49, 5 March 2014 (CET)

Revision as of 19:29, 6 March 2014

Dammaged

Appears to only trigger if the damage is greater than 0.5

Repro:

  • Add to player init

player addEventHandler ["Dammaged", { hint format ["Damage: %1", _this select 2]; }];

  • Set elevation to 5 metres.
  • Preview.
  • Exit.
  • Set elevation to 4.5 meters.
  • Preview.

You may need to fiddle with those figures a bit, but it's a quick and dirty method to test.

Observe: Only damage above 0.5 is hinted.

Am I wrong, or should this be noted in the documentation?

Fred Gandt (talk) 06:54, 3 March 2014 (CET)

-- Yes, Dammaged EH is less sensitive than HandleDamage, not sure if there is a defined threshold.

So we should add a note to the documentation? I'm pretty sure a threshold of 0.5 exists, but that obviously needs testing of verification from bistudio to justify an absolute statement. I'd consider any verifiable fact that affects returns to be important to note, even if the fact is imprecise. A note to the effect that "Dammage will not necessarily trigger for < 0.5 damage", would at least save some folk the trouble I had trying to figure out WTF was going on. Fred Gandt (talk) 04:30, 4 March 2014 (CET)

-- I wouldn't put any definite numbers if I were you. It needs to be tested not only with units and as far as I remember for vehicles you can get EH triggered for damages < 0.5. I personally think copy paste from "Hit" EH where it explains sensitivity would be sufficient.

I'm not seeing Dammage EH triggering for less than 0.5 on Pawnees, Hunters and others, but sure, without confirmation (it'll be in the code somewhere), figures are tough to justify. I agree; a copy-paste of the note in Hit EH would be a start (I noticed that after my last comment here). At least it gives a clue to expect less than obvious behaviour. Fred Gandt (talk) 13:42, 4 March 2014 (CET)