[Solved] Create multiple unit types

Status
Not open for further replies.
Level 4
Joined
May 12, 2022
Messages
22
Hi, I'm trying to make a trigger that Picks every unit in region A and creates a corresponding unit to another region B based on the type of unit that was picked. I'm using point value to determine which unit corresponds to each picked unit. (this seems easier)


  • Trigger 1
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Set VariableSet UnitZ = Constructed structure
      • -------- - --------
      • Set VariableSet FighterY[1] = Footman
      • Set VariableSet FighterY[2] = Knight
      • Set VariableSet FighterY[3] = Rifleman

  • Trigger 2
    • Events
      • Time - Every 5.00 seconds of game time
  • Conditions
  • Actions
  • Unit Group - Pick every unit in (Units in Region_A) and do (Actions)
    • Loop - Actions
      • Unit - Create 1 FighterY[(Point-value of UnitZ)] for (Owner of (Picked unit)) at Center of region B facing Default building facing degrees
UnitZ doesn't work in this case as it only represents the last constructed structure (I think), and I don't know a better way to do this.
I need a better way to make use of point-value somehow ..
I think this is similar to how they trigger Legion TD, but i'm not sure how they triggered that.
Currently the trigger doesn't work at all, not sure why .. but even if it did, I don't think it would work right.
 
Last edited:
Level 30
Joined
Aug 29, 2012
Messages
1,382
Try replacing

  • Create 1 FighterY[(Point-value of UnitZ)]
with

  • Create 1 FighterY[(Point-value of (Picked unit))]
Also, you should probably have an initialization trigger where you set the different FighterY units, I don't think it's useful to have it repeated everytime a building is constructed if it's always the same units
 
Level 4
Joined
May 12, 2022
Messages
22
Try replacing

  • Create 1 FighterY[(Point-value of UnitZ)]
with

  • Create 1 FighterY[(Point-value of (Picked unit))]

I think it might work similarly to using Constructed structure in this case. Doesn't it use the value of the last picked unit? I don't see how it could associate each picked unit to the corresponding unit. I will try it later when I get home.
Thanks for the suggestion!
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
While what you have done here works fine, I'll caution you that Point-Value was never intended to be used for such a purpose and this will mess up the end-of-game points screen if you care about that. This is a situation where a hashtable is the appropriate choice because it allows you to use the unit-type as a parent/child key to read the linked unit-type directly. However... despite both unit-types and parent/child keys literally being integers, GUI will neither let you use a unit-type as a key nor store a unit-type in a hashtable directly. You can trick it by 'converting' between them in JASS/Lua custom script lines, though:
  • Hashtable - Create a hashtable
  • Set SpawnHT = (Last created hashtable)
  • -------- --------
  • Set UT_Base = Footman Building //unit-type variables
  • Set UT_Spawn = Footman
  • Custom script: set udg_INT_Base = udg_UT_Base //integer variables
  • Custom script: set udg_INT_Spawn = udg_UT_Spawn //match your variable names here but keep the udg_ prefixes
  • Hashtable - Save INT_Spawn as INT_Base of 0 in SpawnHT //the 0 is the parent key but we don't care about that here so just use the same for everything
  • -------- --------
  • Set UT_Base = Knight Building
  • Set UT_Spawn = Knight
  • Custom script: set udg_INT_Base = udg_UT_Base //this is all identical each time, just the two first variables change what they're assigned to
  • Custom script: set udg_INT_Spawn = udg_UT_Spawn
  • Hashtable - Save INT_Spawn as INT_Base of 0 in SpawnHT
  • -------- --------
  • Set UT_Base = Rifleman Building
  • Set UT_Spawn = Rifleman
  • Custom script: set udg_INT_Base = udg_UT_Base=
  • Custom script: set udg_INT_Spawn = udg_UT_Spawn
  • Hashtable - Save INT_Spawn as INT_Base of 0 in SpawnHT
  • Set UT_Base = (Unit-type of (Picked Unit))
  • Custom script: set udg_INT_Base = udg_UT_Base //use the right variable names but keep udg_ prefixes here too
  • Set INT_Spawn = (Load INT_Base of 0 in SpawnHT) //hashtable integer load command
  • Custom script: set udg_UT_Spawn = udg_INT_Spawn
  • Unit - Create 1 UT_Spawn for ...
 
Level 4
Joined
May 12, 2022
Messages
22
Oh, thanks for pointing that out. I haven't used hashtables before because it looked too complicated but maybe i'll give it a try.
 
Status
Not open for further replies.
Top