• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] This is causing framerate drops.

Status
Not open for further replies.
Level 5
Joined
May 29, 2009
Messages
63
Leaks?
Inefficient use of GroupEnums?

Maybe I'm missing something that I don't know.

JASS:
function Trig_lasthit_Conditions takes nothing returns boolean
    return AIhitDelay[GetAttacker()]==0 and IsUnitMinion(GetTriggerUnit()) and IsUnitAIHero(GetAttacker()) and IsAutoAttacking(GetAttacker())
endfunction

function Trig_lasthit_Actions takes nothing returns nothing
    local unit target = GetTriggerUnit()
    local unit newtarget
    local unit hero = GetAttacker()
    
    set AIcurrentTarget[hero] = target
    call TriggerSleepAction(.7)
    loop
        exitwhen AIhitDelay[hero] >= 4
        exitwhen AIcurrentTarget[hero]!=target or AIFleeing[hero]
        //call BJDebugMsg( GetUnitName(hero)+" "+ I2S(AIhitDelay[hero]))
    
        set newtarget = AIHeroes_pickNearHero( target, 300 )
        if newtarget!=null and LifePercent(target) > 15 then
            call IssueTargetOrder( hero, "attack", newtarget )
            exitwhen true
        endif
        
        if LifePercent(target) <= 15 then
            //call BJDebugMsg("lasthit")
            call IssueTargetOrder( hero, "attack", target )
            exitwhen true
        endif

        call IssueImmediateOrder(hero, "stop")
        set AIhitDelay[hero] = AIhitDelay[hero] + 1
        call TriggerSleepAction(0.33)
    endloop
    call TriggerSleepAction(1)
    set AIhitDelay[hero] = 0
    set newtarget = null
    set target = null
    set hero = null
endfunction

//===========================================================================
function InitTrig_lasthit_Copy takes nothing returns nothing
    set gg_trg_lasthit_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_lasthit_Copy, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_lasthit_Copy, Condition( function Trig_lasthit_Conditions ) )
    call TriggerAddAction( gg_trg_lasthit_Copy, function Trig_lasthit_Actions )
endfunction

JASS:
    globals
        private group near = CreateGroup()
    endglobals

    public function pickNearHero takes unit given, real range returns unit
        local boolean ret = false
        
        set enumcount = enumcount+1
        
        call GroupEnumUnitsInRange(near, GetUnitX(given), GetUnitY(given), range, Condition(function LiveUnitFilter))
        loop
            set bj_groupRandomCurrentPick = FirstOfGroup(near)
            call GroupRemoveUnit(near,bj_groupRandomCurrentPick)
            exitwhen bj_groupRandomCurrentPick == null
            if IsUnitAlly(bj_groupRandomCurrentPick,GetOwningPlayer(given)) and IsUnitType(bj_groupRandomCurrentPick, UNIT_TYPE_HERO) then
                exitwhen true
            endif
            if IsUnitAlly(bj_groupRandomCurrentPick,GetOwningPlayer(given)) and LifePercent(bj_groupRandomCurrentPick)<=15 then
                exitwhen true
            endif
        endloop
        return bj_groupRandomCurrentPick
    endfunction
 
JASS:
set bj_groupRandomCurrentPick = FirstOfGroup(near)
        call GroupRemoveUnit(near,bj_groupRandomCurrentPick)
        exitwhen bj_groupRandomCurrentPick == null
        if IsUnitAlly(bj_groupRandomCurrentPick,GetOwningPlayer(given)) and (IsUnitType(bj_groupRandomCurrentPick, UNIT_TYPE_HERO) or LifePercent(bj_groupRandomCurrentPick)<=15 ) then
            exitwhen true
        endif

Its useless to repeat the IsUnitAlly Check... utilize the use of ands and or...

also, instead of spamming GetOwningPlayer, why not take it as a parameter or make a local at the top...
 
Status
Not open for further replies.
Top