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

Remembering bought units.

Status
Not open for further replies.
Level 2
Joined
May 1, 2007
Messages
6
I'm not quite sure if this should be in "Triggers & Scripts" forum, please tell me, and i'll remake it over there.

Basically i want to somehow store/remember what units each player have bought (to create like a list of units in their "army"). Then at a certain event, perhaps after a wave was cleared, to restore any missing units. So for example, Billy have bought 1 x Hero, 2 x Rifleman and 1 x Footman, then the round starts and a wave of creeps appear, after the wave is cleared Billy have 1 x Hero, 1 x Rifleman and 0 x Footman, the game would then respawn/ressurect/create/something 1 x Rifleman and 1 x Footman.

Is this possible somehow?
I have some experience with triggers, but haven't quite been able to figure this out.
Perhaps my idea of doing it is flawed, but the essence is that in some way i need the game to log what units a player have purchased, and then being able to remake whatever units he may have lost, so it needs to compare the players current units with the log of what units he have purchased and then recreating whatever is missing.

Thanks in advance! :)
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
I think if you really wanted to make a simple solution you can set all of your human units to "can raise, doesn't decay" and all enemy units to "can't raise, does decay" and then dummy cast a massive Resurrection for each player with huge range and targets set to "player units" (and not allied units or enemy) at the end of every round. You set the targets like that so that each resurrection only revives the player's units not allied units too, since that changes their owner to the caster of resurrection.
  • -------- on map init --------
  • Set RES_POINT = Center of WhereverYouWantToRez <gen> //set the point somehow
  • Player Group - Add Player 1 (Red) to HUMAN_PLAYERS
  • Player Group - Add Player 2 (Blue) to HUMAN_PLAYERS
  • ...
  • -------- etc. for all human players --------
  • -------- then in your 'end of round' trigger: --------
  • Player Group - Pick every player in HUMAN_PLAYERS and do (Actions)
    • Loop - Actions
      • Unit - Create 1 DummyUnit for (Picked Player) at RES_POINT facing Default Buildling Facing degrees
      • Unit - Add a 1.00 second generic expiration timer to (last created unit)
      • Unit - Add RES_ABILITY to (last created unit)
      • Unit - Order (last created unit) to Human Paladin - Resurrection
This is real bootleg but less work than keeping a running tally of all spawned units. It might be possible with a unit group to keep track of them too but that's a different method.
 
Level 2
Joined
May 1, 2007
Messages
6
If it looks stupid but works, it ain't stupid, i guess.
I've tried doing what u said, but i have an issue with the "Can raise - Does not decay" Death type on the units. They don't seem to leave any corpse at all now, and therefore the resurrection doesn't work? This is probably a very simple fix, that i just cant seem to figure out.
 
Level 13
Joined
Jul 15, 2007
Messages
763
The way i achieved this is to use a hashtable. Essentially you convert a unit-type to an integer, and save it at the player's current army size (and then increasing that player's known army size) under that player's number in a hashtable. Then you essentially have an army "list" for each player that can be recalled on demand. You can then cycle through a player's army list, checking if each unit is alive, if its not, you replenish it using the unit type integer stored at that list position.
 
Level 2
Joined
May 1, 2007
Messages
6
The way i achieved this is to use a hashtable. Essentially you convert a unit-type to an integer, and save it at the player's current army size (and then increasing that player's known army size) under that player's number in a hashtable. Then you essentially have an army "list" for each player that can be recalled on demand. You can then cycle through a player's army list, checking if each unit is alive, if its not, you replenish it using the unit type integer stored at that list position.

That sounds a lot like what i was imagining. But i have no experience with hashtable, is there a guide for making such a thing?
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
I was hoping you could get things to decay naturally except for your units which would never decay. Seems like that isn’t possible. Instead you need to make them can raise does decay and change the decay time to infinite (or as long as you can make it) in Advanced > Gameplay Constants. Your enemies should be doesn’t decay then so their bodies don’t pile up all around the map.
 
I was hoping you could get things to decay naturally except for your units which would never decay. Seems like that isn’t possible. Instead you need to make them can raise does decay and change the decay time to infinite (or as long as you can make it) in Advanced > Gameplay Constants. Your enemies should be doesn’t decay then so their bodies don’t pile up all around the map.
It will mess up Raise Dead or any corpse related abilities though, just to keep note of.

---
If one goes with the system approach, a double array can also be used as a solution.
  • Set Var[Arr[Player]] = Unit-Type
 
Level 2
Joined
May 1, 2007
Messages
6
Read up on the guide, and have an idea of how it works now, but going from there to actually figuring out how to store each unit in a hashtable, seems a bit far off :/

Daffa could u explain your idea to greater extent? :)
 
Level 9
Joined
Jul 30, 2018
Messages
445
I would make it with triggers. I just tested it and you would need just two triggers.

The first trigger just registers each unit to a Integer-variable. You can basically use any kind of type you like, like make array for each player or make array for each unit-type or make an array inside an array or whatever. Here's a simple example:

  • Unit Train
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Trained unit)) Equal to Player 1 (Red)
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Trained unit)) Equal to Footman
            • Then - Actions
              • Set Player1Footmen = (Player1Footmen + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Trained unit)) Equal to Rifleman
            • Then - Actions
              • Set Player1Riflemen = (Player1Riflemen + 1)
            • Else - Actions
        • Else - Actions

Then the second trigger then finds how many units a player has of each unit-type and compares their amount to the size of the variable created above.

  • Respawn Units
    • Events
      • [Whatever event when you want to create the units]
    • Conditions
    • Actions
      • -------- Footmen --------
      • Set TempInteger = 0
      • Set TempGroup = (Units owned by Player 1 (Red) matching (((Unit-type of (Matching unit)) Equal to Footman) and (((Matching unit) is alive) Equal to True)))
      • Set TempInteger = (Number of units in TempGroup)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TempInteger Less than Player1Footmen
        • Then - Actions
          • Set TempPoint = [Whatever spawnpoint you want]
          • Unit - Create (Player1Footmen - TempInteger) Footman for Player 1 (Red) at TempPoint facing Default building facing degrees
          • Custom script: call RemoveLocation(udg_TempPoint)
        • Else - Actions
      • Custom script: call DestroyGroup(udg_TempGroup)
      • -------- Riflemen --------
      • Set TempInteger2 = 0
      • Set TempGroup2 = (Units owned by Player 1 (Red) matching (((Unit-type of (Matching unit)) Equal to Rifleman) and (((Matching unit) is alive) Equal to True)))
      • Set TempInteger2 = (Number of units in TempGroup2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TempInteger2 Less than Player1Riflemen
        • Then - Actions
          • Set TempPoint2 = [...]
          • Unit - Create (Player1Riflemen - TempInteger2) Rifleman for Player 1 (Red) at TempPoint2 facing Default building facing degrees
          • Custom script: call RemoveLocation(udg_TempPoint2)
        • Else - Actions
      • Custom script: call DestroyGroup(udg_TempGroup2)

Obviously this is very simple example and doesn't count multiple players and if you have a lot of different unit-types you might want to add them in variables and just run the trigger in loops, but I hope you get the idea. :)
 
Last edited:
Status
Not open for further replies.
Top