• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Unit Leaves a region gets teleported back

Status
Not open for further replies.
Level 4
Joined
Oct 6, 2009
Messages
85
hi i got a question on how do you make when a unit leaves a region the unit get teleported back in the other side or the oposite side like in the picture :fp:

example1g.png


ass you can see the unit leaving the region get teleported back to the oposite side ^^
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
Use minX + maxX - unitX and minY + maxY - unitY.

For example:
  • call SetUnitX(u, minX + maxX - GetUnitX(u))
  • call SetUnitY(u, minY + maxY - GetUnitX(u))
Here's a simple system in JASS:
JASS:
function Exit_Region_Actions takes nothing returns nothing
    local region r = GetTriggeringRegion()
    local integer id = GetHandleId(r)
    local unit u = GetTriggerUnit()
    
    call SetUnitX(u, LoadReal(udg_RectHT, id, 0) + LoadReal(udg_RectHT, id, 2) - GetUnitX(u))
    call SetUnitY(u, LoadReal(udg_RectHT, id, 1) + LoadReal(udg_RectHT, id, 3) - GetUnitY(u))
    
    if GetLocalPlayer() == GetOwningPlayer(u) then
        call SetCameraPosition(GetUnitX(u), GetUnitY(u))
    endif
    
    set r = null
    set u = null
endfunction

function InitRegion takes rect rec returns nothing
    local region r = CreateRegion()
    local integer id = GetHandleId(r)
    
    call SaveReal(udg_RectHT, id, 0, GetRectMinX(rec))
    call SaveReal(udg_RectHT, id, 1, GetRectMinY(rec))
    call SaveReal(udg_RectHT, id, 2, GetRectMaxX(rec))
    call SaveReal(udg_RectHT, id, 3, GetRectMaxY(rec))
    
    call RegionAddRect(r, rec)
    call TriggerRegisterLeaveRegion(udg_ExitRect, r, null)
    
    set r = null
endfunction 

function InitTrig_Exit_Region takes nothing returns nothing
    set udg_RectHT = InitHashtable()
    set udg_ExitRect = CreateTrigger()
    
    call TriggerAddAction(udg_ExitRect, function Exit_Region_Actions )
    
    call InitRegion(gg_rct_ExitRect1)
    call InitRegion(gg_rct_ExitRect2)
    call InitRegion(gg_rct_ExitRect3)
    call InitRegion(gg_rct_ExitRect4)
endfunction


Pastebin link
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
Sorry but I won't make a GUI version.

Create two variables, one trigger variable and one hashtable variable.

Mine are called ExitRect and RectHT. Set the names here. You must add the udg_

JASS:
set udg_RectHT = InitHashtable()
set udg_ExitRect = CreateTrigger()

If you use different names than I did, change all udg_RectHT and udg_ExitRect names to your variable names.

Then create the region and give it some name. Initialize the region like this:
JASS:
call InitRegion(gg_rct_ExitRect1)
Use your variable name and add the gg_rct_

You can remove the four InitRegion() lines that I used.

If you don't want the camera to pan, remove these:
JASS:
if GetLocalPlayer() == GetOwningPlayer(u) then
    call SetCameraPosition(GetUnitX(u), GetUnitY(u))
endif
 
Status
Not open for further replies.
Top