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

[Trigger] Unit Group & Heal Event help

Status
Not open for further replies.
Level 22
Joined
Jul 25, 2009
Messages
3,091
I'm using Bribe's healevent to detect when a unit gains health.

When the unit gains health and the conditions are true (the number of units in the unit group is less than the maximum number of units allowed, and the HP threshold for adding units back to the group has been crossed), a unit is added back to the group, which unit should be determined by

Set TempUnit2 = (Random unit from (Units in (Playable map area) matching ((((Matching unit) is in GMemberGroup[TempInt]) Equal to True) and (((Matching unit) is dead) Equal to True))))

However, it only finds one type of unit, and adds that type of unit to the squad, no matter how many other types of units are, both dead and in GMemberGroup (a group I add all squad members to when they are created)

  • Reinforcing Units
    • Events
      • Game - HealEvent becomes Equal to 1.00
      • Game - HealEvent becomes Equal to 0.50
    • Conditions
      • (Level of Squad Leader Attachment for heal_target) Greater than 0
    • Actions
      • Set TempInt = (Custom value of heal_target)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • GCurrentSquadSize[TempInt] Less than (Real(GCurrentMaxSize[TempInt]))
          • (Percentage life of GLeader[TempInt]) Greater than (GPercentage[TempInt] x (GCurrentSquadSize[TempInt] - 0.00))
        • Then - Actions
          • Set TempUnit2 = (Random unit from (Units in (Playable map area) matching ((((Matching unit) is in GMemberGroup[TempInt]) Equal to True) and (((Matching unit) is dead) Equal to True))))
          • Unit Group - Remove TempUnit2 from GMemberGroup[TempInt]
          • Set GPoint[1] = (Position of heal_target)
          • Set tempLoc2 = (GPoint[1] offset by 160.00 towards (72.00 x (Real(GInt))) degrees)
          • Unit - Create 1 Locust Dummy for (Owner of heal_target) at tempLoc2 facing (Facing of heal_target) degrees
          • Unit - Add Locust Switcher to (Last created unit)
          • Custom script: call UnitAddAbility(GetLastCreatedUnit(),'Aloc')
          • Custom script: call UnitRemoveAbility(GetLastCreatedUnit(),'Aloc')
          • Unit - Set level of Locust Switcher for (Last created unit) to (Point-value of (Unit-type of TempUnit2))
          • AI - Ignore (Last created unit)'s guard position
          • Unit - Set the custom value of (Last created unit) to TempInt
          • Special Effect - Create a special effect at tempLoc2 using Abilities\Spells\Items\AIlm\AIlmTarget.mdl
          • Special Effect - Destroy (Last created special effect)
          • Unit - Disable supply usage for (Last created unit)
          • Set GCurrentSquadSize[TempInt] = (GCurrentSquadSize[TempInt] + 1.00)
          • Custom script: call RemoveLocation(udg_GPoint[1])
          • Custom script: call RemoveLocation(udg_tempLoc2)
        • Else - Actions
 
Level 22
Joined
Jul 25, 2009
Messages
3,091
I think the answer lies in GMemberGroup. Can you show that trigger, too?

The problem is indeed with that group however there is very little room for error in the trigger that adds units to their respective groups.

It's literally just, unit enters map, add unit to group[custom value triggering unit], and I use your indexer to assign custom values in a separate trigger.

All I'm trying to do is make a squad system be able to contain multiple different unit types and reinforce them intelligently, without using a wall of if-then checks to see which unit needs reinforced.

So what's required is a way to find the unit types of dead squad members so they can be recreated when this trigger fires.

