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

[Solved] Possible to Reference Region / Rect Name?

Status
Not open for further replies.
Level 13
Joined
Mar 24, 2013
Messages
1,105
You just need to create a catalog to reference the data you are seeking:

In a config trigger:

set Regions[1] = myRegion
set Regions[2] = myRegion2

set Sound[1] = mySound
set Sound[2] = mySound2

Unit Enters Region

Detect which region was entered.

Knowing which region was entered will let you know which index is correct.

This index will then let you play the proper sound.


For example:

Unit Enters Region

Detected myRegion/Regions[1]

The index of [1] means
Play sound: Sound[1]
 
Level 13
Joined
Mar 24, 2013
Messages
1,105
No there is no such function.

You will add each one to your trigger likely from the config trigger.

set regionCount = regionCount + 1
set Regions[regionCount] = myRegion (The index is still 1, provided regionCount is 0)
set regionCount = regionCount + 1 (The index is still 2)
set Regions[regionCount] = myRegion2

You would do the same for sounds, making sure the indexes line up properly.

After that you will have a loop:

For Each tempInt from 1 to regionCount

Add the Event to your trigger:
Unit Enters Regions[tempInt]

However, you could also just have a stack of them in the event section, although more than a few might be tedious.

In the other trigger (unit enters) your events will be blank as we added them in the config trigger.

In the actions sections you will loop similar to above, through your catalog/list of regions to determine which one fired.

As before, once we know which one fired, we check the index to get the sound desired.

again in pseudo code it would be

For Each tempInt from 1 to regionCount

if Unit entered Regions[tempInt] then
PlaySound[tempInt]
Do anything else you want here.
Then Skip remaining actions because we already found the region
else
--blank-- continue searching.

Forgive the formatting, on my phone.

Also, if I am remembering right, regions are forced to conform to some specific size interval, so this method is likely not ideal should you need hyper precision.

If you need that precision, you would need to use Rects, which are not available in GUI. Then track the potential units coordinates and compare them to the min/Max of the rects to determine when they entered.
 
Level 13
Joined
Mar 24, 2013
Messages
1,105
Okay, I took a look at it and found some things.

Mainly that thing I had mentioned earlier about the size of regions being off in game was half right. So it turns out, they don't need to be a specific size interval, but rather they are slightly shifted from where they are preplaced.

So I did some digging on Hive to see if someone had figured how much they were shifted by. [General] - game does not realise when region contains unit

From what I understand, the event would fire, but when it did the check to see if the unit was contained in the region it could fail because the coordinates of the unit would be falling outside of the shifted region. This lead to region contains unit failing.

So, if we shift the regions back, we should have no problem.

I did some testing and could not get it to fail now, but double check.

I also moved the regions around because when I first tested it I was thinking they were overlapping somehow, but that was a by product of unknown shift.

I suspect you'll also need to look up a tutorial on GetLocalPlayer() so you can play these sounds to a specific player rather than everyone.

  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set PlayersCurrentSong[1] = 0
      • Set PlayersCurrentSong[2] = -1
      • Set Hero = Knight 0000 <gen>
      • Set GenLoopCount = 1
      • Set RegionNum[GenLoopCount] = 1 <gen>
      • Set SongNum[GenLoopCount] = Doom <gen>
      • Set GenLoopCount = (GenLoopCount + 1)
      • Set RegionNum[GenLoopCount] = 2 <gen>
      • Set SongNum[GenLoopCount] = PursuitTheme <gen>
      • Set GenLoopCount = (GenLoopCount + 1)
      • Set RegionNum[GenLoopCount] = 3 <gen>
      • Set SongNum[GenLoopCount] = SadMystery <gen>
      • Set GenLoopCount = (GenLoopCount + 1)
      • Set RegionNum[GenLoopCount] = 4 <gen>
      • Set SongNum[GenLoopCount] = Tension <gen>
      • Set GenLoopCount = (GenLoopCount + 1)
      • Set RegionNum[GenLoopCount] = 5 <gen>
      • Set SongNum[GenLoopCount] = TragicConfrontation <gen>
      • For each (Integer TempInt) from 1 to GenLoopCount, do (Actions)
        • Loop - Actions
          • Trigger - Add to Region Ent Trigger <gen> the event (Unit - A unit enters RegionNum[TempInt])
          • Custom script: call SetRect(udg_RegionNum[udg_TempInt], GetRectMinX(udg_RegionNum[udg_TempInt]) - 32., GetRectMinY(udg_RegionNum[udg_TempInt]) - 32., GetRectMaxX(udg_RegionNum[udg_TempInt]) + 32., GetRectMaxY(udg_RegionNum[udg_TempInt]) + 32.) (This is the preplaced region correction)
  • Region Ent Trigger
    • Events
    • Conditions
    • Actions
      • For each (Integer TempInt) from 1 to GenLoopCount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (RegionNum[TempInt] contains Hero) Equal to True
            • Then - Actions
              • Game - Display to (All players) the text: (String(TempInt))
              • Sound - Stop SongNum[PlayersCurrentSong[(Player number of (Triggering player))]] Immediately
              • Sound - Play SongNum[TempInt]
              • Set PlayersCurrentSong[(Player number of (Triggering player))] = TempInt
              • Skip remaining actions
            • Else - Actions
 

Attachments

  • Spark 6, Sound Test.w3x
    17.3 KB · Views: 25
Wow you are diligent, I never would have guessed that regions had that issue and I'll have to see what to do about that. I likewise didn't experience any failure in your version, and I do know about localplayer but thanks for bringing it up in case I didn't! Thanks again Poke!

In one of my versions the check was being manifest on a low occurrence periodic trigger, such a check would lower the responsiveness of the soundtrack swap, but altogether function decently since in this map it will only be checking 4 units max.
 
Status
Not open for further replies.
Top