Checking if unit reaches a point

Roku

New Member
Reaction score
3
Hey, i used to work with JASS (vJass also) pretty much but then i stopped making maps and now when i started to make a new map i used GUI most of time. However i had problems with this trigger of mine so rewriting it in JASS seemed a good solution. It did work out much better too. Basically i am looking forward to people helping me improving this trigger, and maybe telling me if there's anything wrong, and maybe how to fix it. Well in-game the trigger runs almost as it is supposed to. I'll post it first:

JASS:
function Actions takes nothing returns nothing
    local unit wisp
    local location p
    call AddSpecialEffectLocBJ( GetRectCenter(gg_rct_P4_Boss_Pos), "Abilities\\Spells\\NightElf\\MoonWell\\MoonWellCasterArt.mdl" )
    call DestroyEffect( bj_lastCreatedEffect )
    call CreateNUnitsAtLoc( 1, 'e001', Player(11), GetRectCenter(gg_rct_P4_Boss_Pos), bj_UNIT_FACING )
    set wisp = bj_lastCreatedUnit
    call UnitAddAbility( wisp, 'A011')
    set p = GetUnitLoc(udg_Boss)
    call IssuePointOrderLoc( wisp, "move", p )
    call UnitApplyTimedLife( wisp, 'BTLF', 20.00) 
    loop
        exitwhen GetUnitX(wisp) == GetLocationX(p) and GetUnitY(wisp) == GetLocationY(p)
        call TriggerSleepAction(RMaxBJ(bj_WAIT_FOR_COND_MIN_INTERVAL, 0.10))
    endloop
    call IssueImmediateOrder( wisp, "tranquility" )
endfunction

//===========================================================================
function InitTrig_Wisps_Spawn takes nothing returns nothing
    set gg_trg_Wisps_Spawn = CreateTrigger()
    call DisableTrigger( gg_trg_Wisps_Spawn )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Wisps_Spawn, 10.00 )
    call TriggerAddAction( gg_trg_Wisps_Spawn, function Actions )
endfunction


If my Boss isn't moving, then the wisp goes there normally and does tranquility as it is supposed to with a little delay. Thats ok. But if my Boss is moved (which is how its supposed to happen in game) then the wisp goes to the location and just stays there doing nothing. If then the Boss goes into the tranqulity range (600) of the wisp, then it does cast the spell. I don't know if this is because of the trigger or the game mechanics. I barely converted this from GUI and edited some minor condition things, so you may see a lot of BJ's, help on those appreciated. Leaks also.
 

Flare

Stops copies me!
Reaction score
662
JASS:
exitwhen GetUnitX(wisp) == GetLocationX(p) and GetUnitY(wisp) == GetLocationY(p)

That condition is EXTREMELY unlikely to return true. Make it so that there is ~50-100 units either direction i.e.
(X1 = wisp x, X2 = point x, Y1 = wisp y, Y2 = point y)
JASS:
X1 >= X2-50 and X1 <= X2+50 and Y1 >= Y2-50 and Y1 <= Y2+50
//Thatll make it so the wisp has to be within 50 units of the point, but 50 units may be too small - 100 should be fine since it's a reasonable size



As regards leaks
JASS:
GetRectCenter(gg_rct_P4_Boss_Pos)

Set it to a var (you're doing the same further down)

JASS:
set p = GetUnitLoc(udg_Boss)

You never destroyed it, so it's leaking (destroy it after the loop)

You need to null wisp and p like so (at the end of the trigger)
JASS:
set wisp = null
set p = null



As regards BJ's and that
JASS:
    call AddSpecialEffectLocBJ( GetRectCenter(gg_rct_P4_Boss_Pos), "Abilities\\Spells\\NightElf\\MoonWell\\MoonWellCasterArt.mdl" )
    call DestroyEffect( bj_lastCreatedEffect )

can become


JASS:
    call CreateNUnitsAtLoc( 1, 'e001', Player(11), GetRectCenter(gg_rct_P4_Boss_Pos), bj_UNIT_FACING )
    set wisp = bj_lastCreatedUnit

can become
JASS:
set wisp = CreateUnitAtLoc (whichPlayer, unitId, whichLoc, facing)
 

Tom_Kazansky

--- wraith it ! ---
Reaction score
157
Let me modify it for a bit:
JASS:
function Actions takes nothing returns nothing
    local real x = GetRectCenterX(gg_rct_P4_Boss_Pos)
    local real y = GetRectCenterY(gg_rct_P4_Boss_Pos)
    local unit wisp = CreateUnit( Player(11), 'e001', x,  y , 0 )
    local real bx
    local real by
    call DestroyEffect( AddSpecialEffect( "Abilities\\Spells\\NightElf\\MoonWell\\MoonWellCasterArt.mdl",  x,  y ) )
    call UnitAddAbility( wisp, 'A011')
    set x = GetUnitX( udg_Boss )
    set y = GetUnitY( udg_Boss )
    call IssuePointOrder( wisp, "move", x , y)
    call UnitApplyTimedLife( wisp, 'BTLF', 20.00)
    loop
        set bx = GetUnitX( udg_Boss )
        set by = GetUnitY( udg_Boss )
        exitwhen GetUnitX(wisp) == bx and GetUnitY(wisp) == by
        if x != bx or y != by then
            set x = bx
            set y = by
            call IssuePointOrder( wisp, "move", x , y)
        endif
        call TriggerSleepAction(0)
    endloop
    call IssueImmediateOrder( wisp, "tranquility" )
    set wisp = null
endfunction

//===========================================================================
function InitTrig_Wisps_Spawn takes nothing returns nothing
    set gg_trg_Wisps_Spawn = CreateTrigger()
    call DisableTrigger( gg_trg_Wisps_Spawn )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Wisps_Spawn, 10.00 )
    call TriggerAddAction( gg_trg_Wisps_Spawn, function Actions )
endfunction

Well, as you can see, I just removes some BJs and with the loop, I check the position ( X, Y ) of the udg_Boss, if the udg_Boss moves, re-order the wisp, so it should moves until it get to the position of the udg_Boss, and then it cast Tranquility.

EDIT: and the condition for the loop, you should change it like this:
JASS:
exitwhen IsUnitInRangeXY( wisp , bx , by , 100 )

so when the wisp comes within 100 range of the udg_Boss, it will cast Tranquility.
 

Roku

New Member
Reaction score
3
Thanks for all the help. +rep to you guys :) But i want my wisp to move to the location where the Boss was when the wisp was created, and do tranquility when it arrives there, no matter where the Boss is, so players need to move to Boss or else he gets healed. I think you get what i mean :)

EDIT: I modified it a bit so now its perfect.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top