• 🏆 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] Any better solution for the detect leaving region?

Status
Not open for further replies.
Level 17
Joined
Jun 2, 2009
Messages
1,123
Description: When unit leaves the region, triggering units orders center of the leaving region.

  • OrmanRegen
    • Events
      • Unit - A unit leaves NcUstCheck6 <gen>
      • Unit - A unit leaves NcUstCheck5 <gen>
      • Unit - A unit leaves NcUstCheck4 <gen>
      • Unit - A unit leaves NcUstCheck3 <gen>
      • Unit - A unit leaves NcUstCheck2 <gen>
      • Unit - A unit leaves NcUstCheck1 <gen>
      • Unit - A unit leaves NcAltCheck6 <gen>
      • Unit - A unit leaves NcAltCheck5 <gen>
      • Unit - A unit leaves NcAltCheck4 <gen>
      • Unit - A unit leaves NcAltCheck3 <gen>
      • Unit - A unit leaves NcAltCheck2 <gen>
      • Unit - A unit leaves NcAltCheck1 <gen>
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • Unit - Create 1 DUMMY [JFA] for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees
      • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
      • Unit - Add Rejuvenation // dummy to (Last created unit)
      • Unit - Order (Last created unit) to Night Elf Druid Of The Claw - Rejuvenation (Triggering unit)
I am regenerating leaving unit for the prevent kite but i want to order unit to move region. Is there a simple way to do that instead of creating 12 duplicate triggers (1 for each region)?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,511
Regions are a little bit buggy so I would first fix them using what I suggest here: [JASS] - Region to rect

Then I would create an Array of your Nc Regions. You can throw this in one of your other "setup" triggers:
  • Set Variable NcRegion[1] = ...
  • Set Variable NcRegion[2] = ...
  • Set Variable NcRegion[3] = ...
And then when a unit Enters one of your Nc Regions you can link the two together using a Unit Indexer or Hashtable:
  • Events
    • Unit - A unit enters ...
  • Conditions
    • (Owner of (Triggering unit)) Equal to Neutral Hostile
  • Actions
    • Set Variable NcUnit = (Triggering unit)
    • For each (NcLoop) from 1 to 12 do (Actions)
      • Loop - Actions
        • If (NcUnit is in NcRegion[NcLoop] Equal to True) then
          • Set Variable NcUnitRegion[(Custom value of NcUnit)] = NcRegion[NcLoop]
          • Custom script: exitwhen true
        • Else
Now when a unit Leaves one of your Nc Regions you can just tell them to go back to it:
  • Events
    • Unit - A unit leaves ...
  • Conditions
    • (Owner of (Triggering unit)) Equal to Neutral Hostile
  • Actions
    • Set Variable NcUnit = (Triggering unit)
    • Set Variable NcPoint = (Center of NcUnitRegion[(Custom value of NcUnit)]
    • Unit - Order NcUnit to Move To NcPoint
    • Custom script: call RemoveLocation(udg_NcPoint)
You could possibly combine the Enters/Leaves trigger together to help keep things simple. The idea would be that if the unit isn't in one of the 12 NcRegions then you know it's leaving. So in the Else - Actions you can order NcUnit to Move back to it's NcUnitRegion.
 
Last edited:
Level 17
Joined
Jun 2, 2009
Messages
1,123
@Uncle Thank you very much but i cannot find it.

line.gif
join.gif
set.gif
Set Variable NcUnitRegion[(Custom value of NcUnit)] = NcRegion[NcLoop]

= Part is looking as integer and i can convert it real and string. How to conver it to Region? I have no idea
NcUnitRegion = Integer Array
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,511
Both NcRegion and NcUnitRegion are Region variable arrays. NcUnit is a Unit variable. NcLoop is an Integer variable. NcPoint is a Point variable.

You need to create all of these variables yourself.

Here's the Unit Indexer system I'm using to make the triggers work: GUI Unit Indexer 1.4.0.0

You only want ONE Unit Indexer in your map, so don't import it if you already have one. It will also override the Custom Value of your units so if you were manually using Custom Value in your triggers then that's going to be a problem. The good news is that the Unit Indexer removes the need for you to ever manually set custom value yourself, you can instead rely on the system and use variables as a replacement to custom value.
 
Last edited:
Level 17
Joined
Jun 2, 2009
Messages
1,123
@Uncle Wow it worked :D Honestly i don't understand how it that works but it is working. It looks extremely confusing to me and i don't think my brain can handle this one but it works :) Thank you for your help again hero without cape.