To clarify any confusion on how I create units, I spawn a dummy, then add chaos to it, change the level of chaos to correspond with the point value of the unit, which corresponds with a table of all stored data, unit type etc. Combined with add/remove aloc this make units unselectable while maintaining all their basic functions, moving, following commands, being targetable etc.
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
I'm sorry, I'm a little confused with the triggers, I need some explanations:

  • a unit is added back to the group
    ^I don't see you adding any units anywhere in this trigger? Just a Unit Group - Remove Unit function
  • it only finds one type of unit
    ^You currently only have TempUnit2 set to "Random 1 unit"

  • How are you creating the UnitGroup[] variables? I've been told that WC3 acts a little funny with unit group variables that are arrays. In the past, I've had to initialize them manually via:
    JASS:
    if udg_UnitGroup[udg_Index] == null then
        set udg_UnitGroup[udg_Index] = CreateGroup()
    endif
 
Level 22
Joined
Jul 25, 2009
Messages
3,091
I'm sorry, I'm a little confused with the triggers, I need some explanations:


  • ^I don't see you adding any units anywhere in this trigger? Just a Unit Group - Remove Unit function

  • ^You currently only have TempUnit2 set to "Random 1 unit"

  • How are you creating the UnitGroup[] variables? I've been told that WC3 acts a little funny with unit group variables that are arrays. In the past, I've had to initialize them manually via:
    JASS:
    if udg_UnitGroup[udg_Index] == null then
        set udg_UnitGroup[udg_Index] = CreateGroup()
    endif

Take a squad system

The HP for all members of a squad is intertwined using Bribe's DDS and Bribe's HealEvent.

When the HP of the squad leader drops below X, we remove a squad member, when the HP of the squad leader goes above X, we add a member back to the squad.

The problem is that "TempUnit2" only picks 1 unit type, no matter how many times this fires, it picks the same unit type out of the group when there could be 5 or really any number of different unit types in a squad/GMemberGroup but for some reason it only detects one unit type and that is the only unit type that gets created through this trigger.

Are you initializing the group for each unit?

I'm not sure what you mean?
 
Level 22
Joined
Jul 25, 2009
Messages
3,091
How I add units to groups (I have done this multiple different ways to see if the way I'm adding units, which have chaos/are locusts to a group might be faulty, however every single way I've added units to GMemberGroup it has detected them, but when I reference them in the reinforcing trigger with TempUnit2, it only seems to snag 1 specific unit type.)

  • Add Units to Group
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
    • Actions
      • Set TempInt = (Custom value of (Picked unit))
      • Unit Group - Add (Picked unit) to GMemberGroup[TempInt]
Misc, setup for squads

  • Squad Setups
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • -------- Chaos Marauders --------
      • Set GLeaderIsDifferent[1] = False
      • Set GLeaderUnitType[1] = Chaos Marauder
      • Set GBonusTroopType01[1] = No unit-type
      • Set GRealMaxSize[1] = 6
      • Set GCurrentMaxSize[1] = 6
      • Set GSpecialWeaponType01[1] = (Item-type of No item)
      • Set GBonusMemberType01[1] = (Item-type of No item)
      • Set GMoraleDamageAmount[1] = 1
      • -------- Chaos Warriors --------
      • Set GLeaderIsDifferent[2] = False
      • Set GLeaderUnitType[2] = Chaos Warrior
      • Set GBonusTroopType01[2] = (Unit-type of No unit)
      • Set GRealMaxSize[2] = 3
      • Set GCurrentMaxSize[2] = 3
      • Set GSpecialWeaponType01[2] = (Item-type of No item)
      • Set GBonusMemberType01[2] = (Item-type of No item)
      • Set GMoraleDamageAmount[2] = 20
      • -------- Chaos Warhounds --------
      • Set GLeaderIsDifferent[3] = False
      • Set GLeaderUnitType[3] = Chaos Warhound
      • Set GBonusTroopType01[3] = (Unit-type of No unit)
      • Set GRealMaxSize[3] = 3
      • Set GCurrentMaxSize[3] = 3
      • Set GSpecialWeaponType01[3] = (Item-type of No item)
      • Set GBonusMemberType01[3] = (Item-type of No item)
      • Set GMoraleDamageAmount[3] = 1
