• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Need Help With Choosing Race!

Status
Not open for further replies.
Level 2
Joined
Jun 24, 2019
Messages
13
So it should be simple, but I'm new to maps, and I can't seem to figure it out. I want it to be so that in the beginning you can click on the tavern and see icons that give you a selection of different races.

This won't be for races to do a regular melee game. When you select the race you would like to be, then 12 units of that race will appear on the map somewhere (where isn't important- some given region or something). There isn't base building or anything in this game.

So, something similar to choosing your starting guy in Island Defense, except 1 guy doesn't come out, but 12 (but not all the same unit- but a race group you play the rest of the game with).

Can anybody help?
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
The tavern should sell a unit corresponding to each race. When a player purchases such a unit, catch this with a trigger and check the unit-type to figure out which race was bought. From here you need to create the correct units, and there are two simple ways I see to do it:
  • Store all of the information about what units to create for a race in a series of parallel integer and unit-type arrays (e.g. for race 6 (say 6 is Trolls) make NumUnits6[1] of TypeUnits6[1], NumUnits6[2] of TypeUnits6[2], NumUnits6[3] of TypeUnits6[3], etc. This could also be done in 1 array for all races by making it function like a pseudo-2D array (since wc3 does not truly have multidimensional arrays you have to fake it).

  • Pre-place a group of units for each race (owned by neutral passive) somewhere on the map that players can't access, bounded by a region. Have a different region for each race and store the regions in a region array. When a player chooses race 6, duplicate all of the units currently in RaceRegion[6] for that player.
I like the second solution better. Trigger would look something like this:
  • Events
    • Time - Elapsed game-time is 0.50 seconds
  • Conditions
  • Actions
    • Set RaceCount = (RaceCount + 1)
    • Set RaceBuyUnit[RaceCount] = Human Unit
    • Set RaceRegion[RaceCount] = Human Region <gen>
    • -------- --------
    • Set RaceCount = (RaceCount + 1)
    • Set RaceBuyUnit[RaceCount] = Night Elf Unit
    • Set RaceRegion[RaceCount] = Night Elf Region <gen>
    • -------- --------
    • Set RaceCount = (RaceCount + 1)
    • Set RaceBuyUnit[RaceCount] = Orc Unit
    • Set RaceRegion[RaceCount] = Orc Region <gen>
    • -------- --------
    • Set RaceCount = (RaceCount + 1)
    • Set RaceBuyUnit[RaceCount] = Undead Unit
    • Set RaceRegion[RaceCount] = Undead Region <gen>
    • -------- --------
    • Set RaceCount = (RaceCount + 1)
    • Set RaceBuyUnit[RaceCount] = Dwarf Unit
    • Set RaceRegion[RaceCount] = Dwarves Region <gen>
    • -------- --------
    • Set RaceCount = (RaceCount + 1)
    • Set RaceBuyUnit[RaceCount] = Troll Unit
    • Set RaceRegion[RaceCount] = Troll Region <gen>
  • Events
    • Unit - A unit sells a unit
  • Conditions
    • (Unit-type of (Triggering Unit)) equal to RACE_TAVERN //here, triggering unit is the same as selling unit
  • Actions
    • Set SpawnUnitType = (Unit type of (Sold unit))
    • Set SpawnPlayer = (Owner of (Sold unit))
    • Set SpawnPosition = WHEREVER_IT_SHOULD_BE
    • Unit - Remove (Sold unit)
    • For each (Integer A) from 1 to RaceCount do (Actions)
      • Loop - Actions
        • If (All conditions) then do (Then actions) else do (Else actions)
          • If - Conditions
            • SpawnUnitType equal to RaceBuyUnit[(Integer A)]
          • Then - Actions
            • Custom script: set bj_wantDestroyGroup = true //this cleans a leak in the below unit group pick line automatically, you can read about it in the leak tutorials
            • Unit Group - Pick every unit in RaceRegion[(Integer A)] and do (Actions)
              • Loop - Actions
                • Unit - Create 1 (Unit-type of (Picked Unit)) for SpawnPlayer at SpawnPosition facing (Default building facing degrees)
          • Else - Actions
    • Custom script: call RemoveLocation(udg_SpawnPosition) //cleaning the point leak; change the variable name to match yours but keep the udg_ prefix
 
Level 2
Joined
Jun 24, 2019
Messages
13
Pyrogasm you've saved me again. Literally the only reason I can move forward with this map right now.

I think option 2 is what I'll attempt. I'll update you on here when the trigger is finished.

Thanks again!
 
Level 2
Joined
Jun 24, 2019
Messages
13
Question.

So, would the region array be a region encompassing the other multiple regions around each race? Or is there some place in map editor that is specifically for "region array" that I don't know about?


The tavern should sell a unit corresponding to each race. When a player purchases such a unit, catch this with a trigger and check the unit-type to figure out which race was bought. From here you need to create the correct units, and there are two simple ways I see to do it:
  • Store all of the information about what units to create for a race in a series of parallel integer and unit-type arrays (e.g. for race 6 (say 6 is Trolls) make NumUnits6[1] of TypeUnits6[1], NumUnits6[2] of TypeUnits6[2], NumUnits6[3] of TypeUnits6[3], etc. This could also be done in 1 array for all races by making it function like a pseudo-2D array (since wc3 does not truly have multidimensional arrays you have to fake it).

  • Pre-place a group of units for each race (owned by neutral passive) somewhere on the map that players can't access, bounded by a region. Have a different region for each race and store the regions in a region array. When a player chooses race 6, duplicate all of the units currently in RaceRegion[6] for that player.
I like the second solution better. Trigger would look something like this:
  • Events
    • Time - Elapsed game-time is 0.50 seconds
  • Conditions
  • Actions
    • Set RaceCount = (RaceCount + 1)
    • Set RaceBuyUnit[RaceCount] = Human Unit
    • Set RaceRegion[RaceCount] = Human Region <gen>
    • -------- --------
    • Set RaceCount = (RaceCount + 1)
    • Set RaceBuyUnit[RaceCount] = Night Elf Unit
    • Set RaceRegion[RaceCount] = Night Elf Region <gen>
    • -------- --------
    • Set RaceCount = (RaceCount + 1)
    • Set RaceBuyUnit[RaceCount] = Orc Unit
    • Set RaceRegion[RaceCount] = Orc Region <gen>
    • -------- --------
    • Set RaceCount = (RaceCount + 1)
    • Set RaceBuyUnit[RaceCount] = Undead Unit
    • Set RaceRegion[RaceCount] = Undead Region <gen>
    • -------- --------
    • Set RaceCount = (RaceCount + 1)
    • Set RaceBuyUnit[RaceCount] = Dwarf Unit
    • Set RaceRegion[RaceCount] = Dwarves Region <gen>
    • -------- --------
    • Set RaceCount = (RaceCount + 1)
    • Set RaceBuyUnit[RaceCount] = Troll Unit
    • Set RaceRegion[RaceCount] = Troll Region <gen>
  • Events
    • Unit - A unit sells a unit
  • Conditions
    • (Unit-type of (Triggering Unit)) equal to RACE_TAVERN //here, triggering unit is the same as selling unit
  • Actions
    • Set SpawnUnitType = (Unit type of (Sold unit))
    • Set SpawnPlayer = (Owner of (Sold unit))
    • Set SpawnPosition = WHEREVER_IT_SHOULD_BE
    • Unit - Remove (Sold unit)
    • For each (Integer A) from 1 to RaceCount do (Actions)
      • Loop - Actions
        • If (All conditions) then do (Then actions) else do (Else actions)
          • If - Conditions
            • SpawnUnitType equal to RaceBuyUnit[(Integer A)]
          • Then - Actions
            • Custom script: set bj_wantDestroyGroup = true //this cleans a leak in the below unit group pick line automatically, you can read about it in the leak tutorials
            • Unit Group - Pick every unit in RaceRegion[(Integer A)] and do (Actions)
              • Loop - Actions
                • Unit - Create 1 (Unit-type of (Picked Unit)) for SpawnPlayer at SpawnPosition facing (Default building facing degrees)
          • Else - Actions
    • Custom script: call RemoveLocation(udg_SpawnPosition) //cleaning the point leak; change the variable name to match yours but keep the udg_ prefix
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
No I mean to have a region variable that is an array. Instead of having a different variable for each region (Region1, Region2, etc.) you have one variable and use different indices for each region (Regions[1], Regions[2], etc.). This allows you to do Regions[(Integer A)] instead of having a huge if-block string that’s functioning like a switch/case.

The regions should not overlap and each region should only have the units for that race in it.
 
Level 2
Joined
Jun 24, 2019
Messages
13
Alright, nice. Thanks.


No I mean to have a region variable that is an array. Instead of having a different variable for each region (Region1, Region2, etc.) you have one variable and use different indices for each region (Regions[1], Regions[2], etc.). This allows you to do Regions[(Integer A)] instead of having a huge if-block string that’s functioning like a switch/case.

The regions should not overlap and each region should only have the units for that race in it.
 
Status
Not open for further replies.
Top