[General] Randomizing Regions

Status
Not open for further replies.
Level 22
Joined
Jul 25, 2009
Messages
3,087
So I run a trigger that spawns shit in a region, then, when someone enters said region, it triggers a bunch of stuff.

What I want to do, is make said region, random, so that, you don't go to the same region every time.

There are two methods I know of, both of which, do not work.

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Random integer number between 1 and 100) Less than or equal to 25
    • Then - Actions
      • Set MissionRegion[1] = Helicopter Roof Landing <gen>
      • Set MissionRegion[2] = Scientist Spawn <gen>
    • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 100) Less than or equal to 25
        • Then - Actions
          • Set MissionRegion[1] = Scientist Spawn 2 <gen>
          • Set MissionRegion[2] = Trucks Area <gen>
        • Else - Actions
This is the first. It does not work, because variables cannot be detected via, a unit enters region.

The second method, is to do this...

  • Region - Center Trucks Area <gen> on (Center of Scientist Spawn 2 <gen>)
Moving regions works, but you can no longer detect entry, when you move a region, entry into that region, will still be detected wherever the region was originally. I.e., you move Region 1 from Point 1 to Point 2, going to Point 2 will not detect entry, but going to Point 1 will, since the region originally resided at Point 1, and due to some Blizzard dick up, you can't move regions 100%.

Does anyone know a workaround, because this is pissing me off.

Thanks in advance.
 
You could just make an entry event for all of those regions, then use a variable to determine which one is active

Like

  • Events
    • A unit enters REGION1
  • Conditions
    • Variable: WhichRegion is equal to 1
  • Actions
  • Events
    • A unit enters REGION2
  • Conditions
    • Variable: WhichRegion is equal to 2
  • Actions
and so on...

So all of them have been set-up, but only 1 region will be "active", depending on the value of the variable...

Or you can also opt to use a single dummy unit, then use the event A unit enters within XXX of unit... then just move that unit elsewhere to change regions... this is assuming, all regions have same size...
 
Can't you just create new regions dynamically? I think you can do it in JASS at least.

JASS:
function makeRegion takes nothing returns region
  local region myRegion = CreateRegion()
  local rect myRect = Rect(GetRandomReal(x,y), GetRandomReal(w,z), GetRandomReal(u,v), GetRandomReal(p,q))
  call RegionAddRect(rect)
  return Region //returns a handle to the randomly created region
endfunction

My understanding (from JASS) is that Regions themselves are just the union of some set of rects (2-d quadrilaterals). So I guess it would make sense that moving a region doesn't really do anything, because the rects that make it up didn't move at all. But I could be completely wrong, as I just started learning this stuff.
 
@seth - Regions in GUI are the Rects of JASS...

Also, his regions are already predetermined so I don't think suggesting to dynamically create regions is a good idea, there's just no point in doing it... anyway, my suggestion I think would be enough for what he wants...

now if he wants it to be SO random, then yeah we can simply dynamically create a new one, destroy old trigger and make a new one for the new region (destroy the old to make it efficient)
 
You could just make an entry event for all of those regions, then use a variable to determine which one is active

Like

  • Events
    • A unit enters REGION1
  • Conditions
    • Variable: WhichRegion is equal to 1
  • Actions
  • Events
    • A unit enters REGION2
  • Conditions
    • Variable: WhichRegion is equal to 2
  • Actions
and so on...

So all of them have been set-up, but only 1 region will be "active", depending on the value of the variable...

Or you can also opt to use a single dummy unit, then use the event A unit enters within XXX of unit... then just move that unit elsewhere to change regions... this is assuming, all regions have same size...

I suppose this is the only decent way.
 
I had a "enter region" system, I modified it a bit.


  • InitR
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: local region r
      • -------- ---------------------------------------------- --------
      • Hashtable - Create a hashtable
      • Set RectHash = (Last created hashtable)
      • -------- ---------------------------------------------- --------
      • Set Trig = EnterR <gen>
      • -------- ---------------------------------------------- --------
      • Set RectEnter[0] = Region 003 <gen>
      • Set RectEnter[1] = Region 003 Copy <gen>
      • Set RectEnter[2] = Region 003 Copy 2 <gen>
      • -------- ---------------------------------------------- --------
      • For each (Integer A) from 0 to 2, do (Actions)
        • Loop - Actions
          • Custom script: set r = CreateRegion()
          • Custom script: call RegionAddRect(r, udg_RectEnter[bj_forLoopAIndex])
          • Custom script: call TriggerRegisterEnterRegion(udg_Trig, r, null)
          • Custom script: call SaveRectHandle(udg_RectHash , GetHandleId(r), 0, udg_RectEnter[bj_forLoopAIndex] )
          • Custom script: call SaveRegionHandle(udg_RectHash , 0, bj_forLoopAIndex, r)
      • -------- ---------------------------------------------- --------
      • Custom script: set r = null
      • -------- ---------------------------------------------- --------
      • Trigger - Run RandomReg <gen> (ignoring conditions)
  • RandomReg
    • Events
    • Conditions
    • Actions
      • Custom script: call SaveRegionHandle(udg_RectHash , 1, 0, LoadRegionHandle(udg_RectHash, 0, GetRandomInt(0, 2)))
  • EnterR
    • Events
    • Conditions
    • Actions
      • Custom script: if GetTriggeringRegion() == LoadRegionHandle(udg_RectHash, 1, 0) then
      • Game - Display to Player Group - Player 1 (Red) for 5.00 seconds the text: ZOMG!
      • Trigger - Run RandomReg <gen> (ignoring conditions)
      • Custom script: endif

Remember to configure the GetRandomInt(0, 2), change the 2 to the max index used in the region array.
 

Attachments

Status
Not open for further replies.
Back
Top