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

How can I save entire groups of non-hero units and load them to the next map?

Level 3
Joined
May 27, 2023
Messages
18
I want player units that have survived on my map to basically transfer over to the next mission but I am having trouble figuring out the process of saving them.

Is there a way to save them as a group? Or do I really have to save each individual unit seperately?

What would it look like?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,877
I want player units that have survived on my map to basically transfer over to the next mission but I am having trouble figuring out the process of saving them.

Is there a way to save them as a group? Or do I really have to save each individual unit seperately?

What would it look like?
What do you mean by saving? A save/load system that generates a save file in your Wc3 directory or what Campaign missions use to carry stuff over to the next map (game cache)?
 
Level 3
Joined
May 27, 2023
Messages
18
The game cache is what I'm trying to do yes. I know how to save a hero and have it carry over but when it comes to units, especially larger numbers of them, does each individual unit need to saved separately?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,877
I don't see any way to do this easily in GUI, but I'm not an expert on the matter so maybe there's some Jass functions to simplify it. Regardless here's a GUI method that should work.

Save the units in the game cache using their names + a number to differentiate them. Also, track how many of these units you have and save that value as well so you'll know how many to load in the next map:
  • Save Cache
    • Events
    • Conditions
    • Actions
      • -------- [ MAP ONE ] --------
      • -------- --------
      • -------- Remove unwanted units from being saved (dead for example): --------
      • Unit Group - Pick every unit in SaveUnitGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet SaveUnit = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (SaveUnit is alive) Equal to False
            • Then - Actions
              • Unit Group - Remove SaveUnit from SaveUnitGroup.
            • Else - Actions
      • -------- --------
      • -------- Count up and save each unit: --------
      • Unit Group - Pick every unit in SaveUnitGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet SaveUnit = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of SaveUnit) Equal to Footman
            • Then - Actions
              • Set VariableSet Footman_Count = (Footman_Count + 1)
              • Game Cache - Store SaveUnit as (Footman + (String(Footman_Count))) of Category in MyGameCache
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of SaveUnit) Equal to Rifleman
                • Then - Actions
                  • Set VariableSet Rifleman_Count = (Rifleman_Count + 1)
                  • Game Cache - Store SaveUnit as (Rifleman + (String(Rifleman_Count))) of Category in MyGameCache
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of SaveUnit) Equal to Knight
                    • Then - Actions
                      • Set VariableSet Knight_Count = (Knight_Count + 1)
                      • Game Cache - Store SaveUnit as (Knight + (String(Knight_Count))) of Category in MyGameCache
                    • Else - Actions
      • -------- --------
      • -------- Save how many of these units we have so we can determine how many need to be loaded in our next map: --------
      • Game Cache - Store Footman_Count as FootmanCount of Category in MyGameCache
      • Game Cache - Store Rifleman_Count as RiflemanCount of Category in MyGameCache
      • Game Cache - Store Knight_Count as KnightCount of Category in MyGameCache
So we use a Unit Group variable -> SaveUnitGroup to track the units throughout the session. These are what we're going to save later on. I've left out the Adding of units to this Unit Group but it shouldn't be difficult to figure out how to populate a Unit Group with the units you want. For example:
  • Events
    • Unit - A unit Enters (playable map area)
  • Conditions
    • (Unit-Type of (Triggering unit)) Equal to Footman
    • (Owner of (Triggering unit)) Equal to Player 1 (Red)
  • Actions
    • Unit Group - Add (Triggering unit) to SaveUnitGroup
The loading process is simple, these For Loops will only run their Loop - Actions if you have saved at least 1 of the matching Unit-Type:
  • Load Cache
    • Events
    • Conditions
    • Actions
      • -------- [ MAP TWO ] --------
      • -------- --------
      • -------- Load footman: --------
      • For each (Integer Footman_Count) from 1 to (Load FootmanCount of Category from MyGameCache), do (Actions)
        • Loop - Actions
          • Game Cache - Restore (Footman + (String(Footman_Count))) of Category from MyGameCache for Player 1 (Red) at (Center of (Playable map area)) facing 270.00
      • -------- --------
      • -------- Load rifleman: --------
      • For each (Integer Rifleman_Count) from 1 to (Load RiflemanCount of Category from MyGameCache), do (Actions)
        • Loop - Actions
          • Game Cache - Restore (Rifleman + (String(Rifleman_Count))) of Category from MyGameCache for Player 1 (Red) at (Center of (Playable map area)) facing 270.00
      • -------- --------
      • -------- Load knights: --------
      • For each (Integer Knight_Count) from 1 to (Load KnightCount of Category from MyGameCache), do (Actions)
        • Loop - Actions
          • Game Cache - Restore (Knight + (String(Knight_Count))) of Category from MyGameCache for Player 1 (Red) at (Center of (Playable map area)) facing 270.00
You could turn this into a dynamic system with the use of a Hashtable and a database of your different savable Unit-Types.
 

Attachments

  • Game Cache Triggers.w3m
    18.4 KB · Views: 4
Last edited:
Top