• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] Missile heal on death

Status
Not open for further replies.
Level 40
Joined
Feb 27, 2007
Messages
5,087
Despite this seeming simple, the necessary approach is actually a little complicated. Why? Because Firebolt has a travel time (doesn't damage instantly), and there is no native wc3 way to tell which ability or attack caused damage. Which unit caused damage isn't hard, but knowing what it did to cause that damage is literally impossible without a workaround in advance. The workaround one uses is to create a dummy unit and cause that unit to cast a special version of Firebolt; when a unit dies and the killing unit had this firebolt spell you can be certain it was a dummy caster that killed the target and therefore the kill was due to the Firebolt spell (since the dummy caster could never otherwise kill anything).

In your case it's a little more complicated because in addition to knowing if the kill was due to Firebolt you also need to know who the original caster was in order to heal them. (The original caster won't get kill credit on the score screen, either, though they will get kill gold and xp as long as the dummy caster that gets the kill is owned by them. It's possible to get around this with a damage detection system but that just makes all of this more complicated.) You'll need to store the caster and the dummy caster in a pair of parallel unit arrays so you can 'store' the caster's data along with the dummy. You could also do this with a Hashtable but understanding how that works is a little bit more complicated.
  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
    • (Ability being cast) equal to HERO_ABILITY_THAT_DOES_NOTHING_BUT_SET_A_UNIT_TARGET
  • Actions
    • Set TempPoint = (Position of (Triggering Unit))
    • Unit - Create 1 DUMMY_CASTER for (Owner of (Triggering Unit)) at TempPoint facing Default Building Facing degrees
    • Unit - Add a 2.00 second generic expiration timer to (Last created unit) //make this long enough that the dummy is definitely alive after a max travel time firebolt
    • Unit - Add DUMMY_FIREBOLT_ABILITY to (Last created unit)
    • Unit - Set level of DUMMY_FIREBOLT_ABILITY for (Last created unit) to (Level of (Ability being cast) for (Triggering Unit))
    • Unit - Order (Last created unit) to (Neutral Ogre Magi - Firebolt) (Target unit of ability being cast) //honestly I don't remember what the firebolt order is, but use that here
    • Set FB_CasterCount = (FB_CasterCount + 1)
    • Set FB_Dummy[FB_CasterCount] = (Last created unit)
    • Set FB_Caster[FB_CasterCount] = (Triggering Unit)
  • Events
    • Unit - A unit dies
  • Conditions
    • (Level of DUMMY_FIREBOLT_ABILITY for (Killing Unit)) Greater than 0
  • Actions
    • For each (Integer A) from 1 to FB_CasterCount do (Actions)
      • Loop - Actions
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • FB_Dummy[(Integer A)] equal to (Killing Unit)
          • Then - Actions
            • Set FB_TempInt = (Integer A)
            • Custom script: exitwhen true
          • Else - Actions
    • Unit - Set life of FB_Caster[FB_TempInt] to ((Life of FB_Caster[FB_TempInt]) + (5.00 x (Real((Level of HERO_ABILITY_THAT_DOES_NOTHING_BUT_SET_A_UNIT_TARGET for FB_Caster[FB_TempInt]))))) //do whatever healing you want here, howevver it should occur (you can dummy cast a healing spell on the caster if that's what you'd prefer)
  • Events
    • Unit - A unit dies
  • Conditions
    • (Level of DUMMY_FIREBOLT_ABILITY for (Triggering Unit)) Greater than 0
  • Actions
    • For each (Integer A) from 1 to FB_CasterCount do (Actions)
      • Loop - Actions
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • FB_Dummy[(Integer A)] equal to (Triggering Unit)
          • Then - Actions
            • Set FB_TempInt = (Integer A)
            • Set FB_Caster[FB_TempInt] = FB_Caster[FB_CasterCount]
            • Set FB_Dummy[FB_TempInt] = FB_Dummy[FB_CasterCount]
            • Set FB_CasterCount = (FB_CasterCount - 1) //this process is called "dynamic indexing"; if you want to look it up there's a good tutorial here
          • Else - Actions
 
Level 5
Joined
Sep 30, 2017
Messages
54
Despite this seeming simple, the necessary approach is actually a little complicated. Why? Because Firebolt has a travel time (doesn't damage instantly), and there is no native wc3 way to tell which ability or attack caused damage. Which unit caused damage isn't hard, but knowing what it did to cause that damage is literally impossible without a workaround in advance. The workaround one uses is to create a dummy unit and cause that unit to cast a special version of Firebolt; when a unit dies and the killing unit had this firebolt spell you can be certain it was a dummy caster that killed the target and therefore the kill was due to the Firebolt spell (since the dummy caster could never otherwise kill anything).

In your case it's a little more complicated because in addition to knowing if the kill was due to Firebolt you also need to know who the original caster was in order to heal them. (The original caster won't get kill credit on the score screen, either, though they will get kill gold and xp as long as the dummy caster that gets the kill is owned by them. It's possible to get around this with a damage detection system but that just makes all of this more complicated.) You'll need to store the caster and the dummy caster in a pair of parallel unit arrays so you can 'store' the caster's data along with the dummy. You could also do this with a Hashtable but understanding how that works is a little bit more complicated.
  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
    • (Ability being cast) equal to HERO_ABILITY_THAT_DOES_NOTHING_BUT_SET_A_UNIT_TARGET
  • Actions
    • Set TempPoint = (Position of (Triggering Unit))
    • Unit - Create 1 DUMMY_CASTER for (Owner of (Triggering Unit)) at TempPoint facing Default Building Facing degrees
    • Unit - Add a 2.00 second generic expiration timer to (Last created unit) //make this long enough that the dummy is definitely alive after a max travel time firebolt
    • Unit - Add DUMMY_FIREBOLT_ABILITY to (Last created unit)
    • Unit - Set level of DUMMY_FIREBOLT_ABILITY for (Last created unit) to (Level of (Ability being cast) for (Triggering Unit))
    • Unit - Order (Last created unit) to (Neutral Ogre Magi - Firebolt) (Target unit of ability being cast) //honestly I don't remember what the firebolt order is, but use that here
    • Set FB_CasterCount = (FB_CasterCount + 1)
    • Set FB_Dummy[FB_CasterCount] = (Last created unit)
    • Set FB_Caster[FB_CasterCount] = (Triggering Unit)
  • Events
    • Unit - A unit dies
  • Conditions
    • (Level of DUMMY_FIREBOLT_ABILITY for (Killing Unit)) Greater than 0
  • Actions
    • For each (Integer A) from 1 to FB_CasterCount do (Actions)
      • Loop - Actions
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • FB_Dummy[(Integer A)] equal to (Killing Unit)
          • Then - Actions
            • Set FB_TempInt = (Integer A)
            • Custom script: exitwhen true
          • Else - Actions
    • Unit - Set life of FB_Caster[FB_TempInt] to ((Life of FB_Caster[FB_TempInt]) + (5.00 x (Real((Level of HERO_ABILITY_THAT_DOES_NOTHING_BUT_SET_A_UNIT_TARGET for FB_Caster[FB_TempInt]))))) //do whatever healing you want here, howevver it should occur (you can dummy cast a healing spell on the caster if that's what you'd prefer)
  • Events
    • Unit - A unit dies
  • Conditions
    • (Level of DUMMY_FIREBOLT_ABILITY for (Triggering Unit)) Greater than 0
  • Actions
    • For each (Integer A) from 1 to FB_CasterCount do (Actions)
      • Loop - Actions
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • FB_Dummy[(Integer A)] equal to (Triggering Unit)
          • Then - Actions
            • Set FB_TempInt = (Integer A)
            • Set FB_Caster[FB_TempInt] = FB_Caster[FB_CasterCount]
            • Set FB_Dummy[FB_TempInt] = FB_Dummy[FB_CasterCount]
            • Set FB_CasterCount = (FB_CasterCount - 1) //this process is called "dynamic indexing"; if you want to look it up there's a good tutorial here
          • Else - Actions
Wow. This seem way more complicated then I thought! Still thank you for the reply.
 
Status
Not open for further replies.
Top