HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Unit leaves region "problem"

06-19-2006, 09:23 PM#1
The_AwaKening
I have a trigger to set a unit invulnerable when entering a region and remove it when the leave the region. Works fine expect when they happen to teleport with archmage out. It doesn't seem to trigger. Is there a way around this, if not, I have another idea to make it work.
06-19-2006, 10:11 PM#2
Rising_Dusk
You could use a timer that constantly checks if they're in the region, and if they aren't it removes the invulnerability and destroys itself.
06-20-2006, 04:10 AM#3
The_AwaKening
My other idea was to put an invis dummy type of unit in that region with an aura that gives invulnerability.

--edit
The more I think about it, your way would be easier and more logical. I just wish the trigger would work without having to run a timer.
06-20-2006, 05:01 AM#4
The_AwaKening
OK, if anyone is bored, here is my current trigger that needs the fixing up. I tried the timer but seem to have problems with it. I've never used timers with periodic functions. I did try, but failed. I'm not familiar with tables either so maybe they could be avoided
Collapse JASS:
function Trig_Ghosting_Actions takes nothing returns nothing
 local unit u=GetTriggerUnit()
    if GetUnitAbilityLevel(u,'Agho')>0 and RectContainsUnit(gg_rct_RecipeAll,u)==false then
        call UnitRemoveAbility(u,'Agho')
        call SetUnitInvulnerable(u,false)
    elseif GetUnitAbilityLevel(u,'Agho')==0 and RectContainsUnit(gg_rct_RecipeAll,u) then
        call UnitAddAbility(u,'Agho')
        call SetUnitInvulnerable(u,true)
    endif
 set u=null
endfunction

//===========================================================================
function InitTrig_Ghosting takes nothing returns nothing
    set gg_trg_Ghosting = CreateTrigger(  )
    call TriggerRegisterLeaveRectSimple( gg_trg_Ghosting, gg_rct_RecipeAll )
    call TriggerRegisterEnterRectSimple( gg_trg_Ghosting, gg_rct_RecipeAll )
    call TriggerAddAction( gg_trg_Ghosting, function Trig_Ghosting_Actions )
endfunction
06-20-2006, 05:41 AM#5
Rising_Dusk
Your current trigger checks once if they are in the rect and then does the effect and never again.
Here, I rewrote it for you.

Collapse JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

//******************************************************************************
//*You'll need to create a global called 'cache' of type gamecache for this to work.
function Cache takes nothing returns gamecache
    if udg_cache==null then
        call FlushGameCache(InitGameCache("GameCache.x"))
        set udg_cache=InitGameCache("GameCache.x")
    endif
    return udg_cache
endfunction

function SetHandleInt takes handle h,string n,integer v returns nothing
    if v==0 then
        call FlushStoredInteger(Cache(),I2S(H2I(h)),n)
    else
        call StoreInteger(Cache(),I2S(H2I(h)),n,v)
    endif
endfunction

function SetHandleHandle takes handle subject,string name,handle value returns nothing
    call SetHandleInt(subject,name,H2I(value))
endfunction

function GetHandleUnit takes handle subject,string name returns unit
    return GetStoredInteger(Cache(),I2S(H2I(subject)),name)
    return null
endfunction

function FlushLocals takes handle subject returns nothing
    call FlushStoredMission(Cache(),I2S(H2I(subject)))
endfunction

//******************************************************************************
//*Above are the handle variable functions you'll need to use for this to work.
//******************************************************************************

function Ghosting_Timer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t, "Ghosting_Unit")
    
    if not RectContainsCoords(gg_rct_RecipeAll, GetUnitX(u), GetUnitY(u)) then
        call UnitRemoveAbility(u, 'Agho')
        call FlushLocals(t)
        call PauseTimer(t)
        call DestroyTimer(t)
    endif
    
    set u = null
    set t = null
endfunction

function Ghosting_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local timer t = CreateTimer()
 
    call UnitAddAbility(u, 'Agho')
    call SetUnitInvulnerable(u, true)
    call SetHandleHandle(t, "Ghosting_Unit", u)
    call TimerStart(t, .033, true, function Ghosting_Timer)
    
    set u = null
    set t = null
endfunction

function InitTrig_Ghosting takes nothing returns nothing
    set gg_trg_Ghosting = CreateTrigger()
    call TriggerRegisterEnterRectSimple(gg_trg_Ghosting, gg_rct_RecipeAll)
    call TriggerAddAction(gg_trg_Ghosting, function Ghosting_Actions)
endfunction

That should work (Even though I didnt test it).
If it doesn't I'll fix whatever I may have done wrong. :/
06-20-2006, 07:21 AM#6
aquilla
The_AwaKening: Does that version work fully or not when a unit blinks/mass teleports? From what I recall it should work (unless perhaps if it's triggered), but I've been having my share of rect/region problems too.. Anyways, I fixed up the code a bit
Collapse JASS:
function Ghosting takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local rect r = gg_rct_RecipeAll
    if GetUnitAbilityLevel(u, 'Agho') > 0 and GetRectMinX(r) <= x and x <= GetRectMaxX(r) and GetRectMinY(r) <= y and y <= GetRectMaxY(r) then
        call UnitRemoveAbility(u, 'Agho')
        call SetUnitInvulnerable(u, false)
    else
        call UnitAddAbility(u, 'Agho')
        call SetUnitInvulnerable(u, true)
    endif
    set u = null
    set r = null
endfunction

//===========================================================================
function InitTrig_Ghosting takes nothing returns nothing
    local trigger t = CreateTrigger()
    local region r = CreateRegion()
    call RegionAddRect(r, gg_rct_RecipeAll)
    call TriggerRegisterEnterRegion(t, r, null)
    call TriggerRegisterLeaveRegion(t, r, null)
    call TriggerAddAction(t, function Ghosting)
    set t = null
    set r = null
endfunction
06-21-2006, 12:34 AM#7
The_AwaKening
It seems to have been happening only with mass teleport. I'm not even quite sure now that it's happening all the time and might be related to something else. Gonna test a bit and I'll get back to you.

--edit
As I tested it a little more, I've come to find that my original trigger is actually ok. There was another bug actually causing it that I've addressed. Thanks for the responses