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

Does "Region - Move" Work?

Status
Not open for further replies.
Level 6
Joined
Dec 9, 2014
Messages
176
So I have a simple bag system that involves hero units with a chest model that can't move or attack and is invulnerable and uses their inventory as sort of a backpack. The ability "Open Backpack" simply moves the backpack to the character and changes it's ownership from Neutral Passive to Red, allowing the player to use the backpack as need for items. It works fine as it is currently, but the problem is "closing" the backpack.

I decided to designate an area of the map the player will never see as sort of a holding area for the backpack bags when they are not "open". I tried to make it so that when the player opens the backpack the bag is moved to where the player is and so is a region moved and centered on the player. When the player leaves the region (assuming they are done with the backpack) the bags should then be changed back to the ownership of Neutral Hostile and moved back to their holding area. So far I haven't been able to get this to work. Any help would be much appreciated!


  • Summon Stash
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Open Backpack (New)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Open Backpack (New) for (Triggering unit)) Equal to 1
        • Then - Actions
          • Unit - Move Bag 1 0150 <gen> instantly to (Center of (Region centered at (Position of (Triggering unit)) with size (300.00, 300.00))), facing (Facing of (Triggering unit)) degrees
          • Unit - Change ownership of Bag 1 0150 <gen> to Player 1 (Red) and Retain color
          • Wait 0.10 seconds
          • Region - Center Close Backpack <gen> on (Position of Bag 1 0150 <gen>)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Open Backpack (New) for (Triggering unit)) Equal to 2
        • Then - Actions
          • Unit - Move Bag 1 0150 <gen> instantly to (Center of (Region centered at (Position of (Triggering unit)) with size (100.00, 100.00))), facing (Facing of (Triggering unit)) degrees
          • Unit - Change ownership of Bag 1 0150 <gen> to Player 1 (Red) and Retain color
          • Unit - Move Bag 2 0151 <gen> instantly to (Center of (Region centered at (Position of (Triggering unit)) with size (100.00, 100.00))), facing (Facing of (Triggering unit)) degrees
          • Unit - Change ownership of Bag 2 0151 <gen> to Player 1 (Red) and Retain color
          • Wait 0.10 seconds
          • Region - Center Close Backpack <gen> on (Position of Bag 1 0150 <gen>)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Open Backpack (New) for (Triggering unit)) Equal to 3
        • Then - Actions
          • Unit - Move Bag 1 0150 <gen> instantly to (Center of (Region centered at (Position of (Triggering unit)) with size (100.00, 100.00))), facing (Facing of (Triggering unit)) degrees
          • Unit - Change ownership of Bag 1 0150 <gen> to Player 1 (Red) and Retain color
          • Unit - Move Bag 2 0151 <gen> instantly to (Center of (Region centered at (Position of (Triggering unit)) with size (100.00, 100.00))), facing (Facing of (Triggering unit)) degrees
          • Unit - Change ownership of Bag 2 0151 <gen> to Player 1 (Red) and Retain color
          • Unit - Move Bag 3 0152 <gen> instantly to (Center of (Region centered at (Position of (Triggering unit)) with size (100.00, 100.00))), facing (Facing of (Triggering unit)) degrees
          • Unit - Change ownership of Bag 3 0152 <gen> to Player 1 (Red) and Retain color
        • Else - Actions
  • Return Stash
    • Events
      • Unit - A unit leaves Close Backpack <gen>
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 1 (Red)
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Wait 0.10 seconds
      • Unit - Change ownership of Bag 1 0150 <gen> to Neutral Passive and Retain color
      • Unit - Change ownership of Bag 2 0151 <gen> to Neutral Passive and Retain color
      • Unit - Change ownership of Bag 3 0152 <gen> to Neutral Passive and Retain color
      • Unit - Change ownership of Bag 4 0153 <gen> to Neutral Passive and Retain color
      • Unit - Change ownership of Bag 5 0149 <gen> to Neutral Passive and Retain color
      • Unit - Change ownership of Bag 6 0154 <gen> to Neutral Passive and Retain color
      • Unit - Move Bag 1 0150 <gen> instantly to (Center of Backpack Home <gen>)
      • Unit - Move Bag 2 0151 <gen> instantly to (Center of Backpack Home <gen>)
      • Unit - Move Bag 3 0152 <gen> instantly to (Center of Backpack Home <gen>)
      • Unit - Move Bag 4 0153 <gen> instantly to (Center of Backpack Home <gen>)
      • Unit - Move Bag 5 0149 <gen> instantly to (Center of Backpack Home <gen>)
      • Unit - Move Bag 6 0154 <gen> instantly to (Center of Backpack Home <gen>)
      • Wait 0.10 seconds
      • Region - Center Close Backpack <gen> on (Center of Close Backpack Home <gen>)
  • Level Up Stash
    • Events
      • Unit - A unit Gains a level
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 1 (Red)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Hero level of (Triggering unit)) Equal to 10
        • Then - Actions
          • Unit - Set level of Open Backpack (New) for (Triggering unit) to 2
          • Game - Display to Player Group - Player 1 (Red) the text: |cffffcc00Your Back...
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Hero level of (Triggering unit)) Equal to 20
        • Then - Actions
          • Unit - Set level of Open Backpack (New) for (Triggering unit) to 3
          • Game - Display to Player Group - Player 1 (Red) the text: |cffffcc00Your Back...
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Hero level of (Triggering unit)) Equal to 30
        • Then - Actions
          • Unit - Set level of Open Backpack (New) for (Triggering unit) to 4
          • Game - Display to Player Group - Player 1 (Red) the text: |cffffcc00Your Back...
        • Else - Actions
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
why yes it does.
  • Wait 0.10 seconds
