• 🏆 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!

Placing heroes in diffrent regions

Status
Not open for further replies.
Level 7
Joined
Aug 8, 2008
Messages
340
So I am working on this hero arena map from time to time, but recently I've encountered a problem - a trigger I can't seem to figure out how to make. So I would really appreciate it, if you (my fellow Hiveworker) could explain to me, how to make it.
(preferable without leaks)
(I'm not using GUI or Jass)

The trigger will be used whenever a match is about to begin, placing the heroes in diffrent areas of the arena.

The trigger:
timer expires
pick every hero in region
move picked hero to a random region (1 out of 8) without heroes being placed in the same region.

it's setting up the 8 diffrent regions trigger-wise and making sure the heroes can't be moved to the same region, which seems to be the most diffecult part of the trigger to me.
 
Level 25
Joined
Sep 26, 2009
Messages
2,373
(I'm not using GUI or Jass)
Wrong on both accounts I guess?
Jass is the scripting language wc3 triggers use and GUI stands for "Graphical User Interface" - it is the graphical representation of Jass (tho it misses many functions pure jass has). The pseudo-code you posted seems to be of GUI nature, so you're basically using jass without knowing it :)

Anyway, back to your issue. What I would do is simply swap regions and decrement the range of the random number.
Look at this:
  • Set reg[1] = Region<01>
  • Set reg[2] = Region<02>
  • Set reg[3] = Region<03>
  • Set reg[4] = Region<04>
I just used 4 regions for simplicity. Now do this:

  • Set int_num = Random number between 1 and 4
Notice I saved the value into a variable.

Now I move the hero to reg[int_num]. Next thing I do, I swap the region on index int_num with last region. Let's say int_num is number 2.
set reg[1] = Region<01>
set reg[2] = Region<02>
set reg[3] = Region<03>
set reg[4] = Region<04>
and swap the two colored ones:
set reg[1] = Region<01>
set reg[2] = Region<04>
set reg[3] = Region<03>
set reg[4] = Region<02>

By decrementing the max range of the random number by 1, I basically do this:
set reg[1] = Region<01>
set reg[2] = Region<04>
set reg[3] = Region<03>
set reg[4] = Region<02>

Now all I do is pick random number between 1 and 3! I decremented the range by 1, because under index 4 is the already used region. When I choose the second region, I swap it with the last unused region (in this case, the currently last unused region is region under index 3) and decrement the range by 1 again.
To know which region you need to swap, you need the int_num variable to refer to that region.

check this:
  • Region selection
    • Events
    • Conditions
    • Actions
      • -------- Initialization on match start --------
      • Set max_region = 8
      • -------- - you can even set here regions anew if needed or use ITE block if they are not yet created --------
      • -------- /////////////////////////// --------
      • -------- I just assumed here there will be 4 heroes matched up, hence the 'to 4' loop --------
      • For each (Integer loop_var) from 1 to 4, do (Actions)
        • Loop - Actions
          • Set index = (Random integer number between 1 and max_region)
          • Unit - Move hero[loop_var] instantly to reg[index]
          • -------- /////////////////////////// --------
          • -------- I save the region here into slot #9, because that slot will never be used by any region (since max_region is 8 or less) --------
          • Set reg[9] = reg[index]
          • Set reg[index] = reg[max_region]
          • Set reg[max_region] = reg[9]
          • Set max_region = (max_region - 1)
A side note: I advise using points instead of regions to prevent unnecessary memory leaks. In the trigger above, the array reg is actually variable of type "point", not "region".
 
Level 7
Joined
Aug 8, 2008
Messages
340
Ahh sorry, I've never been very good with the whole trigger thing. ;) I've just recently learned how to use dummy units. :p

I am working on it as we speak. I get the part of removing the 'occupied' regions from the equation. However, I do not know how to pick the random generated region and than remove it in that way. Could you be a little more specific?

This is what I've got so far:
 

Attachments

  • Unavngivet.png
    Unavngivet.png
    13.7 KB · Views: 126
Level 25
Joined
Sep 26, 2009
Messages
2,373
It's all shown in the trigger in my post. Basically you use the "Set variable" option. In this option you select an integer variable (if you don't have one, create it) and you set into this variable the "Math - Random number between 1 and X)". X is your second integer variable (in my example it's called max_regions). Now you use the variable that has the random number as index in the array.

It all depends on how many heroes are matched up too! If you just match two heroes, you can simplify the trigger a bit and do it more manually. If there are too many heroes, you should automatize it like in my example.


Also watch out, the "Center of region" option causes memory leaks (these lag your game over time when too many leaks pile up). Check this thread to understand how to remove them: http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/
 
Status
Not open for further replies.
Top