Most efficient method using rects

shiFt

Member
Reaction score
8
What would be the most efficient method of detecting if a unit is in a rect then giving it an ability eg) +10 damage, and removing it again if the unit leaves the rect? Use enter/leave functions or a perodic, or some other solution?
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
is the rect a constant? never moved nor re-created? if so use the "unit enters region" event.

if not you could use periodic checks whether
Code:
rect.min_x < unit.x < rect.max_x
and
Code:
rect.min_y < unit.y < rect.max_y

using jass these checks would be alot more effective since you wouldnt need to create locations thisfor as you have to in GUI.
 

shiFt

Member
Reaction score
8
Explain more about the jass thingy, they are preplaced on the map, like bonus zones each gives diffrent ability etc.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
If they are preplaced, then you don't have to use those JASS functions(Functions right?), just use Unit enters region event.

Those JASS functions are for detecting units in a region that is not preplaced, units or number of units, or something like that
 

shiFt

Member
Reaction score
8
Im currently using the enters/leaving event however sometimes when a unit passes throught the region they dont lose the bonus ability, it does not get removed on leaving, in some cases it bugs.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Im currently using the enters/leaving event however sometimes when a unit passes throught the region they dont lose the bonus ability, it does not get removed on leaving, in some cases it bugs.

shouldnt do this if triggered properly. as said above, post the triggers here maybe.
 

shiFt

Member
Reaction score
8
Fairly simple?
JASS:
scope BONUS initializer Init 

globals
    private constant integer BUFF = &#039;Bons&#039;
endglobals

private function Conditions takes nothing returns boolean
   return IsUnitType(GetEnteringUnit(), UNIT_TYPE_HERO) == true 
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetEnteringUnit()
    call UnitAddAbility(u, BUFF)
    set u = null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger(  )
   call TriggerRegisterEnterRectSimple( t, gg_rct_Bonus )
    call TriggerAddCondition(t, Condition( function Conditions ) )
    call TriggerAddAction(t, function Actions )
    set t= null
endfunction

JASS:
scope BONUSRE initializer Init 

globals
    private constant integer BUFF = &#039;Bons&#039;
endglobals

private function Conditions takes nothing returns boolean
   return IsUnitType(GetLeavingUnit(), UNIT_TYPE_HERO) == true 
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetLeavingUnit()
    call UnitRemoveAbility(u, BUFF)
    set u = null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger(  )
   call TriggerRegisterLeaveRectSimple( t, gg_rct_Bonus )
    call TriggerAddCondition(t, Condition( function Conditions ) )
    call TriggerAddAction(t, function Actions )
    set t= null
endfunction
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Maybe check if the unit has buff instead of checking whether the unit is a hero? Actually I'm clueless :D
 

shiFt

Member
Reaction score
8
Its not really a buff, I used that to show the bonus ability. I make it hero so it only fires if they enter and not if neutral creeps etc. enter it, spose it makes it more efficient?
 
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