broken. remove all of these.

you forgot to center the location if level of abil == 3

your level up script wont work if the player skips a level (e.g. 9 straight to 11 thru a quest or smth)

are you sure Close Backpack <gen> isnt huge

other than that your code's fine (besides the obnoxious amount of leaks) whats not working
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Region - Move does work but what GUI users do not know is that there is no direct Enter/Leave event type for GUI regions. The events in the events block are being created at map init and Enter/Leave basically make a copy of the GUI region to transform it into a jass region, which is another type and the direct events exist for them. So if you call Region - Move, it will not affect the jass region the event is made up with.
 
Level 6
Joined
Dec 9, 2014
Messages
176
why yes it does.
  • Wait 0.10 seconds
broken. remove all of these. you forgot to center the location if level of abil == 3 your level up script wont work if the player skips a level (e.g. 9 straight to 11 thru a quest or smth) are you sure Close Backpack <gen> isnt huge other than that your code's fine (besides the obnoxious amount of leaks) whats not working

Actually, weird thing is, I found that it won't even move the backpack units without those waits. I don't know why for sure but my logic is that the game is missing something and needs more time to figure stuff out, so I gave it a couple of small waits and it works. I don't think the problem of a level skip should ever be an issue. I have the experience gained from kills turned way down and quests as never worth more than a full level, at most they may be worth a 3rd of a level. Close Backpack Region is not big at all, maybe 500 by 500. As for the leaks, it's a single player map and so far I have put many hours into testing and what not and it never lags or crashes or anything. Hell, I set my character on a patrol and let it run all night just killing stuff and it never lagged or anything.

WaterKnight, I'm not sure what I should do then. Would a trigger turn off/on do any good?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
You can register new events during runtime but you cannot clear a trigger of its events without destroying the trigger. So this would require jass.

You could adjust the jass region, which of course you would need jass for as well.

Instead of using Enter/Leave events, you can periodically check nearby units and keep track of them in a unit group.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,199
There are no natives to move regions.

To move a region constructed from a single rect you can do the following...

1. Clear the rect area from the region.
2. Move the constructing rect to the new position of the region.
3. Add the rect area to the region.

I am not sure if altering regions after event creation will affect the area registered by the event however in theory it should.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
It does but adding/removing cells does not trigger enter/leave events for units that are currently within the changed area, which is why you should additionally pick units/keep track of them and check whether they are now/still within. There is a function IsUnitInRegion.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
ooh ur right :D forgots about tha.

so basically every 0.25 seconds check if the player is in rect. if not, than exit backpack
 
Level 6
Joined
Dec 9, 2014
Messages
176
Cool beans! I'll try that!

Edit: Actually could someone make a small example of that? I don't need a big thing just a starter. I've never made a trigger that periodically checks for things lol.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
  • every o.o3 seconds
  • conditions : backpack is open
  • actions : if unit isnt in region <packpack region> then
  • do shit
  • set backpack is open = false
  • endif
 
