• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Pick unit ... matching ....

Status
Not open for further replies.
What is most efficient way to make a loop through unit group which has lot of these conditions and such? In GUI is Pick every unit in .... matching ... , when you convert in JASS you get
call ForGroupBJ( GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Trig_lalala_Func002001002)), function Trig_lalala_Func002A )
I wonder if I should keep this structure or I should program something very new.
 
Level 21
Joined
Mar 19, 2009
Messages
444
The best way, but it's in Jass, is to use the Filter to check all counditions and to directly implement the things you want into the filter.
Such as:
JASS:
    private function Example takes nothing returns boolean
        local unit target = GetFilterUnit()
            if not(IsUnitType(target,UNIT_TYPE_DEAD)) then
                 call UnitDamageTarget(target,target,DAMAGE, true, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
            endif
            set target = null
            return true
    endfunction

    private function Blabla1 takes nothing returns nothing
           //...
           call GroupEnumUnitsInRange(ENUM_GROUP,x,y, AOE, Filter(function Example))
           //...
    endfunction
 
Ok, I did it in some way, but now I experience lag, I have no idea which command is so heavy to cause it

JASS:
function Trig_Regroup_Actions takes nothing returns nothing
    local real Xpos
    local real Ypos
    local integer order
    local integer i = 1
    local unit wanderer
    local unit commander
    local unit target
    local location point1
    local location point2
    local group batalion = CreateGroup()
    loop
        set commander = GetCaptain(udg_Battallion[i])
        set point1 = GetUnitLoc(commander)
        exitwhen (commander == null)
        call GroupAddGroup( udg_Battallion[i], batalion )
        //call DisplayTextToForce( GetPlayersAll(), "trying to regroup" )
         loop
            set wanderer = FirstOfGroup(batalion)
            exitwhen (wanderer == null)
            set point2 = GetUnitLoc(wanderer)
            if ( DistanceBetweenPoints( point1, point2 ) >= udg_BattallionRegroup and not (IsUnitInGroup(wanderer, udg_BattallionQueued ) ) ) then
                //call DisplayTextToForce( GetPlayersAll(), "regroup" )
                call IssuePointOrder( wanderer, "move", GetLocationX(point1), GetLocationY(point1) )
                call GroupAddUnit( udg_BattallionQueued, wanderer )
                call TriggerExecute( GetTriggeringTrigger() )
                loop
                    set point1 = GetUnitLoc(commander)
                    set point2 = GetUnitLoc(wanderer)
                    exitwhen ( DistanceBetweenPoints( point1, point2 ) <= 150 )
                    call TriggerSleepAction( 0.5 )
                    call RemoveLocation( point1 )
                    call RemoveLocation( point2 )
                endloop
                set Xpos = LoadReal( udg_hashtable, GetHandleId(commander) , 3)
                set Ypos = LoadReal( udg_hashtable, GetHandleId(commander) , 4)
                set order = LoadInteger( udg_hashtable, GetHandleId(commander), 2 )
                set target = LoadUnitHandle( udg_hashtable, GetHandleId(commander), 5 )
                if ( order != 0 and GetUnitCurrentOrder(commander) != String2OrderIdBJ("") ) then
                    if ( target == null ) then
                        call IssuePointOrderById(wanderer, order, Xpos, Ypos )
                    else
                        call IssueTargetOrderById(wanderer, order, target )
                    endif
                endif
                set target = null
                call GroupRemoveUnit( udg_BattallionQueued, wanderer )
                //call TriggerExecute( GetTriggeringTrigger() )
            endif
            call GroupRemoveUnit(batalion, wanderer)
            set wanderer = null
        endloop
        call DestroyGroup( batalion )
        set i = i + 1
        call RemoveLocation(point1)
        call RemoveLocation(point2)
        set commander = null
    endloop 
    
endfunction

//===========================================================================
function InitTrig_Regroup takes nothing returns nothing
    set gg_trg_Regroup = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Regroup, 2.00 )
    call TriggerAddAction( gg_trg_Regroup, function Trig_Regroup_Actions )
endfunction
 
Level 11
Joined
Sep 12, 2008
Messages
657
he did so many bjs, locations, gahh my eyes hurt =[

btw.. they made a much easier way instead your event.. (in init code)

its

call TimerStart(CreateTimer(), 0.032, true, function YourFunction)
0.032 = period, true = looping the timer, making it endless, and function which code to run.

theres also PauseTimer(TimerVariableIfYouGot1)
and ResumeTimer(TimerVariableIfYouGot1)

instead of locations, (point1, point2)
use 4 reals, 2 reals each point.
set real1 = GetLocationX(WhichLocation), set real2 = GetLocationY(WhichLocation)
set real3 = GetLocationX(AnotherLocation), set real4 = GetLocationY(AnotherLocation)
then instead of DistaceBetweenPoints do:

SquareRoot(real1 * real3 + real2 * real4)
and it will do the same, and make you'r code alot faster.

about your heavy lags..
thats all i could see.. try fixing locations/etc, and it might be better..
and make sure you run the code ONLY when the group is not empty.
or else it could run it empty, and do alot of if then elses that doesnt exist.
 
I discovered the source. Actually one of my custom functions wasn't correctly written and this trigger called it. It was a miracle that even worked correctly (but with this lag). And for event and conditions I use the default gui generated code, since I don't understand this thing much.

Anyway, about picking units, when I enum them, should I call function ForGroup or make my custom loop instead? And can I make the function which is passed as argument of ForGroup to have even its arguments? (I would need to pass some locals)
 
Status
Not open for further replies.
Top