1. Find your way through the deepest dungeon in the 18th Mini Mapping Contest Poll.
    Dismiss Notice
  2. A brave new world lies beyond the seven seas. Join the 34th Modeling Contest today!
    Dismiss Notice
  3. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Hive 3 Remoosed BETA - NOW LIVE. Go check it out at BETA Hive Workshop! Post your feedback in this new forum BETA Feedback.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Hot Spot System

Discussion in 'Triggers & Scripts' started by Itachi2020, Oct 5, 2020.

  1. Itachi2020

    Itachi2020

    Joined:
    Mar 24, 2020
    Messages:
    66
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Hi guys,

    I am trying to create a hot spot system. What I am trying to achieve is when there are multiple players building in an area of the map, the periodically spawned roaming creeps will gravitate that way.

    So, some context. I have a system that spawns creeps every 15 seconds and they randomly roam around the map. What I would like is for a separate system to run every 60 seconds which pulls the creeps towards the hot spots. If a player is building alone (so has 1 main structure), they won't pull creeps, they just need to fight off the ones that randomly come across their base.

    So far I've created a 60 second timer and the below trigger. Unfortunately it doesn't work. Basically, the idea is that every 60 seconds a point is put on every town hall, counts how many other town halls are in close proximity and then pulls creeps in X radius towards the town hall, depending on how many town halls are close by. (I have also included the improved tiers).

    If I can get some help perhaps fixing the below trigger, or creating a better system, please let me know!

    • Loop
      • Events
        • Time - Every 60.00 seconds of game time
      • Conditions
      • Actions
        • Custom script: set bj_wantDestroyGroup = true
        • Unit Group - Pick every unit in (Units of type Settlement) and do (Actions)
          • Loop - Actions
            • Set VariableSet SpawnLocation = (Position of (Picked unit))
            • Set VariableSet CountTownHalls = (((Number of units in (Units within 2500.00 of SpawnLocation matching ((Unit-type of (Matching unit)) Equal to Settlement).)) + (Number of units in (Units within 2500.00 of SpawnLocation matching ((Unit-type of (Matching unit)) Equal to Keep).))) + ((Number o
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • CountTownHalls Equal to 1
              • Then - Actions
              • Else - Actions
                • Set VariableSet TownHallPull = (CountTownHalls x 2500)
            • Custom script: set bj_wantDestroyGroup = true
            • Unit Group - Pick every unit in (Units within (Real(TownHallPull)) of SpawnLocation matching (((Matching player) is in UndeadForces.) Equal to True).) and do (Actions)
              • Loop - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Current order of (Picked unit)) Not equal to (Order(attack))
                    • (Current order of (Picked unit)) Not equal to (Order(rainoffire))
                    • (Current order of (Picked unit)) Not equal to (Order(carrionswarm))
                  • Then - Actions
                    • Unit - Order (Picked unit) to Attack-Move To SpawnLocation
                    • AI - Ignore (Picked unit)'s guard position
                    • Custom script: call RemoveLocation(udg_SpawnLocation)
                  • Else - Actions
            • Custom script: call RemoveLocation(udg_SpawnLocation)
     
    Last edited: Oct 5, 2020
  2. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    2,471
    Resources:
    0
    Resources:
    0
    The problem:
    • Unit Group - Pick every unit in (Units within (Real(TownHallPull)) of SpawnLocation matching (((Matching player) is in UndeadForces.) Equal to True).) and do (Actions)

    Matching player is not usable in this condition, since you're picking UNITS and not players. Use "Owner of matching unit is in UndeadForces" instead.

    And since you have an If Then Else for filtering the picked units you could add to it the condition "Owner of picked unit is in UndeadForces = True" instead of using Matching.
     
  3. Itachi2020

    Itachi2020

    Joined:
    Mar 24, 2020
    Messages:
    66
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Good spot! Thanks dude for going through that trigger.

    I've managed to get it working, only if I remove the order conditions which is a bit annoying. Still functional, and as it's only a re-occurring trigger every 60 seconds so I'm not too concerned about potentially cancelling out an ability cast.
     
  4. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    2,471
    Resources:
    0
    Resources:
    0
    Also, not sure if this is intentional, but you're ordering the UndeadForces to move to a new SpawnLocation X times, X being the number of Settlements.

    So if players have 10 Settlements, 10 SpawnLocations will be created, and enemies will be ordered to move to Attack-Move to each one.

    Since this all occurs at the same time, only the last SpawnLocation (10th one) will be used. Meaning those other 9 Spawn Locations and calculations were completely pointless.

    To fix this you would move every single line of code below Set Variable CountTownHalls to OUTSIDE and below the first Pick Every Unit function.

    Then if you wanted the UndeadForces to move to a "random" SpawnLocation, you could delete "set bj_wantDestroyGroup = true" and set the Settlement unit's as a Unit Group variable. Then you can set SpawnLocation = Position of random unit from SettlementGroup.
     
  5. Itachi2020

    Itachi2020

    Joined:
    Mar 24, 2020
    Messages:
    66
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Right I think I understand. I was under the impression that the spawnlocation wouldn't work like that. Is this what you mean? Also FYI players can only have one settlement each.

    -settlementpullgroup is a group for the settlements to sit in for the random group attack function.


    • Loop
      • Events
        • Time - HotSpotTimer expires
      • Conditions
      • Actions
        • Unit Group - Remove all units from SettlementPullGroup.
        • Custom script: set bj_wantDestroyGroup = true
        • Unit Group - Pick every unit in (Units of type Settlement) and do (Actions)
          • Loop - Actions
            • Set VariableSet SpawnLocation = (Position of (Picked unit))
            • Set VariableSet CountSettlements = 0
            • Set VariableSet CountSettlements = (CountSettlements + (Number of units in (Units within 2500.00 of SpawnLocation matching ((Unit-type of (Matching unit)) Equal to Settlement).)))
        • Unit Group - Add all units of (Units within 2500.00 of SpawnLocation matching ((Unit-type of (Matching unit)) Equal to Settlement).) to SettlementPullGroup
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • CountSettlements Equal to 1
          • Then - Actions
          • Else - Actions
            • Set VariableSet TownHallPull = (CountSettlements x 2500)
        • Custom script: set bj_wantDestroyGroup = true
        • Unit Group - Pick every unit in (Units within (Real(TownHallPull)) of SpawnLocation matching (((Owner of (Matching unit)) is in UndeadForces.) Equal to True).) and do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
              • Then - Actions
                • Set VariableSet AttackPoint = (Position of (Random unit from SettlementPullGroup))
                • Unit - Order (Picked unit) to Attack-Move To AttackPoint
                • AI - Ignore (Picked unit)'s guard position
              • Else - Actions
        • Custom script: call RemoveLocation(udg_SpawnLocation)
        • Custom script: call RemoveLocation(udg_AttackPoint)
        • Countdown Timer - Start HotSpotTimer as a One-shot timer that will expire in 60.00 seconds
     
    Last edited: Oct 6, 2020
  6. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    2,471
    Resources:
    0
    Resources:
    0
    Sorry, I think I misread the trigger and may have mislead you. Not sure if the random point thing would actually work based on how I described it.

    Regardless, your original trigger had leaks. Here's how I would do it:
    • Untitled Trigger 001
      • Events
      • Conditions
      • Actions
        • Set VariableSet TempGroups[0] = (Units of type Town Hall)
        • Unit Group - Pick every unit in TempGroups[0] and do (Actions)
          • Loop - Actions
            • Set VariableSet CountTownHalls = 0
            • Set VariableSet TempPoint = (Position of (Picked unit))
            • -------- --------
            • Set VariableSet TempGroups[1] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Footman).)
            • Set VariableSet TempGroups[2] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Knight).)
            • Set VariableSet TempGroups[3] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Rifleman).)
            • -------- --------
            • Set VariableSet CountTownHalls = (CountTownHalls + (Number of units in TempGroups[0]))
            • Set VariableSet CountTownHalls = (CountTownHalls + (Number of units in TempGroups[1]))
            • Set VariableSet CountTownHalls = (CountTownHalls + (Number of units in TempGroups[2]))
            • Set VariableSet CountTownHalls = (CountTownHalls + (Number of units in TempGroups[3]))
            • Set VariableSet TownHallPull = (CountTownHalls x 2500)
            • -------- --------
            • Set VariableSet TempGroups[4] = (Units within (Real(TownHallPull)) of TempPoint.)
            • Unit Group - Pick every unit in TempGroups[4] and do (Actions)
              • Loop - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Owner of (Picked unit)) Equal to Neutral Hostile
                    • ((Picked unit) is alive) Equal to True
                  • Then - Actions
                    • Unit - Order (Picked unit) to Attack-Move To TempPoint
                  • Else - Actions
            • -------- --------
            • Custom script: call DestroyGroup (udg_TempGroups[1])
            • Custom script: call DestroyGroup (udg_TempGroups[2])
            • Custom script: call DestroyGroup (udg_TempGroups[3])
            • Custom script: call DestroyGroup (udg_TempGroups[4])
            • Custom script: call RemoveLocation (udg_TempPoint)
        • Custom script: call DestroyGroup (udg_TempGroups[0])
    ^Replace Town Hall with Settlements and Footman/Knight/Rifleman with your Tiered Units. Some other minor details may be off or missing but I'm sure you can fix them.

    Here's another version of that trigger that will only order a Unit to attack ONCE per cycle. This could help make units spread out more. I add the Picked Units to a Unit Group called "AlreadyAttacked" after they're issued an Attack-Move order, then I filter them out of the Conditions so that they don't get issued an Attack-Move order again. Then I clear this Group once the trigger is finished so that it will work again in the future.
    • Untitled Trigger 001
      • Events
      • Conditions
      • Actions
        • Set VariableSet TempGroups[0] = (Units of type Town Hall)
        • Unit Group - Pick every unit in TempGroups[0] and do (Actions)
          • Loop - Actions
            • Set VariableSet CountTownHalls = 0
            • Set VariableSet TempPoint = (Position of (Picked unit))
            • -------- --------
            • Set VariableSet TempGroups[1] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Footman).)
            • Set VariableSet TempGroups[2] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Knight).)
            • Set VariableSet TempGroups[3] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Rifleman).)
            • -------- --------
            • Set VariableSet CountTownHalls = (CountTownHalls + (Number of units in TempGroups[0]))
            • Set VariableSet CountTownHalls = (CountTownHalls + (Number of units in TempGroups[1]))
            • Set VariableSet CountTownHalls = (CountTownHalls + (Number of units in TempGroups[2]))
            • Set VariableSet CountTownHalls = (CountTownHalls + (Number of units in TempGroups[3]))
            • Set VariableSet TownHallPull = (CountTownHalls x 2500)
            • -------- --------
            • Set VariableSet TempGroups[4] = (Units within (Real(TownHallPull)) of TempPoint.)
            • Unit Group - Pick every unit in TempGroups[4] and do (Actions)
              • Loop - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • ((Picked unit) is in AlreadyAttacked.) Equal to False
                    • (Owner of (Picked unit)) Equal to Neutral Hostile
                    • ((Picked unit) is alive) Equal to True
                  • Then - Actions
                    • Unit - Order (Picked unit) to Attack-Move To TempPoint
                    • Unit Group - Add (Picked unit) to AlreadyAttacked
                  • Else - Actions
            • -------- --------
            • Custom script: call DestroyGroup (udg_TempGroups[1])
            • Custom script: call DestroyGroup (udg_TempGroups[2])
            • Custom script: call DestroyGroup (udg_TempGroups[3])
            • Custom script: call DestroyGroup (udg_TempGroups[4])
            • Custom script: call RemoveLocation (udg_TempPoint)
        • Custom script: call DestroyGroup (udg_TempGroups[0])
        • Unit Group - Remove all units from AlreadyAttacked.

    EDIT: Keep in mind that Unit Groups will pick Dead units as well, and I THINK dead Structures will get picked, I'm not entirely sure of on this.

    The UndeadForces might be Dead though so that's why I check if they're Alive in my conditions. Also, I know you said that "Current order of Picked unit" was causing problems, but I think the real issue was how you were removing SpawnLocation in your original trigger. You should be able to use that Condition without problems if done correctly.

    For efficiencies sake it might be better to just have a single Unit Group that you use to keep track of Settlements. This way you don't have to create/destroy a new group each time. You could do the same for tiered units as well.
     
    Last edited: Oct 8, 2020
  7. Itachi2020

    Itachi2020

    Joined:
    Mar 24, 2020
    Messages:
    66
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Thanks a lot dude for going into so much detail! I've implemented it and it works! I did remove the "Set VariableSet CountTownHalls = (CountTownHalls + (Number of units in TempGroups[0]))" in the third section in the unit group as it wasn't necessary as the unit types would get added anyway in the other groups.
    For some reason though it runs once, and then it doesn't run again. I've tried to fix using a variable timer and then just a basic re-occurring event. Both only run the trigger once. I added a game message into the trigger so I can detect when it runs and the values that it finds.

    I'm not sure if it's just an issue with this specific file. I've had a few triggers recently stop working for no good reason. Like game messages not appearing even on triggers with no conditions. I had a timer also produce crashes which was annoying to find/remove.

    Below for reference.

    • Loop
      • Events
        • Time - Every 30.00 seconds of game time
      • Conditions
      • Actions
        • Unit Group - Add all units of (Units of type Settlement) to TempGroups[0]
        • Unit Group - Add all units of (Units of type Keep) to TempGroups[0]
        • Unit Group - Add all units of (Units of type Castle Hero) to TempGroups[0]
        • Unit Group - Add all units of (Units of type Castle Normal) to TempGroups[0]
        • Unit Group - Pick every unit in TempGroups[0] and do (Actions)
          • Loop - Actions
            • Set VariableSet CountSettlements = 0
            • Set VariableSet TempPoint = (Position of (Picked unit))
            • -------- - --------
            • Set VariableSet TempGroups[1] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Settlement).)
            • Set VariableSet TempGroups[2] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Keep).)
            • Set VariableSet TempGroups[3] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Castle Hero).)
            • Set VariableSet TempGroups[4] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Castle Normal).)
            • -------- - --------
            • Set VariableSet CountSettlements = (CountSettlements + (Number of units in TempGroups[1]))
            • Set VariableSet CountSettlements = (CountSettlements + (Number of units in TempGroups[2]))
            • Set VariableSet CountSettlements = (CountSettlements + (Number of units in TempGroups[3]))
            • Set VariableSet CountSettlements = (CountSettlements + (Number of units in TempGroups[4]))
            • Set VariableSet CountSettlements = (CountSettlements - 1)
            • Game - Display to (All players) the text: (String(CountSettlements))
            • Set VariableSet TownHallPull = ((Real(CountSettlements)) x 2500.00)
            • Environment - Create Blight for Player 1 (Red) from (Position of (Picked unit)) to a radius of TownHallPull. (Just to see the radius it creates)
            • -------- - --------
            • Set VariableSet TempGroups[4] = (Units within TownHallPull of TempPoint.)
            • Unit Group - Pick every unit in TempGroups[4] and do (Actions)
              • Loop - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • ((Owner of (Picked unit)) is in UndeadForces.) Equal to True
                    • ((Picked unit) is alive) Equal to True
                    • ((Picked unit) is in AlreadyAttacked.) Equal to False
                  • Then - Actions
                    • Unit - Order (Picked unit) to Attack-Move To TempPoint
                    • Unit Group - Add (Picked unit) to AlreadyAttacked
                  • Else - Actions
            • Custom script: call DestroyGroup (udg_TempGroups[1])
            • Custom script: call DestroyGroup (udg_TempGroups[2])
            • Custom script: call DestroyGroup (udg_TempGroups[3])
            • Custom script: call DestroyGroup (udg_TempGroups[4])
            • Custom script: call RemoveLocation (udg_TempPoint)
        • Custom script: call DestroyGroup (udg_TempGroups[0])
        • Unit Group - Remove all units from AlreadyAttacked.
     
  8. DoomBlade

    DoomBlade

    Joined:
    Feb 5, 2018
    Messages:
    364
    Resources:
    0
    Resources:
    0
    It runs only once, because of this
    You destroy the group and it is never created again.

    You need to store the group into a variable. Like Uncle showed you in one of his triggers.

    The simple solution is to use "Remove all units from TempGroups[0]".

    But for better functionality, store the units into a variable in the trigger.

    Setvariable TempGroups[0] = Units within range of point matching unit is a building
    If/then/else
    If unit type of picked unit settlement
    If unit type of picked unit castle hero
    If unit type of picked unit keep
    If unit type of picked unit castle normal
    Then
    Add picked unit to TempGroups[0]
    else
    Remove picked unit from TempGroups[0]
     
  9. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    2,471
    Resources:
    0
    Resources:
    0
    Just make TempGroup[0] = Units of type settlements like how I did it. Don't try to Add/Remove units to that Unit Group since we're going to destroy it.

    These are TEMPorary Unit Groups, meaning they're intended to be created/destroyed again and again.

    And your issues come from the fact that you've been destroying your Points/Groups/etc... inside of your Pick Every Unit functions which results in them breaking. Think about it, how can you "Order picked unit to Attack-Move to TempPoint" if TempPoint no longer exists.

    Remember, Pick Every Unit runs the Actions ONCE for each picked unit. If you destroy anything important in it then it will fail to work for all of the other units. That's why it'll often work 1 time, or work only for the 1st unit it picks, because you've destroyed something that the future picked units needed.

    In other words, Pick Every Unit is a Loop, it runs the Actions from top to bottom X times, X being the total number of Picked Units. Each Picked Unit will cause the Actions to run once.


    An important concept to understand is how the game engine works. Triggers/Actions are always ordered and resolved from top to bottom, with only 1 thing happening at a time. When you have a Trigger with the Event "A unit dies" and then you kill 2 Units at the same exact time, that Trigger doesn't run only once. It runs twice, once for each dying unit. This is because the game ordered the units deaths to happen one after the other.

    If you do:
    -Kill last created unit
    -Create 1 Footman
    It won't work, because you're try to kill the unit before it's even created.

    If you swap the order of these Actions then it does work:
    -Create 1 Footman
    -Kill last created unit

    With this in mind, don't get fooled by something like: "Create 3 Footman". It's still using the above system of ordering, meaning that only 1 Footman will be created at a time. So in-game these Footman will be created at the same time, at least for gameplay purposes, but for coding purposes they're really created 1 by 1.

    That function really translates to:
    -Create 1 Footman
    -Create 1 Footman
    -Create 1 Footman

    If you then used:
    -Kill Last created unit

    It would kill the 3rd Footman since it was the last unit created.

    Hopefully this makes sense. A good way to visualize what I'm describing is to Display Text Messages of the Names of the Picked Units inside of a Pick Every Unit function. You'll see one message per Picked Unit, and the order in which these Actions occurred will be made clear:
    "Footman"
    "Knight"
    "Archer"
    etc...
     
    Last edited: Oct 7, 2020
  10. Itachi2020

    Itachi2020

    Joined:
    Mar 24, 2020
    Messages:
    66
    Resources:
    1
    Maps:
    1
    Resources:
    1
    The trigger needs to create and run points for every Settlement, Keep, Castle Normal and Castle Hero. That's why I added them all to the TempGroup0.
    So a Settlement upgrades to a Keep, Keep to Castles etc. They all need to include this function where they are part of the hot spot system and count each other.
    Would it be better to have four variations of this trigger? Then using Set VariableSet TempGroups[0] = (Units of type Settlement/Keep/Castle Normal/Castle Hero) for each tier?

    In the trigger I posted the TempGroups0 gets removed after the unit group loop, so surely the unit loop would run X amount of times using the units in TempGroup0 before getting deleted at the very end of the trigger? When the trigger fires again it will re-populate the TempGroups0 with Settlements/Keeps/Castles - as players may have had their main building destroyed/rebuilt. Removing all units from the group at the end of the trigger/destroying it surely has the same effect? As the next time the trigger fires it should re-create that group with an updated group of units?

    The temp location, this needs to be reset every loop of the unit group as each unit in the TempGroup0 has a different location. So creating it at the start of the loop and removing it at the end of the loop should be fine? The same for TempGroups(1-4) They get re-created within the loop and specific to each individual unit in the group. Does destroying it then just mean that it cannot be re-created/assigned further in the loop?

    Is the issue that when they have been destroyed (TempLoc/TempGroup[]) that they cannot be re-populated within the same trigger/loop? So say the first loop of the unit group populates these groups, uses them and then destroys the tempgroup... the second unit/loop simply cannot re-assign the point or re-populate the groups as these variables as they have been fully destroyed and then unaccessible in that trigger? Would I need to empty the groups using "Remove all units from TempGroups[1-4]" and not destroying TempLoc. I would need to destroy TempLoc/TempGroups right at the end of the trigger?

    I will try that function to include all of these units! I will let you know how it goes.
     
  11. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    2,471
    Resources:
    0
    Resources:
    0
    You've never set TempGroup[0] but you're trying to add units to it. You cannot add units to a Unit Group that doesn't exist. That's the only issue with your trigger at the moment.

    And if you want the other buildings to be in TempGroup[0] then recreate my trigger EXACTLY as you see it, and then adjust TempGroup[0] to:
    • Set VariableSet TempGroups[0] = (Units in playable map area matching Unit-type = A or Unit-type = B or Unit-type = C or Unit-type = D)
     
    Last edited: Oct 8, 2020
  12. Itachi2020

    Itachi2020

    Joined:
    Mar 24, 2020
    Messages:
    66
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Sweet. The below trigger works well, I tested it on battle.net and three players (luckily) decided to build together and they had a much tougher time due to the additional pressure from the undead forces.

    Is removing all units from tempgroup at the end okay? That shouldn't cause leaks as they will just be repopulated next time?

    • Loop
      • Events
        • Time - Every 30.00 seconds of game time
      • Conditions
      • Actions
        • Set VariableSet TempGroups[0] = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to Settlement) or (((Unit-type of (Matching unit)) Equal to Keep) or (((Unit-type of (Matching unit)) Equal to Castle Hero) or ((Unit-type of (Matching unit)) Equal to Castle Normal
        • Unit Group - Pick every unit in TempGroups[0] and do (Actions)
          • Loop - Actions
            • Set VariableSet CountSettlements = 0
            • Set VariableSet TempPoint = (Position of (Picked unit))
            • -------- - --------
            • Set VariableSet TempGroups[1] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Settlement).)
            • Set VariableSet TempGroups[2] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Keep).)
            • Set VariableSet TempGroups[3] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Castle Hero).)
            • Set VariableSet TempGroups[4] = (Units within 2500.00 of TempPoint matching ((Unit-type of (Matching unit)) Equal to Castle Normal).)
            • -------- - --------
            • Set VariableSet CountSettlements = (CountSettlements + (Number of units in TempGroups[1]))
            • Set VariableSet CountSettlements = (CountSettlements + (Number of units in TempGroups[2]))
            • Set VariableSet CountSettlements = (CountSettlements + (Number of units in TempGroups[3]))
            • Set VariableSet CountSettlements = (CountSettlements + (Number of units in TempGroups[4]))
            • Set VariableSet CountSettlements = (CountSettlements - 1)
            • Set VariableSet TownHallPull = ((Real(CountSettlements)) x 2500.00)
            • -------- - --------
            • Set VariableSet TempGroups[4] = (Units within TownHallPull of TempPoint.)
            • Unit Group - Pick every unit in TempGroups[4] and do (Actions)
              • Loop - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • ((Owner of (Picked unit)) is in UndeadForces.) Equal to True
                    • ((Picked unit) is alive) Equal to True
                    • ((Picked unit) is in AlreadyAttacked.) Equal to False
                  • Then - Actions
                    • Unit - Order (Picked unit) to Attack-Move To TempPoint
                    • Unit Group - Add (Picked unit) to AlreadyAttacked
                  • Else - Actions
            • Unit Group - Remove all units from TempGroups[1].
            • Unit Group - Remove all units from TempGroups[2].
            • Unit Group - Remove all units from TempGroups[3].
            • Unit Group - Remove all units from TempGroups[4].
        • Custom script: call RemoveLocation (udg_TempPoint)
        • Unit Group - Remove all units from TempGroups[0].
        • Unit Group - Remove all units from AlreadyAttacked.
     
  13. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    2,471
    Resources:
    0
    Resources:
    0
    You need to destroy TempGroup[0], not Remove all units from it.

    Also, if you only have exactly 1 Settlement on the map, the AI will never get ordered to attack it since you subtract 1 from TownHallCount.

    Other than that, it looks good :)
     
  14. Itachi2020

    Itachi2020

    Joined:
    Mar 24, 2020
    Messages:
    66
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Brilliant. Thanks for all the help!
     
  15. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    2,471
    Resources:
    0
    Resources:
    0
    Same goes for all of the other TempGroups, make sure to Destroy all of them.

    Only use Remove all units for Unit Groups that aren't destroyed, like AlreadyAttacked.

    So again, you're destroying ALL of the TempGroups, not Adding/Removing units from them.