Misc, removing units via your DDS

  • Removing Units
    • Events
      • Game - DamageModifierEvent becomes Equal to 1.00
    • Conditions
    • Actions
      • Set TempUnit = GLeader[(Custom value of DamageEventTarget)]
      • Set TempInt = (Custom value of DamageEventTarget)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Percentage life of GLeader[TempInt]) Less than or equal to (GPercentage[TempInt] x (GCurrentSquadSize[TempInt] - 1.00))
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Warp Jump for DamageEventTarget) Equal to 0
            • Then - Actions
              • Unit - Kill DamageEventTarget
              • Set GCurrentSquadSize[TempInt] = (GCurrentSquadSize[TempInt] - 1.00)
            • Else - Actions
              • Set TempGroup2 = (Units in (Playable map area) matching ((TempInt Equal to (Custom value of (Matching unit))) and ((((Matching unit) is dead) Equal to False) and (TempUnit Not equal to (Matching unit)))))
              • Set TempUnit2 = (Random unit from TempGroup2)
              • Unit - Kill TempUnit2
              • Set GCurrentSquadSize[TempInt] = (GCurrentSquadSize[TempInt] - 1.00)
              • Custom script: call DestroyGroup(udg_TempGroup2)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Warp Jump for DamageEventTarget) Equal to 0
            • Then - Actions
              • Unit - Cause DamageEventSource to damage TempUnit, dealing DamageEventAmount damage of attack type Pierce and damage type Normal
            • Else - Actions
Misc, reinforcing units via your Heal Event

  • Reinforcing Units
    • Events
      • Game - HealEvent becomes Equal to 1.00
      • Game - HealEvent becomes Equal to 0.50
    • Conditions
      • (Level of Warp Jump for heal_target) Greater than 0
    • Actions
      • Set TempInt = (Custom value of heal_target)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • GCurrentSquadSize[TempInt] Less than (Real(GCurrentMaxSize[TempInt]))
          • (Percentage life of GLeader[TempInt]) Greater than (GPercentage[TempInt] x (GCurrentSquadSize[TempInt] - 0.00))
        • Then - Actions
          • Set TempUnit2 = (Random unit from (Units in (Playable map area) matching ((((Matching unit) is in GMemberGroup[TempInt]) Equal to True) and (((Matching unit) is dead) Equal to True))))
          • Unit Group - Remove TempUnit2 from GMemberGroup[TempInt]
          • Set GPoint[1] = (Position of heal_target)
          • Set tempLoc2 = (GPoint[1] offset by 160.00 towards (72.00 x (Real(GInt))) degrees)
          • Unit - Create 1 LocustDummy for (Owner of heal_target) at tempLoc2 facing (Facing of heal_target) degrees
          • Unit - Add Locust Switcher to (Last created unit)
          • Custom script: call UnitAddAbility(GetLastCreatedUnit(),'Aloc')
          • Custom script: call UnitRemoveAbility(GetLastCreatedUnit(),'Aloc')
          • Unit - Set level of Locust Switcher for (Last created unit) to (Point-value of (Unit-type of TempUnit2))
          • AI - Ignore (Last created unit)'s guard position
          • Unit - Set the custom value of (Last created unit) to TempInt
          • Special Effect - Create a special effect at tempLoc2 using Abilities\Spells\Items\AIlm\AIlmTarget.mdl
          • Special Effect - Destroy (Last created special effect)
          • Unit - Disable supply usage for (Last created unit)
          • Set GCurrentSquadSize[TempInt] = (GCurrentSquadSize[TempInt] + 1.00)
          • Custom script: call RemoveLocation(udg_GPoint[1])
          • Custom script: call RemoveLocation(udg_tempLoc2)
        • Else - Actions
All tied together with your indexer.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
As I thought, you never initialized the group. The first trigger should, instead, be this:

  • Add Units to Group
    • Events
      • Game - UnitIndexEvent becomes Equal to 1.00 //this is the same as "unit enters map" as you have UnitIndexer already
    • Conditions
    • Actions
      • Custom script: set udg_GMemberGroup[udg_UDex] = CreateGroup()
      • Unit Group - Add (Picked unit) to GMemberGroup[UDex] //Use UDex as it is already set to the custom value with this event
