• 🏆 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!

[Spell] Elegant way to determine target abilities?

Status
Not open for further replies.
Level 12
Joined
May 16, 2020
Messages
660
Hi guys,

I'm trying to re-create Doom 's "Devour" ability from dota 2:
"Consumes an enemy or neutral creep, acquiring any special abilities that it possessed."

I have around 20 creeps in my map, each with their own abilities. To determine which ability I need to add to my hero upon devouring a unit, I would need to run a huge nested if function (if devoured unit = X, add ability X, else if devoured unit = Y, add abilly Y, etc...). But this is not very elegant nor efficient I'd say.

So my question: Is there a more elegant and efficient way to determine which ability I need to add based on which target is chosen to devour?

Cheers
 
Level 8
Joined
Jan 28, 2016
Messages
486
If it's just one ability per creep, then you could store the 20 unit-types into an array variable and the respective abilities into another array variables on map init.

When you cast your Devour spell, have a condition to check the unit-type of target unit and loop through all 20 unit-types in the array.

Once you get a match, add the corresponding ability (check out the spoiler; will probably make more sense).

  • Devour Setup
    • Events
    • Conditions
    • Actions
      • -------- --- --------
      • -------- Add all the creep unit types here --------
      • Set DevourCreepType[1] = Footman
      • Set DevourCreepType[2] = Rifleman
      • Set DevourCreepType[3] = Priest
      • -------- --- --------
      • -------- Add all the creep abilities here --------
      • Set DevourCreepAbility[1] = Ensnare
      • Set DevourCreepAbility[2] = Slow
      • Set DevourCreepAbility[3] = Heal
  • Devour Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Devour
    • Actions
      • -------- --- --------
      • -------- Loop through numbers 1 to 3 in this example --------
      • For each (Integer LoopInteger) from 1 to 3, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Target unit of ability being cast)) Equal to DevourCreepType[LoopInteger]
            • Then - Actions
              • -------- --- --------
              • -------- EXAMPLE --------
              • -------- Let's say you cast Devour on a Rifleman --------
              • -------- The loop will start at number 1 and check if target is a Footman --------
              • -------- It will fail (because it's a Rifleman, not a Footman) and do nothing --------
              • -------- At Number 2, the loop will check to see if target is a Rifleman --------
              • -------- Since the target is a Rifleman, the loop will add the Slow ability to the caster --------
              • -------- Because DevourCreepAbility[2] is set to Slow in the Devour Setup trigger --------
              • -------- --- --------
              • -------- NOTE: There is nothing to remove existing creep abilities from the caster in this example --------
              • -------- --- --------
              • Unit - Add DevourCreepAbility[LoopInteger] to (Triggering unit)
            • Else - Actions

This is very basic example of how to implement this loop method.

Again, this will only work with one ability per creep.

There would a few other things to consider; namely removing any existing creep ability and what happens when the hero with the Devour spell dies.

Hopefully this can get you started though.
 
Level 23
Joined
Jun 26, 2020
Messages
1,838
Is also possible do it with variables if the target units have more than 1 ability (I think 2 is the max.) for 2 abilities, you can asing like this
  • Set DevourCreepType[n]=Footman
  • Set DevourCreepType[2n-1]=Heal
  • Set DevourCreepType[2n]=Ensare
And change the @Dehua_Darbuya 's trigger adding
  • Unit - Add DevourCreepAbility[2*LoopInteger-1] to (Triggering unit)
  • Unit - Add DevourCreepAbility[2*LoopInteger] to (Triggering unit)
 
Level 12
Joined
May 16, 2020
Messages
660
Thanks a lot you two, this worked!:

  • Devour Config
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet Devour_UnitType[1] = Kobold Taskmaster
      • Set VariableSet Devour_UnitType[2] = Assassin
      • Set VariableSet Devour_UnitType[3] = Enforcer
      • Set VariableSet Devour_UnitType[4] = Mother Bear
      • Set VariableSet Devour_UnitType[5] = Moss Golem
      • Set VariableSet Devour_UnitType[6] = Alpha Wolf
      • Set VariableSet Devour_UnitType[7] = Furbolg Ursa Champion
      • Set VariableSet Devour_UnitType[8] = Crazed Hermit
      • Set VariableSet Devour_UnitType[9] = Spitting Spider
      • Set VariableSet Devour_UnitType[10] = Satyr Hellcaller
      • Set VariableSet Devour_UnitType[11] = Plague Treant
      • Set VariableSet Devour_UnitType[12] = Arachnathid Overlord
      • Set VariableSet Devour_UnitType[13] = Forest Troll Shadow Priest
      • Set VariableSet Devour_UnitType[14] = Ogre Lord
      • Set VariableSet Devour_UnitType[15] = Mud Golem
      • Set VariableSet Devour_Ability_A[1] = Speed Aura
      • Set VariableSet Devour_Ability_B[1] = Devour_Ability_B[0]
      • Set VariableSet Devour_Ability_A[2] = Envenomed Weapons (Neutral Hostile)
      • Set VariableSet Devour_Ability_B[2] = Devour_Ability_B[0]
      • Set VariableSet Devour_Ability_A[3] = Evasion (Neutral Hostile)
      • Set VariableSet Devour_Ability_B[3] = Devour_Ability_B[0]
      • Set VariableSet Devour_Ability_A[4] = Bash (Neutral Hostile 1)
      • Set VariableSet Devour_Ability_B[4] = Toughness Aura (Neutral Hostile)
      • Set VariableSet Devour_Ability_A[5] = Hurl Boulder
      • Set VariableSet Devour_Ability_B[5] = Spawn Shard Golem
      • Set VariableSet Devour_Ability_A[6] = Swiftness Aura
      • Set VariableSet Devour_Ability_B[6] = Critical Strike (Neutral Hostile)
      • Set VariableSet Devour_Ability_A[7] = Packleader's Aura
      • Set VariableSet Devour_Ability_B[7] = Thunder Clap (Neutral Hostile)
      • Set VariableSet Devour_Ability_A[8] = Purge (Neutral Hostile)
      • Set VariableSet Devour_Ability_B[8] = Devour_Ability_B[0]
      • Set VariableSet Devour_Ability_A[9] = Web (Neutral Hostile 2)
      • Set VariableSet Devour_Ability_B[9] = Devour_Ability_B[0]
      • Set VariableSet Devour_Ability_A[10] = Mana Burn (Neutral Hostile 1)
      • Set VariableSet Devour_Ability_B[10] = Devour_Ability_B[0]
      • Set VariableSet Devour_Ability_A[11] = Force of Nature (Neutral Hostile 1)
      • Set VariableSet Devour_Ability_B[11] = Spawn Corrupted Treant
      • Set VariableSet Devour_Ability_A[12] = Sand Wave
      • Set VariableSet Devour_Ability_B[12] = Devour_Ability_B[0]
      • Set VariableSet Devour_Ability_A[13] = Heal (Neutral Hostile 1)
      • Set VariableSet Devour_Ability_B[13] = Brilliance Aura (Neutral Hostile)
      • Set VariableSet Devour_Ability_A[14] = Cleaving Attack (Neutral Hostile)
      • Set VariableSet Devour_Ability_B[14] = Devour_Ability_B[0]
      • Set VariableSet Devour_Ability_A[15] = Shockwave (Neutral Hostile)
      • Set VariableSet Devour_Ability_B[15] = Earthmother Aura (Neutral Hostile)
  • Devour
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Devour
    • Actions
      • Set VariableSet Devour_Index = (Devour_Index + 1)
      • Set VariableSet Devour_Caster = (Triggering unit)
      • Set VariableSet Devour_Target = (Target unit of ability being cast)
      • Unit - Cause Devour_Caster to damage Devour_Target, dealing 10000000.00 damage of attack type Chaos and damage type Universal
      • Set VariableSet InfernalBlade_CV = (Custom value of Devour_Caster)
      • Set VariableSet Devour_UnitType[0] = (Unit-type of (Target unit of ability being cast))
      • Set VariableSet Devour_Counter[Devour_CV] = 70.00
      • Set VariableSet Devour_Heal[Devour_CV] = (-3.00 + (4.00 x (Real((Level of Devour for Devour_Caster)))))
      • Set VariableSet Devour_Gold[Devour_CV] = (50 x (Level of Devour for Devour_Caster))
      • Unit Group - Add Devour_Caster to Devour_Group
      • Special Effect - Destroy Devour_Specialeffect[Devour_CV]
      • Special Effect - Create a special effect attached to the origin of Devour_Caster using Abilities\Spells\Orc\LiquidFire\Liquidfire.mdl
      • Set VariableSet Devour_Specialeffect[Devour_CV] = (Last created special effect)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Devour_Boolean_Gold[Devour_CV] Equal to False
        • Then - Actions
          • Set VariableSet Devour_Boolean_Gold[Devour_CV] = True
        • Else - Actions
          • Player - Set (Owner of Devour_Caster).Current gold to (((Owner of Devour_Caster) Current gold) + Devour_Gold[Devour_CV])
          • Sound - Play AlchemistTransmuteDeath1 <gen> at 100.00% volume, attached to Devour_Caster
          • Floating Text - Create floating text that reads (+ + (String(Devour_Gold[Devour_CV]))) above Devour_Caster with Z offset 0.00, using font size 11.00, color (100.00%, 100.00%, 20.00%), and 0.00% transparency
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Set the velocity of (Last created floating text) to 48.00 towards 90.00 degrees
          • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
          • Floating Text - Change the fading age of (Last created floating text) to 2.50 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Devour_UnitType[0] Not equal to Devour_UnitType_Eaten[Devour_CV]
        • Then - Actions
          • -------- DEVOURS DIFFERENT UNIT (LANE CREEP OR NEUTRAL HOSTILE) --------
          • For each (Integer Devour_Integer) from 1 to 15, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Devour_UnitType[0] Equal to Devour_UnitType[Devour_Integer]
                • Then - Actions
                  • For each (Integer Devour_Integer) from 1 to 15, do (Actions)
                    • Loop - Actions
                      • Unit - Remove Devour_Ability_A[Devour_Integer] from Devour_Caster
                      • Unit - Remove Devour_Ability_B[Devour_Integer] from Devour_Caster
                • Else - Actions
                  • -------- NOTHING HAPPENS IF NOT DEFINED CREEP FROM LIST --------
          • For each (Integer Devour_Integer) from 1 to 15, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Devour_UnitType[0] Equal to Devour_UnitType[Devour_Integer]
                • Then - Actions
                  • Set VariableSet Devour_UnitType_Eaten[Devour_CV] = (Unit-type of (Target unit of ability being cast))
                  • Unit - Add Devour_Ability_A[Devour_Integer] to Devour_Caster
                  • Unit - Add Devour_Ability_B[Devour_Integer] to Devour_Caster
                • Else - Actions
                  • -------- NOTHING HAPPENS IF NOT DEFINED CREEP FROM LIST --------
        • Else - Actions
          • -------- NOTHING HAPPENS IF SAME UNIT TYPE DEVOURED --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Devour_Index Equal to 1
        • Then - Actions
          • Countdown Timer - Start Devour_Timer as a Repeating timer that will expire in 1.00 seconds
          • Trigger - Turn on Devour Loop <gen>
        • Else - Actions
  • Devour Loop
    • Events
      • Time - Devour_Timer expires
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Devour_Group and do (Actions)
        • Loop - Actions
          • Set VariableSet Devour_Caster = (Picked unit)
          • Set VariableSet InfernalBlade_CV = (Custom value of Devour_Caster)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Devour_Caster is alive) Equal to True
              • Devour_Counter[Devour_CV] Greater than 0.00
            • Then - Actions
              • Set VariableSet Devour_Counter[Devour_CV] = (Devour_Counter[Devour_CV] - 1.00)
              • Unit - Set life of Devour_Caster to ((Life of Devour_Caster) + Devour_Heal[Devour_CV])
            • Else - Actions
              • Player - Set (Owner of Devour_Caster).Current gold to (((Owner of Devour_Caster) Current gold) + Devour_Gold[Devour_CV])
              • Sound - Play AlchemistTransmuteDeath1 <gen> at 100.00% volume, attached to Devour_Caster
              • Floating Text - Create floating text that reads (+ + (String(Devour_Gold[Devour_CV]))) above Devour_Caster with Z offset 0.00, using font size 11.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
              • Floating Text - Change (Last created floating text): Disable permanence
              • Floating Text - Set the velocity of (Last created floating text) to 48.00 towards 90.00 degrees
              • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
              • Floating Text - Change the fading age of (Last created floating text) to 2.50 seconds
              • Special Effect - Destroy Devour_Specialeffect[Devour_CV]
              • Unit Group - Remove Devour_Target from Devour_Group.
              • Set VariableSet Devour_Index = (Devour_Index - 1)
              • Set VariableSet Devour_Boolean_Gold[Devour_CV] = False
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Devour_Index Equal to 0
        • Then - Actions
          • Countdown Timer - Pause Devour_Timer
          • Trigger - Turn off (This trigger)
          • Game - Display to (All players) the text: OFF
        • Else - Actions
 
Status
Not open for further replies.
Top