[Trigger] Help with Footman into Captain Trigger?

Level 14
Joined
May 9, 2021
Messages
263
Hello.

I am trying to make this Trigger work, but I'm obviously doing something wrong.

The Trigger is supposed to detect every Footman owned by all Players of the same Force (allied), pick one Footman and turn it into a Captain, and then turn that Captain back into a Footman after a duration and restart the whole thing again.

However, currently, it is not doing anything...

Here is the Trigger:

Untitled.png


The variables are:

  • Footman_TempGroup (unit group, contains all the Footmen matching the conditions).
  • MaxMana (real, detects the Mana of all Footmen (I think...?))
  • Captain (Unit, sets the Captain)
  • Captain_Duration (Timer Array(1), sets the duration)

Help with this would be appreciated. I am not good with Triggers (I was helped with this Trigger on another thread).
 
Level 21
Joined
Mar 16, 2008
Messages
955
Maybe try something like this. I haven't tested and there might be a better way. But I think this is better than your current trigger:

  • initiate
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet captin_unit_var = Captain 0000 <gen>
  • captain dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Captain
    • Actions
      • Set VariableSet red_units = (Units owned by Player 1 (Red) of type Footman)
      • Set VariableSet red_units = (Random 1 units from red_units)
      • Unit Group - Pick every unit in red_units and do (Actions)
        • Loop - Actions
          • Unit - Replace (Picked unit) with a Captain using The old unit's relative life and mana
          • Set VariableSet captin_unit_var = (Last replaced unit)
I was thinking also add a timer if a footman wasn't found to check again in a few sec. So this system will fall apart if there are no footmen. But just wanted to give you something to work with.
 

Attachments

  • captain replacement test.w3m
    13.3 KB · Views: 3
Level 14
Joined
May 9, 2021
Messages
263
Maybe try something like this. I haven't tested and there might be a better way. But I think this is better than your current trigger:

  • initiate
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet captin_unit_var = Captain 0000 <gen>
  • captain dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Captain
    • Actions
      • Set VariableSet red_units = (Units owned by Player 1 (Red) of type Footman)
      • Set VariableSet red_units = (Random 1 units from red_units)
      • Unit Group - Pick every unit in red_units and do (Actions)
        • Loop - Actions
          • Unit - Replace (Picked unit) with a Captain using The old unit's relative life and mana
          • Set VariableSet captin_unit_var = (Last replaced unit)
I was thinking also add a timer if a footman wasn't found to check again in a few sec. So this system will fall apart if there are no footmen. But just wanted to give you something to work with.
Hey, I can't open the test map (not my version).
 
Level 29
Joined
Sep 26, 2009
Messages
2,594
Your trigger in the original post:
1. In the condition "(Percentage mana of (Picked unit)) Greater than or equal to MaxMana"
  • Which unit is (Picked unit)?
  • What is the amount of MaxMana? Don't forget you are comparing percentage of unit's mana, not its current value. MaxMana should therefore be 100.00, but then again, why hide such constant behind variable?

2. You then reset mana to zero, so basically any unit should be available for being promoted to Captain.

3. What is the unit group supposed to do? It's "Loop - Actions" block is empty. Is it a wonder that the trigger does nothing? :D
* Also, you leak the unit group here. While you do assign it to variable, you do not clear it afterwards.

4. What is the "Else" block of the "If/Then/Else" even supposed to do? Your logic now is:
"If percentage of picked unit is >= MaxMana, then do something, otherwise do the exact same check, that is 'If percentage of picked unit is >= MaxMana', and if true, do something else"

5. As for the nested If/Then/Else, it suffers from same problem: Who is (Picked unit)?
 
Level 14
Joined
May 9, 2021
Messages
263
Your trigger in the original post:
1. In the condition "(Percentage mana of (Picked unit)) Greater than or equal to MaxMana"
  • Which unit is (Picked unit)?
  • What is the amount of MaxMana? Don't forget you are comparing percentage of unit's mana, not its current value. MaxMana should therefore be 100.00, but then again, why hide such constant behind variable?

2. You then reset mana to zero, so basically any unit should be available for being promoted to Captain.

3. What is the unit group supposed to do? It's "Loop - Actions" block is empty. Is it a wonder that the trigger does nothing? :D
* Also, you leak the unit group here. While you do assign it to variable, you do not clear it afterwards.

