What's more efficient?

Dirac

22710180
Reaction score
147
I need to know if a unit within the range of another unit dies, so what's best?

-Checking periodically if around the main unit are there any dead units
Pros
Ignores any unit that dies outside range
Cons
Uses timers

-Create a trigger that detonates every time a unit dies and then check if that unit is nearby the main unit
Pros
Doesn't use timers
Cons
Leaks triggers conditions and actions
Checks all units in the map even when there's no need

NOTE: for every dead unit i create a timer, so consider that registering unnecessary unis affects efficiency
 

Ayanami

칼리
Reaction score
288
The second option is more efficient. If you're worried about Actions leak, just don't use them, use Conditions instead. And as for the trigger, you can destroy them.
 

Dirac

22710180
Reaction score
147
As i thought, i used condition before BUT

for some reason conditions for REGISTER_PLAYER_UNIT_DEATH won't recieve GetTriggerUnit() or GetDyingUnit(). Oddly if you input GetFilterUnit() you get the killing unit, so i think there's no way to avoid the action leak
 

Dirac

22710180
Reaction score
147
and how exactly do i use that event for "any unit dies"?

It only registers the death of 1 unit, not every unit
 

Ayanami

칼리
Reaction score
288
You could register to every unit upon entering the map. And also to pre-placed units.
 

Dirac

22710180
Reaction score
147
Something like this then
JASS:
//
    private function add takes nothing returns boolean
        ACTIONS
        return false
    endfunction

    private function AddDeathTrigger takes nothing returns boolean
        local trigger trig=CreateTrigger()
        call TriggerRegisterUnitEvent(trig,GetFilterUnit(),EVENT_UNIT_DEATH)
        call TriggerAddCondition(trig,Condition(function add))
        return false
    endfunction

    private function start takes nothing returns nothing
        local trigger trig=CreateTrigger()
        local region reg=CreateRegion()
        call RegionAddRect(reg,GetWorldBounds())
        call TriggerRegisterEnterRegion(trig,reg,Condition(function AddDeathTrigger))
        call GroupEnumUnitsInRect(GROUP,GetWorldBounds(),function AddDeathTrigger)
    endfunction
 

Ayanami

칼리
Reaction score
288
Yeah. However, I'd suggest you to add the units in a group. This is to prevent the unit from registering the event twice (I believe this can occur).
 

Sevion

The DIY Ninja
Reaction score
413
Why don't you just use the Player Unit event?

JASS:
//
    private function Actions takes nothing returns nothing
        local unit dyingUnit = GetTriggerUnit()
        local unit killingUnit = GetKillingUnit()

        // Put Conditions Here
        if ( true ) then
        endif
    endfunction

    private function Init takes nothing returns nothing
        local trigger t=CreateTrigger()
        local integer i = 11

        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_DEATH, null)
            exitwhen i == 0
            set i = i - 1
        endloop

        call TriggerAddAction(t, funciton Actions)
    endfunction
 

Ayanami

칼리
Reaction score
288
Why don't you just use the Player Unit event?

JASS:
//
    private function Actions takes nothing returns nothing
        local unit dyingUnit = GetTriggerUnit()
        local unit killingUnit = GetKillingUnit()

        // Put Conditions Here
        if ( true ) then
        endif
    endfunction

    private function Init takes nothing returns nothing
        local trigger t=CreateTrigger()
        local integer i = 11

        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_DEATH, null)
            exitwhen i == 0
            set i = i - 1
        endloop

        call TriggerAddAction(t, funciton Actions)
    endfunction

Yeah actually, why not. I was thinking that he needed to destroy his trigger, but I don't see a need to do so, now that I'm looking back at the question xD
 

NBalfa

New Member
Reaction score
10
actually the second option is better as you could set a nice conditional of the type:
dying unit is within range of x unit in unitgroup
well if you have stored that value of unit you should(well I am not uning vJass coz my pc cant accept it so I could not tell you the exact answer in vJass)
reduce the bugging with functions like that:
making sure that the dying unit is not caster nor building or anything else you dont want
the point is to have reduced that amound of units at the begining
 

Dirac

22710180
Reaction score
147
Why don't you just use the Player Unit event?
Lol you can't be serious. That's what i used before i created this thread, BRB gotta delete some of the lines in my code :(
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
Can you tell me what is your purpose ??
because you may register the units that will be checked in a unit array or unitgroup and check when your unit dies if one of them is nearby.

check my hero in current contest, the function for gaining soul points
 

Dirac

22710180
Reaction score
147
I'll just go ahead and close this thread since Ayanami's answer has helpful enoguh, even when he did make me code something i didn't need lol
 
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