• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Block Damage trigger problem

Status
Not open for further replies.
Level 4
Joined
Dec 5, 2011
Messages
75
my spell create a wall on unit and blocks (X) amount of damage
Problems found:
-the spell dont block the first attack only the second
-after blocking all damage at first cast the next block amount is reduced..
  • Cast Wall(Initially On)
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to (==) Wall
    • Actions
      • Set CasterWall = (Target unit of ability being cast)
      • Set LastLocation = (Position of (Target unit of ability being cast))
      • Set AbsorbedDamage = 0
      • Set MaxDamage = (100 x (Level of Wall for CasterWall))
      • Trigger - Add to Absorb Wall <gen> the event (Unit - CasterWall Takes damage)
      • Trigger - Turn on Absorb Wall <gen>



  • Absorb Wall(Initially Off)
    • Events
    • Conditions
    • Actions
      • Unit - Set life of CasterWall to ((Life of CasterWall) + (Damage taken))
      • Set AbsorbedDamage = (AbsorbedDamage + (Integer((Damage taken))))
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • AbsorbedDamage Greater than or equal to (>=) MaxDamage
          • Then - Actions
            • Special Effect - Create a special effect at LastLocation using Objects\Spawnmodels\NightElf\NEDeathMedium\NEDeath.mdl
            • Special Effect - Destroy (Last created special effect)
            • Custom script: call RemoveLocation (udg_LastLocation)
            • Trigger - Turn off (This trigger)
          • Else - Actions
Thanks!!
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
-after blocking all damage at first cast the next block amount is reduced..

It looks like the reason it reduces the damage the second time around is because you're registering the same event to the unit twice. I tried registering two identical Unit takes damage events to a single trigger and it executed the trigger-actions twice on only a single occurrence of the event.

The solution to this would be remembering which units have been registered to the trigger (using a hashtable would be one of the more efficient ways of doing this). You could also use a Damage Detection Engine.

-the spell dont block the first attack only the second

Is the unit at full health when the unit is attacked? It looks like you immediately add the health to compensate for the damage, but the damage takes place after the fact that you've added the health. If the unit is at 100/100 health, you add 25, and then subtract 25, you're left with 75/100 health (because unit health cannot go above 100%).

The fix to this is to remember the health of the unit before the damage takes place, and then set it to that amount after the damage has been dealt (which occurs immediately after the event fires the trigger). In order to set the unit's health immediately after the damage has been dealt you'll have to run a 0-second expiring timer and apply the actions on the 0-second expiration.

This has a different problem as well. In cases where you want to reduce damage that exceeds the unit's maximum health, you're going to have even more trouble. Resetting the unit's health after the damage has been dealt won't work because the unit will have died (and cannot be set to alive). Adding that amount of health before the damage is dealt won't work either because even if the unit is at maximum health, the unit will still die once the damage is dealt. The trick to getting past this problem is using an ability that increases maximum life to increase the unit's life to some large amount, such as 10^6. This will allow the unit to be damaged without killing it, and allow you to modify the unit's life after the damage has been dealt so it reflects the correct amount.
 
Level 4
Joined
Dec 5, 2011
Messages
75
then should i add a condition in the second trigger to solve the 1st problem?
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Well you won't want a condition, but you'll want something that prevents this from happening to a unit twice:
  • Trigger - Add to Absorb Wall <gen> the event (Unit - CasterWall Takes damage)
Because if it is added to the same unit twice, then the actions associated with that trigger are going to be executed twice on a single occurrence of the event (which you don't want).

In order to determine whether or not this unit has been added, I suppose I would suggest a hashtable. The hashtable can store the integer ID of the unit (which is unique for every unit) and then a check to see whether or not the unit's integer ID is contained in the hashtable would determine whether or not you need to add the unit takes damage event to the trigger.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Do you want to completely block the damage, or what ?

If yes, just add Hardened Skin ability to the unit, set the Data - Ignored Damage to 9999999.00 and the Data - Minimum Damage to 0

Solve for completely block enemy physical damage
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
I'm not sure if it works for blocking instances of physical damage, but I'm not sure. I believe that once the Unit takes damage event triggers you cannot prevent the damage from affecting the unit. The only workaround for this is to play with the unit's HP to create the illusion that you're changing how much damage is being dealt.

If you give an arbitrary unit the Hardened ability with the specifications you listed, you're right, the unit will not take damage. However, if you want a spell that negates the next several instances of damage (whether it be from a spell, or an attack) you need to modify the unit's HP rather than trying to add abilities that modify the amount of damage the unit should take.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
The way I see it, both method works, so why not take the simple way ?

For spells, you can use Spell Damage Reduction ability and set the Data - Damage Reduction to 1.00 (100%)

For next instances, you can use an indexing/hashtable method to save its current instance left bla bla

But the root to this problem is how to execute it in simple and short way, yet effective
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
But you've clearly misunderstood what I was just trying to explain...

Even if you customize a spell-damage-reduction ability, you cannot use it to negate single instances of damage. If you add the ability to the unit when the unit takes damage, the effect of the ability will not negate damage that has already been set into motion. If you are attacked by a Footman and add the damage reducing ability to the your unit, the damage dealt by the Footman will still be applied regardless of the fact that you've just added the ability.

I mean, I'm not absolutely positive you cannot get this to work (it could be my error) but you haven't even touched upon what I was saying.
 
Status
Not open for further replies.
Top