gadget:UnitPreDamaged and script.HitByWeapon are both called when a unit takes damage (and both can overwrite the damage)
example usage would be to use script.HitByWeapon to have the unitscript play a hit-animation when a unit was damaged.
And UnitPreDamaged to overwrite damage: like a unit does not take damage in "superpower mode" or whatever.
But that example already fails, because script.HitByWeapon gets called BEFORE gadget:UnitPreDamaged.
So the unit script would play the hit animation even if the gadget later decides no damage was taken.
For example to make flying debris pieces cause less damage one can do:
Code: Select all
function gadget:UnitPreDamaged (...)
if weaponDefID == -1 then -- -1= flying debris pieces
return 5
Code: Select all
function script.HitByWeapon (x, z, weaponDefID, damage)
if weaponDefID == -1 then damage=5 end - --1= flying debris pieces
...
animation that takes into account damage
...
return damage
Share this if you cry everywhere. 1 like = #yoloswag.
I think the order makes more sense like this:
1) gadget:UnitPreDamaged (can overwrite engine damage)
2) script.HitByWeapon (can again overwrite)
3) gadget:UnitDamaged (just notification callin)
I can not think of a situation where you would want 1&2 otherway around.
especially since it also is:
1) gadget:UnitDestroyed
2) script.killed
Or make new LUS callin so that order would be like:
1) script.HitByWeapon (can overwrite engine damage)
2) gadget:UnitPreDamaged (can overwrite above)
3) script.HitByWeaponAfterGadget (just notification callin like UnitDamaged is)
(maybe name it something more clever)
4) gadget:UnitDamaged (just notification callin)
Only other idea I thought of is make your own script.HitByWeaponForReal like:
Code: Select all
gadget:UnitPreDamaged (...)
CallAsUnit (unitID, evn.HitByWeaponForReal, realDamage)
Or maybe the swapping can be done with gadget handler already?