Level 6
Joined
Dec 9, 2014
Messages
176
So I got it to work finally, yay! After many failed attempts I decided to ditch the premade region and instead had the game make one around the backpack and it works. When hittng the "Open Backpack" ability, it turns on this trigger:

  • Return Stash
    • Events
      • Time - Every 0.25 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Sorceress Not equal to No unit
          • ((Region centered at (Position of Bag 1 0150 <gen>) with size (500.00, 500.00)) contains Sorceress) Equal to False
        • Then - Actions
          • Unit - Change ownership of Bag 1 0150 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 2 0151 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 3 0152 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 4 0153 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 5 0149 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 6 0154 <gen> to Neutral Passive and Retain color
          • Unit - Move Bag 1 0150 <gen> instantly to (Center of Backpack Home <gen>)
          • Unit - Move Bag 2 0151 <gen> instantly to (Center of Backpack Home <gen>)
          • Unit - Move Bag 3 0152 <gen> instantly to (Center of Backpack Home <gen>)
          • Unit - Move Bag 4 0153 <gen> instantly to (Center of Backpack Home <gen>)
          • Unit - Move Bag 5 0149 <gen> instantly to (Center of Backpack Home <gen>)
          • Unit - Move Bag 6 0154 <gen> instantly to (Center of Backpack Home <gen>)
          • Game - Display to Player Group - Player 1 (Red) the text: |cffffcc00Backpack ...
          • Trigger - Turn off (This trigger)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Wizard Not equal to No unit
          • ((Region centered at (Position of Bag 1 0150 <gen>) with size (500.00, 500.00)) contains Wizard) Equal to False
        • Then - Actions
          • Unit - Change ownership of Bag 1 0150 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 2 0151 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 3 0152 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 4 0153 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 5 0149 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 6 0154 <gen> to Neutral Passive and Retain color
          • Unit - Move Bag 1 0150 <gen> instantly to (Center of Backpack Home <gen>)
          • Unit - Move Bag 2 0151 <gen> instantly to (Center of Backpack Home <gen>)
          • Unit - Move Bag 3 0152 <gen> instantly to (Center of Backpack Home <gen>)
          • Unit - Move Bag 4 0153 <gen> instantly to (Center of Backpack Home <gen>)
          • Unit - Move Bag 5 0149 <gen> instantly to (Center of Backpack Home <gen>)
          • Unit - Move Bag 6 0154 <gen> instantly to (Center of Backpack Home <gen>)
          • Game - Display to Player Group - Player 1 (Red) the text: |cffffcc00Backpack ...
          • Trigger - Turn off (This trigger)
        • Else - Actions
Thank you guys so much for helping me with this! I will be uploading v0.4 in the Map Development section shortly.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Convert Point With Size To Region creates a new (GUI) region everytime. So you leak 2 of them per 0.25 seconds. Same for the bunch of Center Of Region and Position Of Unit calls. They create new locations. It would be advisable to clean them up.

  • Return Stash
    • Events
      • Time - Every 0.25 seconds of game time
    • Conditions
    • Actions
      • Set bagLoc = (Position of Bag 1 0150 <gen>)
      • Set bagRect = (Region centered at bagLoc with size (500.00, 500.00))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Sorceress Not equal to No unit
          • (bagRect contains Sorceress) Equal to False
        • Then - Actions
          • Unit - Change ownership of Bag 1 0150 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 2 0151 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 3 0152 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 4 0153 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 5 0149 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 6 0154 <gen> to Neutral Passive and Retain color
          • Set backpackHomeLoc = (Center of Backpack Home <gen>)
          • Unit - Move Bag 1 0150 <gen> instantly to backpackHomeLoc
          • Unit - Move Bag 2 0151 <gen> instantly to backpackHomeLoc
          • Unit - Move Bag 3 0152 <gen> instantly to backpackHomeLoc
          • Unit - Move Bag 4 0153 <gen> instantly to backpackHomeLoc
          • Unit - Move Bag 5 0149 <gen> instantly to backpackHomeLoc
          • Unit - Move Bag 6 0154 <gen> instantly to backpackHomeLoc
          • Custom script: call RemoveLocation(udg_backpackHomeLoc)
          • Game - Display to Player Group - Player 1 (Red) the text: |cffffcc00Backpack ...
          • Trigger - Turn off (This trigger)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Wizard Not equal to No unit
          • (bagRect contains Wizard) Equal to False
        • Then - Actions
          • Unit - Change ownership of Bag 1 0150 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 2 0151 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 3 0152 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 4 0153 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 5 0149 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Bag 6 0154 <gen> to Neutral Passive and Retain color
          • Set backpackHomeLoc = (Center of Backpack Home <gen>)
          • Unit - Move Bag 1 0150 <gen> instantly to backpackHomeLoc
          • Unit - Move Bag 2 0151 <gen> instantly to backpackHomeLoc
          • Unit - Move Bag 3 0152 <gen> instantly to backpackHomeLoc
          • Unit - Move Bag 4 0153 <gen> instantly to backpackHomeLoc
          • Unit - Move Bag 5 0149 <gen> instantly to backpackHomeLoc
          • Unit - Move Bag 6 0154 <gen> instantly to backpackHomeLoc
          • Custom script: call RemoveLocation(udg_backpackHomeLoc)
          • Game - Display to Player Group - Player 1 (Red) the text: |cffffcc00Backpack ...
          • Trigger - Turn off (This trigger)
        • Else - Actions
    • Custom script: call RemoveLocation(udg_bagLoc)
    • Custom script: call RemoveRect(udg_bagRect)
 
Level 6
Joined
Dec 9, 2014
Messages
176
I see, so weird the game doesn't have an automatic remove for things like this to avoid creating tons of regions and what not. Thanks for the help!
 
Status
Not open for further replies.
Top