• 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.

[Solved] Detect and Remove unit group

Status
Not open for further replies.
I have created a altered blighted gold mine that uses dummies to harvest itself. That works fine, what doesn't is when I go to remove the dummies. I know that Locust units can't be detected via "units in range" and must be stored in a unit group.

How can I store them in a leak free way (this must function in a melee setting) so that when the mine dies I can detect units in that unit group in 512 range and "kill" them?
 
Create a local group for each mine and save it via hashtable (call SaveGroupHandle (udg_Hash, GetHandleId (udg_GoldMine), 0, g)). Create the dummies and add them to this group.

Then,
  • Tr
  • Events
    • Unit - A unit dies
  • Conditions
    • (Unit-type of (Triggering unit)) Equal to Gold Mine
  • Actions
    • Custom script: set udg_Id = GetHandleId (GetTriggerUnit())
    • Set Group = (Load 0 of Id from Hash)
    • Unit Group - Pick every unit in Group and do (Actions)
      • Loop - Actions
        • Unit - Kill (Picked unit)
        • Unit Group - Remove (Picked unit) from Group
    • Custom script: call DestroyGroup (udg_Group)
    • Hashtable - Clear all child hashtables of Id in Hash
 
I'm not sure how to go about the first part to be honest. How do I create a local for each instance? This is the opening trigger.

  • Consumed Mine Birth
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Consumed Mine
    • Actions
      • Hashtable - Create a hashtable
      • Set Consumed_Birth = (Position of (Triggering unit))
      • Unit - Create 3 Mine Tentacle for (Owner of (Triggering unit)) at Consumed_Birth facing Default building facing degrees
      • Set Consumed_Units = (Last created unit group)
      • Unit Group - Pick every unit in Consumed_Units and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Harvest (Triggering unit)
          • Animation - Play (Picked unit)'s birth animation
      • Custom script: call RemoveLocation(udg_Consumed_Birth)
      • Custom script: call DestroyGroup(udg_Consumed_Units)
 
The hashtable should be created in the map initialization:
  • Tr
  • Events
    • Map Initialization
  • Conditions
  • Actions
    • Hashtable - Create a hashtable
    • Set Hash = (Last created hashtable)
  • Consumed Mine Birth
  • Events
    • Unit - A unit Finishes construction
  • Conditions
    • (Unit-type of (Triggering unit)) Equal to Consumed Mine
  • Actions
    • Custom script: local group g = CreateGroup()
    • Custom script: set udg_Id = GetHandleId (GetTriggerUnit()) //udg_Id is an Integer variable
    • Custom script: call SaveGroupHandle (udg_Hash, udg_Id, 0, g)
    • Set Consumed_Birth = (Position of (Triggering unit))
    • For each (Integer A) from 1 to 3, do (Actions)
      • Loop - Actions
        • Unit - Create 1 Mine Tentacle for (Triggering player) at Consumed_Birth facing Default building facing degrees
        • Custom script: call GroupAddUnit (g, bj_lastCreatedUnit)
    • Custom script: call RemoveLocation (udg_Consumed_Birth)
 
  • Like
Reactions: Kam
Status
Not open for further replies.
Top