• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

I need to know what goes wrong with this spell

Status
Not open for further replies.
Level 4
Joined
May 12, 2022
Messages
22
Hello, I am trying to create a spell for a unit (Sorceress). I want the Sorceress unit to respect the following conditions:
  • cast the default slow ability on a random enemy unit in 1000 range from Sorceress
  • this should trigger only after the Sorceress has damaged an enemy unit
  • the random enemy unit doesn't already have the slow buff.
  • don't use unit groups

  • Sorceress
    • Events
      • Unit - A unit Takes damage
    • Conditions
      • (Unit-type of (Damage source)) Equal to Sorceress
    • Actions
      • Set VariableSet Unit1Sorceress = (Random unit from (Units within 1000.00 of (Position of (Damage source)).))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit1Sorceress has buff Slow) Equal to False
          • ((Damage source) belongs to an enemy of (Owner of Unit1Sorceress).) Equal to True
        • Then - Actions
          • Unit - Order (Damage source) to Human Sorceress - Slow Unit1Sorceress
        • Else - Actions
I can see the problems but I don't know how to fix them. The variable can choose the same unit that already has the buff or even an allied unit or itself.

So I tried to change the variable to this:

  • Set VariableSet Unit1Sorceress = (Random unit from (Units within 1000.00 of (Position of (Damage source)) matching ((Unit1Sorceress belongs to an enemy of (Owner of (Damage source)).) Equal to True).))
But it doesn't work as it specifies "Unit1Sorceress" in the same variable "Unit1Sorceress" (I think this is the problem at least)
I don't know how else I could have the variable target only enemies of the Sorceress.

Does anyone know a way? Except using unit groups.

Thank you!
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
You have to use Unit Groups, in fact, you're already using a Unit Group:
  • (Random unit from (Units within 1000.00 of (Position of (Damage source)).))
^ That's creating a Unit Group of all units within 1000.00 range of the Sorceress. It's then getting a random unit from that Unit Group.

Also, you need to use the Event Response (Matching unit) when filtering units during the creation of a Unit Group:
  • Set VariableSet Unit1Sorceress = (Random unit from (Units within 1000.00 of (Position of (Damage source)) matching (((Matching unit) belongs to an enemy of (Owner of (Damage source)).) Equal to True).))
Unit1Sorceress hasn't been Set yet so referencing it after "matching" doesn't make sense.

What you need to do is filter your Unit Group to get rid of unwanted targets:
  • Sorc Slow
    • Events
      • Unit - A unit Takes damage
    • Conditions
      • (Unit-type of (Damage source)) Equal to Sorceress
    • Actions
      • Set VariableSet Source = (Damage source)
      • -------- --------
      • -------- Create our Unit Group: --------
      • Set VariableSet Point = (Position of Source)
      • Set VariableSet Group = (Units within 1000.00 of Point.)
      • -------- --------
      • -------- Filter out unwanted targets (dead, has buff, etc): --------
      • Set VariableSet Found_A_Target = False
      • Unit Group - Pick every unit in Group and do (Actions)
        • Loop - Actions
          • Set VariableSet Target = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Target belongs to an enemy of (Owner of Source).) Equal to True
              • (Target is alive) Equal to True
              • (Target has buff Slow) Equal to False
              • (Target is A structure) Equal to False
              • (Target is Magic Immune) Equal to False
              • (Target is Mechanical) Equal to False
              • (Target is invulnerable) Equal to False
            • Then - Actions
              • -------- We found at least one valid target, let's remember this for later on: --------
              • Set VariableSet Found_A_Target = True
            • Else - Actions
              • -------- It's untargetable, remove it from this group! --------
              • Unit Group - Remove Target from Group.
      • -------- --------
      • -------- If there's at least 1 valid target then let's proceed to try and slow one at random: --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Found_A_Target Equal to True
        • Then - Actions
          • Set VariableSet Target = (Random unit from Group)
          • Unit - Order Source to Human Sorceress - Slow Target
        • Else - Actions
      • -------- --------
      • -------- Clean up the memory leaks (optional): --------
      • Custom script: call RemoveLocation( udg_Point )
      • Custom script: call DestroyGroup( udg_Group )
1) I filter the Unit Group by using a Pick Every Unit action and an If Then Else action which makes it easier to manage and customize.

2) I control whether we tell the Sorceress to do anything with the Found_A_Target boolean variable. This way it only issues the order if we know for certain that there's a valid target nearby.

3) I use variables for the Source and Target to make things more efficient. Using an Event Response is actually a function call that returns you a global variable, so we can skip that step and reference the global variable directly.

4) Lastly, I clean up the memory leaks to help keep the map running smoothly over time.
 

Attachments

  • Sorc Slow.w3m
    19.3 KB · Views: 3
Last edited:
Status
Not open for further replies.
Top