• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Which would cause less lag (every 1 sec VS wait and run) trigger

Status
Not open for further replies.
Level 4
Joined
Dec 19, 2011
Messages
29
Hello there,

I made a trigger which would increase life regeneration for my enemy creeps by 0.3% per sec

  • Life Aura Team 1
    • Events
    • Conditions
    • Actions
      • Set Temp_Group_Team1 = (Units in (Playable map area) matching ((Owner of (Matching unit)) Equal to Player 11 (Dark Green)))
      • Unit Group - Pick every unit in Temp_Group_Team1 and do (Actions)
        • Loop - Actions
          • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + ((Max life of (Picked unit)) x (0.1 x 0.03)))
      • Custom script: call DestroyGroup (udg_Temp_Group_Team1)
      • Wait 1.00 seconds
      • Trigger - Run (This trigger) (checking conditions)


Is it better to keep it that way or to do this

  • Life Aura Team 1
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Group_Team1 = (Units in (Playable map area) matching ((Owner of (Matching unit)) Equal to Player 11 (Dark Green)))
      • Unit Group - Pick every unit in Temp_Group_Team1 and do (Actions)
        • Loop - Actions
          • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + ((Max life of (Picked unit)) x (0.1 x 0.03)))
      • Custom script: call DestroyGroup (udg_Temp_Group_Team1)
which has less lag?
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
Hello there,

I made a trigger which would increase life regeneration for my enemy creeps by 0.3% per sec

  • Life Aura Team 1
    • Events
    • Conditions
    • Actions
      • Set Temp_Group_Team1 = (Units in (Playable map area) matching ((Owner of (Matching unit)) Equal to Player 11 (Dark Green)))
      • Unit Group - Pick every unit in Temp_Group_Team1 and do (Actions)
        • Loop - Actions
          • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + ((Max life of (Picked unit)) x (0.1 x 0.03)))
      • Custom script: call DestroyGroup (udg_Temp_Group_Team1)
      • Wait 1.00 seconds
      • Trigger - Run (This trigger) (checking conditions)


Is it better to keep it that way or to do this

  • Life Aura Team 1
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Group_Team1 = (Units in (Playable map area) matching ((Owner of (Matching unit)) Equal to Player 11 (Dark Green)))
      • Unit Group - Pick every unit in Temp_Group_Team1 and do (Actions)
        • Loop - Actions
          • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + ((Max life of (Picked unit)) x (0.1 x 0.03)))
      • Custom script: call DestroyGroup (udg_Temp_Group_Team1)
which has less lag?

areu sure this triggers lagging?i dont see nothing wrong with it.

anyway u could use max life *3/1000 coz easier :)
 
Level 13
Joined
Mar 24, 2010
Messages
950
its probably better to use the event timer of 1 sec because using waits when not necessary is not good to do. It can cause problems esp in on line games when a lag spike occurs etc.. Also becuz of that its not as accurately timed
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
its probably better to use the event timer of 1 sec because using waits when not necessary is not good to do. It can cause problems esp in on line games when a lag spike occurs etc.. Also becuz of that its not as accurately timed

right, somehow i dont watched its call same trigger in last row in 1st example.
so its both periodic trigger, and ofc periodic timer better
 
Both triggers will look like this (more or less):
JASS:
function Trig_test_Func001A takes nothing returns nothing
    call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) + ( 0.1 * 0.03 ) ) )
endfunction

function Trig_test_Actions takes nothing returns nothing
    call ForGroupBJ( GetUnitsOfPlayerAll(Player(10)), function Trig_test_Func001A )
endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    set gg_trg_test = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_test, 1.00 )
    call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction

