Random Region Spawn, help

CroMoX

New Member
Reaction score
2
Hey guys I was trying to make a trigger where I buy a unit from the tavern, and randomly move it to one of eight set regions on the map, but I wanted to make it since there are 8 players maximum in the map, another person cannot move to that region, and has to move to an unused region.

This is so everyone will spawn at different regions, no doubling up so they cannot kill each other. I already have my regions put in an array, but when I tried to do the actual trigger I could not work out how to do it, I tried loops with integers but it never worked, and I cannot get my head around how to do it.

Any help would be appreciated.

If you need a better description please ask, and I will try to further extend on it

EDIT: Each player will only have one hero each
 

thorhunter

You can change this now in User CP.
Reaction score
32
Initialization Trigger:
Event - Map Initialization
Actions -
//Set Array of regions:
Region[1]=xxx
.
.
Region[8]=xxx

Hero picking trigger:
Event - Unit enters <region> "Playable map area"
Condition - Triggering unit is a hero = true
Actions -
Move 'Triggering unit' to <center of region> "Region[Player Number of 'Owner of triggering unit']


If players get more heroes later on you should turn off or destroy the triggers as soon as you can or modify the conditions (like check number of heroes player has etc.)
 

CroMoX

New Member
Reaction score
2
Well that is similar to what I want, but I don't want them to have a player specific region like you have, what I was hoping more for was that they had a random chance to move to any region, not their player number region, but another person couldn't move to that one.

E.g a number is randomly made when a character is picked out of 1 - 8, I get 7 and move to the 7th region in the array. Then another person gets a character, and they get a 7 too, I want it so they cannot move there, and that it gets re-rolled.

The part I couldn't do was how to make it find if it's the same region/number rolled, and to random another number and check, until I get one that hasn't been taken.

Thanks for the reply
 

thorhunter

You can change this now in User CP.
Reaction score
32
I see.

Initialization Trigger:

Event - Map Initialization
Actions -
//Set Array of regions:
Region[1]=xxx
.
.
Region[8]=xxx
Set Regions_integer=8


Hero picking trigger:

Event - Unit enters <region> "Playable map area"
Condition - Triggering unit is a hero = true
Actions -
Set Temp_integer=Random number between 1 and Regions_integer
Move 'Triggering unit' to <center of region> Region[Temp_integer]
For loop (Integer A) from 'Temp_integer' to 'Regions_integer -1'
Region[Integer A] = Region[Integer A] +1
Regions_integer=Regions_integer-1
 

CroMoX

New Member
Reaction score
2
Is the variable regions_Integer set to anything in the variables tab? (I mean is it not default 0)

I tried what you got there, and it doesn't work, like it works for a couple of tries then they all just continue spawning at the same area, it doesn't work for the 8 times.

Code:
Move Trigger
    Events
        Unit - A unit Sells a unit
    Conditions
        ((Triggering unit) is A structure) Equal to True
        (Unit-type of (Triggering unit)) Equal to Tavern of the Depths
    Actions
        Set RndInt = (Random integer number between 1 and RegionInteger)
        Custom script:  set bj_wantDestroyGroup = true
        Unit - Move (Sold unit) instantly to (Center of SpawnRegion[RndInt])
        For each (Integer A) from RndInt to (RegionInteger - 1), do (Actions)
            Loop - Actions
                Set SpawnRegion[(Integer A)] = SpawnRegion[((Integer A) + 1)]
                Set RegionInteger = (RegionInteger - 1)
 

afisakov

You can change this now in User CP.
Reaction score
37
Is the variable regions_Integer set to anything in the variables tab? (I mean is it not default 0)

I tried what you got there, and it doesn't work, like it works for a couple of tries then they all just continue spawning at the same area, it doesn't work for the 8 times.

Code:
Move Trigger
    Events
        Unit - A unit Sells a unit
    Conditions
        ((Triggering unit) is A structure) Equal to True
        (Unit-type of (Triggering unit)) Equal to Tavern of the Depths
    Actions
        Set RndInt = (Random integer number between 1 and RegionInteger)
       [B] Custom script:  set bj_wantDestroyGroup = true[/B]
        Unit - Move (Sold unit) instantly to (Center of SpawnRegion[RndInt])
        For each (Integer A) from RndInt to (RegionInteger - 1), do (Actions)
            Loop - Actions
                Set SpawnRegion[(Integer A)] = SpawnRegion[((Integer A) + 1)]
             [B]   Set RegionInteger = (RegionInteger - 1)[/B]

Why do you use wantdestroygroup here? you do not reference a unit group therefore this serves no purpose.

The error in your trigger is that "Set RegionInteger = (RegionInteger - 1)" is not supposed to be in the loop.
The purpose is of the loop is to shift the regions over one space to remove the spot of the used region. After they are all moved, you decrease the regioninteger once to account for having one less region. The way you had it, it dropped to 0 in 2-4 runs, depending on what region it randomed, and then no longer was able to randomize the region.

P.S. ((Triggering unit) is A structure) Equal to True is redundant if you already check unit_type=tavern of depths
 

CroMoX

New Member
Reaction score
2
Ok I will give it a go in a second. I did the wrong thing to remove leaks was meant to set variable and remove location (derp on my part).

EDIT: It worked thank you so much both of you for the help.
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top