I am using this UnitIndexer (Bribe's DDS) for DDS, i hope it will not causes any issues with DDS system..

Unit Indexer
Events
Map initialization
Conditions
Actions
Custom script: call ExecuteFunc("InitializeUnitIndexer")
Custom script: endfunction
Custom script:
Custom script: function ClearUnitIndex takes nothing returns nothing
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Custom value of UDexUnits[UDex]) Equal to 0
Then - Actions
Set UnitIndexLock[UDex] = (UnitIndexLock[UDex] - 1)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
UnitIndexLock[UDex] Equal to 0
Then - Actions
Set UDexNext[UDexPrev[UDex]] = UDexNext[UDex]
Set UDexPrev[UDexNext[UDex]] = UDexPrev[UDex]
Set UDexPrev[UDex] = 0
Set UnitIndexEvent = 0.00
Set UnitIndexEvent = 2.00
Set UnitIndexEvent = 0.00
Set UDexUnits[UDex] = No unit
Set UDexNext[UDex] = UDexRecycle
Set UDexRecycle = UDex
Else - Actions
Else - Actions
Custom script: endfunction
Custom script:
Custom script: function IndexUnit takes nothing returns boolean
Custom script: local integer pdex = udg_UDex
Custom script: local integer ndex
-------- - --------
-------- You can customize the following block - if conditions are false the (Matching unit) won't be indexed. --------
-------- - --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
UnitIndexerEnabled Equal to True
(Custom value of (Matching unit)) Equal to 0
Then - Actions
Set UDexWasted = (UDexWasted + 1)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
UDexWasted Equal to 32
Then - Actions
Set UDexWasted = 0
Set UDex = UDexNext[0]
Custom script: loop
Custom script: exitwhen udg_UDex == 0
Custom script: set ndex = udg_UDexNext[udg_UDex]
Custom script: call ClearUnitIndex()
Custom script: set udg_UDex = ndex
Custom script: endloop
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
UDexRecycle Equal to 0
Then - Actions
Set UDex = (UDexGen + 1)
Set UDexGen = UDex
Else - Actions
Set UDex = UDexRecycle
Set UDexRecycle = UDexNext[UDex]
Set UDexUnits[UDex] = (Matching unit)
Unit - Set the custom value of UDexUnits[UDex] to UDex
Set UDexPrev[UDexNext[0]] = UDex
Set UDexNext[UDex] = UDexNext[0]
Set UDexNext[0] = UDex
Set UnitIndexLock[UDex] = 1
Set UnitIndexEvent = 0.00
Set UnitIndexEvent = 1.00
Set UnitIndexEvent = 0.00
Custom script: set udg_UDex = pdex
Else - Actions
Custom script: return false
Custom script: endfunction
Custom script:
Custom script: function InitializeUnitIndexer takes nothing returns nothing
Custom script: local integer i = bj_MAX_PLAYER_SLOTS
Custom script: local boolexpr b = Filter(function IndexUnit)
Custom script: local region re = CreateRegion()
Custom script: local trigger t = GetTriggeringTrigger()
Custom script: local rect r = GetWorldBounds()
Custom script: call RegionAddRect(re, r)
Custom script: call TriggerRegisterEnterRegion(t, re, b)
Custom script: call TriggerClearActions(t)
Custom script: call TriggerAddAction(t, function ClearUnitIndex)
Set UnitIndexerEnabled = True
Custom script: loop
Custom script: set i = i - 1
Custom script: call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, Player(i), b)
Custom script: exitwhen i == 0
Custom script: endloop
Custom script: call RemoveRect(r)
Custom script: set re = null
Custom script: set r = null
Custom script: set t = null
Custom script: set b = null
Set UnitIndexEvent = 3.00
Set UnitIndexEvent = 0.00
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,511
Glad it works, but if you're saying that you already had a Unit Indexer in your map then DO NOT import the one I linked. You should only have ONE unit indexer in your map at a time, because that's all you need.