/*
function TriggerRegisterTimerEventPeriodic takes trigger trig, real timeout returns event
    return TriggerRegisterTimerEvent(trig, timeout, true)
endfunction

function GetUnitsOfPlayerAll takes player whichPlayer returns group
    return GetUnitsOfPlayerMatching(whichPlayer, null)
endfunction

    function GetUnitsOfPlayerMatching takes player whichPlayer, boolexpr filter returns group
        local group g = CreateGroup()
        call GroupEnumUnitsOfPlayer(g, whichPlayer, filter)
        call DestroyBoolExpr(filter)
        return g
    endfunction

function ForGroupBJ takes group whichGroup, code callback returns nothing
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    call ForGroup(whichGroup, callback)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(whichGroup)
    endif
endfunction

function GetUnitStateSwap takes unitstate whichState, unit whichUnit returns real
    return GetUnitState(whichUnit, whichState)
endfunction

function SetUnitLifeBJ takes unit whichUnit, real newValue returns nothing
    call SetUnitState(whichUnit, UNIT_STATE_LIFE, RMaxBJ(0,newValue))
endfunction
    
    function RMaxBJ takes real a, real b returns real
        if (a < b) then
            return b
        else
            return a
        endif
    endfunction
*/
Where is red function BJ function, that will call additional function etc etc. (Green code).

Now as you can see you will create group few times, run timers few times etc etc.
So it's same. I know that you are scared because of that run each 1 sec, but wait XXX game time is also timer.

  • Test
    • Events
    • Conditions
    • Actions
      • Wait 2.00 game-time seconds
JASS:
function Trig_Test_Actions takes nothing returns nothing
    call PolledWait( 2 )
endfunction

//===========================================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Test, function Trig_Test_Actions )
endfunction

/*
function PolledWait takes real duration returns nothing
    local timer t
    local real  timeRemaining

    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop
            set timeRemaining = TimerGetRemaining(t)
            exitwhen timeRemaining <= 0

            // If we have a bit of time left, skip past 10% of the remaining
            // duration instead of checking every interval, to minimize the
            // polling on long waits.
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
        call DestroyTimer(t)
    endif
endfunction
*/

And finally here is my suggestion:
I hope that you use JASS NEW GEN:
JASS:
struct LifeReg extends array

    private static constant player P      = Player(10)               //Player 11 in GUI (Dark Green)
    private static constant real INTERVAL = 1.                       //Timer loop interval
    
    private static method run takes nothing returns nothing
        local unit u
        local real life
        local real maxlife
        call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, P, null)    //bj_lastCreatedGroup don't need to be nulled or destoryed it's global variable
        loop
            set u = FirstOfGroup(bj_lastCreatedGroup)
            exitwhen u == null                                        //handle don't need to be nulled or destroyed as well it will become null in loop

            set life = GetUnitState(u, UNIT_STATE_LIFE)              //real or integer don't leak, we use it just to shorten code
            set maxlife = GetUnitState(u, UNIT_STATE_MAX_LIFE)
            call SetUnitState(u, UNIT_STATE_LIFE, life + (maxlife * 0.03) )

            call GroupRemoveUnit(bj_lastCreatedGroup, u)
        endloop
    endmethod
    
    private static method onInit takes nothing returns nothing
        local trigger T = CreateTrigger()
        call TriggerRegisterTimerEvent(T, INTERVAL, true)
        call TriggerAddAction(T, function thistype.run)
        set T = null
    endmethod
endstruct

if not then try this:
JASS:
function run takes nothing returns nothing
    local unit u
    local real life
    local real maxlife
    call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, Player(0), null)
    loop
        set u = FirstOfGroup(bj_lastCreatedGroup)
        exitwhen u == null
        
        set life = GetUnitState(u, UNIT_STATE_LIFE)
        set maxlife = GetUnitState(u, UNIT_STATE_MAX_LIFE)
        call SetUnitState(u, UNIT_STATE_LIFE, life + (maxlife * 0.03) )
        
        call GroupRemoveUnit(bj_lastCreatedGroup, u)
    endloop
endfunction
    
function InitTrig_LifeReg takes nothing returns nothing
        local trigger T = CreateTrigger()
        call TriggerRegisterTimerEvent(T, 1.0, true)
        call TriggerAddAction(T, function run)
        set T = null