4. What is the "Else" block of the "If/Then/Else" even supposed to do? Your logic now is:
"If percentage of picked unit is >= MaxMana, then do something, otherwise do the exact same check, that is 'If percentage of picked unit is >= MaxMana', and if true, do something else"

5. As for the nested If/Then/Else, it suffers from same problem: Who is (Picked unit)?
Yes I'm starting to understand that there are a number of problems... It all made sense at the time...

Just try to recreate the trigger on your version. Re-creating the trigger will be good practice to learn more about triggers. Just read the triggers line by line and think about what it will do.
I did recreate the Trigger (I've still got the map)... Though I ran into a problem setting "Captin_Var" as "Last Replaced Unit". Such an option was not available using Unit Group variable, and using Unit Variable, Captin_Var doesn't show up at all...
 
Level 21
Joined
Mar 16, 2008
Messages
955
Come to think of it, you don't actually need the variables. You can just reference the unit-type. I can post an update like this if you want but I think you could just ignore all the variable part actually.

  • captain dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Captain
    • Actions
      • Set VariableSet red_units = (Units owned by Player 1 (Red) of type Footman)
      • Set VariableSet red_units = (Random 1 units from red_units)
      • Unit Group - Pick every unit in red_units and do (Actions)
        • Loop - Actions
          • Unit - Replace (Picked unit) with a Captain using The old unit's relative life and mana
red_units will leak so maybe make two separate group variables then clear the leaks at the end.
 
Last edited:
Level 14
Joined
May 9, 2021
Messages
263
Come to think of it, you don't actually need the variables. You can just reference the unit-type. I can post an update like this if you want but I think you could just ignore all the variable part actually.

  • captain dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Captain
    • Actions
      • Set VariableSet red_units = (Units owned by Player 1 (Red) of type Footman)
      • Set VariableSet red_units = (Random 1 units from red_units)
      • Unit Group - Pick every unit in red_units and do (Actions)
        • Loop - Actions
          • Unit - Replace (Picked unit) with a Captain using The old unit's relative life and mana
Thank you SO much!!! This was killing me!

I'll figure out the rest.

Thank you again!
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Remember, you don't want to use a Unit Group when trying to get ONE random unit. When interacting with a single Unit you would rely on a Unit variable:
  • captain dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Captain
    • Actions
      • Set VariableSet footman_group = (Units owned by Player 1 (Red) matching (Unit-type of (Matching unit)) Equal to Footman) and ((Matching unit) is Alive Equal to True))
      • Set VariableSet random_footman = (Random unit from footman_group)
      • Unit - Replace random_footman with a Captain using The old unit's relative life and mana
      • Custom script: call DestroyGroup(udg_footman_group)
^ So with that in mind we can use the random_footman Unit variable to get our random footman. I also adjusted the footman_group Unit Group to require that the footman is alive (dead units get added to Unit Groups as well). You'll probably want to customize this further with more Conditions. Lastly, I addressed the memory leak that comes with setting a Unit Group variable. This is optional and won't change the outcome of the trigger.
 
Last edited:
Level 14
Joined
May 9, 2021
Messages
263
Remember, you don't want to use a Unit Group when trying to get ONE random unit. When interacting with a single Unit you would rely on a Unit variable:
  • captain dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Captain
    • Actions
      • Set VariableSet footman_group = (Units owned by Player 1 (Red) matching (Unit-type of (Matching unit)) Equal to Footman) and ((Matching unit) is Alive Equal to True))
      • Set VariableSet random_footman = (Random unit from footman_group)
      • Unit - Replace random_footman with a Captain using The old unit's relative life and mana
      • Custom script: call DestroyGroup(udg_footman_group)
^ So with that in mind we can use the random_footman Unit variable to get our random footman. I also adjusted the footman_group Unit Group to require that the footman is alive (dead units get added to Unit Groups as well). You'll probably want to customize this further with more Conditions. Lastly, I addressed the memory leak that comes with setting a Unit Group variable. This is optional and won't change the outcome of the trigger.
Okay, I'll do that, thanks.

Just a question. Whenever I attempt to use Custom Scripts, it disables the Trigger. Why is this?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Okay, I'll do that, thanks.

Just a question. Whenever I attempt to use Custom Scripts, it disables the Trigger. Why is this?
You need to enable JassHelper, you'll see it in one of the tabs at the top of the Trigger Editor. Also, custom script is case sensitive and will throw an error if it doesn't match perfectly.
 
Top