Understand that a Unit Indexer is a very simple system. All it does is assign a unique Custom Value to each of your units, whether they are preplaced on the map or created later on.

Custom Value is an Action that you may have seen before. It lets you save an Integer to a Unit and can be used for many different things.

So let's say you only had 10 Footman in your map. The Unit Indexer system would give each one of those Footman a Custom Value between 1 and 10. No two Footman will EVER have the same Custom Value.

Now that we know each unit has it's own unique Integer (custom value), we can start to take advantage of that.

By using Variable Arrays we can save as much data as we want to our units. Here's an example:
  • Events
    • Time - Elapsed game time is 0.01 seconds
  • Conditions
  • Actions
    • Unit - Create 1 Paladin...
    • Set Variable FireDamage[Custom value of (Last created unit)] = 100
    • Set Variable ColdDamage[Custom value of (Last created unit)] = 200
    • Set Variable LightningDamage[Custom value of (Last created unit)] = 300
    • Unit - Create 1 Archmage...
    • Set Variable FireDamage[Custom value of (Last created unit)] = 25
    • Set Variable ColdDamage[Custom value of (Last created unit)] = 50
    • Set Variable LightningDamage[Custom value of (Last created unit)] = 75
In the above trigger I've created some Integer arrays (FireDamage, ColdDamage, LightningDamage) which are meant to track how much elemental damage my unit's deal. I've given the Paladin 100 Fire Damage, 200 Cold Damage, and 300 LightningDamage. I've given the Archmage 25 Fire Damage, 50 Cold Damage, and 75 Lightning Damage.

So using this method I was able to create new stats for my units. This is great for making RPGs since you may want more stats than just Strength, Agility, and Intelligence.

Now let's say my Archmage has a spell called Fireball which deals damage to an enemy unit. I could use his FireDamage stat to calculate the damage dealt:
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Fireball
  • Actions
    • Unit - Cause (Casting unit) to deal FireDamage[Custom value of (Casting unit)] to (Target unit of ability being cast)...
This will deal 25 damage to the enemy unit since we gave our Archmage 25 FireDamage[]. If our Paladin were to cast Fireball he would deal 100 damage since that's how much FireDamage[] he has.

We've now created an Ability Power system which should be familiar if you've ever played League of Legends before.

And it doesn't stop there, you can use any type of Variable Array, it doesn't just have to be an Integer. This can be useful for keeping track of Special Effects that are attached to Units that you want to delete later on. It can be used with Booleans to remember different states about your unit -> Is my unit in town? Is my unit a boss? It can be used to save just about anything you want to a Unit.
 
Last edited:
Level 17
Joined
Jun 2, 2009
Messages
1,123
@Uncle You are definitely hero without cape to me. I really appreciate you. By the way i was never talked about myself.

I am 38 years old and still i am active. I have a MOBA map (language is Türkçe/Turkish) and playing with my friends. My MOBA map is 21 years old (i have created it when RoC is out 2002) and created many different maps.

And also i have a few maps in Reforged and one of them uploaded to hive (world war risk but nobody plays and i am not updating) and working with outdated + reforged editor this is why i was created topic like this "when i opened reforged editor, no more open 1.26 editor again" because i am using both 1.26 and reforged editors.

Anyway i just wanted to talk about myself. I hope you will get what do you want in your life.
 
Status
Not open for further replies.
Top