endfunction

But you need trigger named "LifeReg"
 

Attachments

  • xxx.w3x
    18.3 KB · Views: 36
Level 14
Joined
Apr 20, 2009
Messages
1,543
if not then try this:
JASS:
function run takes nothing returns nothing
    local unit u
    local real life
    local real maxlife
    call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, Player(10 Instead of 0), null)
    loop
        set u = FirstOfGroup(bj_lastCreatedGroup)
        exitwhen u == null
        
        set life = GetUnitState(u, UNIT_STATE_LIFE)
        set maxlife = GetUnitState(u, UNIT_STATE_MAX_LIFE)
        call SetUnitState(u, UNIT_STATE_LIFE, life + (maxlife * 0.03) )
        
        call GroupRemoveUnit(bj_lastCreatedGroup, u)
    endloop
endfunction
    
function InitTrig_LifeReg takes nothing returns nothing
        local trigger T = CreateTrigger()
        call TriggerRegisterTimerEvent(T, 1.0, true)
        call TriggerAddAction(T, function run)
        set T = null
endfunction

But you need trigger named "LifeReg"

In your non vJass trigger the index is Player(0) instead of Player(10) as in Exoudar's trigger example.
Exoudar would need to change this to his/her likings but it might be easyer if you could update it for him/her.
Making it more GUI user friendly ^.^

Just a friendly reminder :thumbs_up:
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
I can't I haven't got the time to open up the editor :(
I'm always busy, I can answer some questions off the top of my head but I really just can't open up the editor xD Sorry...

I guess it's got something to do with the player you've created inside the test map?
But then copy and pasting the code into his map would make it not work right?
 
  • Life Increase
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) owned by Player 11 (Dark Green)) and do (Actions)
        • Loop - Actions
          • Set TempUnit = (Picked unit)
          • Unit - Set life of TempUnit to ((Percentage life of TempUnit) + 0.30)%
This would be the most optimal way to do it for GUI.
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
why dont you just make an unholy aura ability, add to a dummy unit creep, remove all
the buffs then aura AOE is 999999?...
if you dont want that, just initialize all the creeps add it to the Temp_Group_Team1 then
loop it, no need to destroy coz why would you destroy something that is still needed...
you may index the creeps though so that if the creeps dies it is removed from that
group, then if index==0, off the trigger...
 
why dont you just make an unholy aura ability, add to a dummy unit creep, remove all
the buffs then aura AOE is 999999?...
if you dont want that, just initialize all the creeps add it to the Temp_Group_Team1 then
loop it, no need to destroy coz why would you destroy something that is still needed...
you may index the creeps though so that if the creeps dies it is removed from that
group, then if index==0, off the trigger...

That would disallow him to use Unholy Aura on units effected by the buff.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
  • Life Increase
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) owned by Player 11 (Dark Green)) and do (Actions)
        • Loop - Actions
          • Set TempUnit = (Picked unit)
          • Unit - Set life of TempUnit to ((Percentage life of TempUnit) + 0.30)%
This would be the most optimal way to do it for GUI.

No, your leaking a location.
Pick every unit in .....
 
No, your leaking a location.
Pick every unit in .....
No I am not leaking a "location" Playable map area is a REGION, and it doesn't leak.
as I said, you dont need to destroy the group if its still needed, recycle it...
Yes you do, because if he adds new units during the game they will not be part of the unit group. Unless he manually adds them. But that would be frustrating.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
No I am not leaking a "location" Playable map area is a REGION, and it doesn't leak.

My fault, didn't think...
Still a shame that that one specific action contains 4 BJ's though.. :(
JASS:
call ForGroupBJ( GetUnitsInRectAll(GetPlayableMapRect()), function my_trig)

JASS:
function GetUnitsInRectAll takes rect r returns group
    return GetUnitsInRectMatching(r, null)
endfunction

ow well... GUI
 
Status
Not open for further replies.
Top