And another one for when the unit is removed:

  • Remove units from group
    • Events
      • Game - UnitIndexEvent becomes Equal to 2.00
    • Conditions
    • Actions
      • Custom script: call DestroyGroup(udg_GMemberGroup[udg_UDex])
 
Level 22
Joined
Jul 25, 2009
Messages
3,091
As I thought, you never initialized the group. The first trigger should, instead, be this:

  • Add Units to Group
    • Events
      • Game - UnitIndexEvent becomes Equal to 1.00 //this is the same as "unit enters map" as you have UnitIndexer already
    • Conditions
    • Actions
      • Custom script: set udg_GMemberGroup[udg_UDex] = CreateGroup()
      • Unit Group - Add (Picked unit) to GMemberGroup[UDex] //Use UDex as it is already set to the custom value with this event
And another one for when the unit is removed:

  • Remove units from group
    • Events
      • Game - UnitIndexEvent becomes Equal to 2.00
    • Conditions
    • Actions
      • Custom script: call DestroyGroup(udg_GMemberGroup[udg_UDex])

This did not fix the issue.

Here's what happens.

A squad is 7 units, 5 storm troopers, 1 vox oculi, 1 commandant.

The commandant is the leader of the squad, so we ignore him in the squad calculations all together.

Kill all 5 storm troopers and the 1 vox oculi, then bring the commandant to a fountain to heal, heal event fires and reinforces the members of the squad, it should add the 5 storm troopers and 1 vox oculi, but it doesn't, it adds 6 storm troopers.

TempUnit2 should get the dead units and recreate them when heal event fires, and it does get the dead units, but for some reason it only gets storm troopers.

So when the squad is full, it'll be 7/7, 7 living members, 7 maximum, and it's this way when they spawn and after they're reinforced, the difference is, when they spawn, you've got 1 vox 5 storms and 1 commandant, after the vox oculi dies and you reinforce a squad, that vox oculi is now replaced with a storm trooper.

Hopefully this will help add context to the issue.
 
Level 22
Joined
Jul 25, 2009
Messages
3,091
I made a check using game text to see if this trigger is firing, and it's not, on any units.

  • Add Units to Group
    • Events
      • Game - UnitIndexEvent becomes Equal to 1.00
    • Conditions
    • Actions
      • Custom script: set udg_GMemberGroup[udg_UDex] = CreateGroup()
      • Game - Display to (All players) the text: (Name of (Picked unit))
      • Unit Group - Add (Picked unit) to GMemberGroup[UDex]
 
Level 22
Joined
Jul 25, 2009
Messages
3,091
Ignore everything up until this point; I discovered the problem.

I made a trigger that adds units to their GMemberGroup[UDex] and then displays the names of the units added, simply to check if they're added properly.

When they get added the names show up like so

Commandant
Kriegsguard
Locust Dummy
Locust Dummy
Locust Dummy
Locust Dummy
Locust Dummy

For some reason it only recognizes 1 Kriegsguard when a squad spawns (something to do with Chaos)

The point value of a Locust Dummy is 1, the point value of a Kriegsguard is also 1, so every time it finds a random unit from GMemberGroup (TempUnit2, in the first trigger I posted), it's finding a Locust Dummy with a point value of 1 and creating a unit from my setup table which is [1], which is a Kriegsguard.

ex.jpg


Chaos is not detected on all of the units

How do I solve this?
 
Last edited by a moderator:
Level 22
Joined
Jul 25, 2009
Messages
3,091
Please don't post consecutively so quickly.

I don't know the specifics, but could it be that the unit spawns as a different type before transforming into the battle guard?

If you read the triggers I posted above about /creating units/ or even read the original trigger I posted; I create a locust -> then add chaos -> then change the level of chaos.

I posted twice in the span of 24 hours, if I recall correctly that's the acceptable span of time for a single "bump."
 
Status
Not open for further replies.
Top