Does Selecting a Unit Leak?

Level 11
Joined
Jun 30, 2008
Messages
580
Name^

This is the code that is causing my handles to go up whenever I select a unit:

JASS:
library DamageTargSys initializer Init
    globals
        private constant integer SELECTER_MODEL     = 'h004'
        private constant integer MAX_DISTANCE       = 500
        
        private boolean IsSelect = false
    endglobals
    
    private function Select takes nothing returns nothing
        local player selecter = GetTriggerPlayer()
        local unit target = GetTriggerUnit()
        local CharDat dat = LoadInteger(CD, GetPlayerId(selecter), 1)
        if (IsSelect == false) then
            if (dat.Character != target) then
                call RemoveUnit(dat.SelectionMod)
                set dat.SelectionMod = CreateUnit(selecter, SELECTER_MODEL, GetUnitX(target), GetUnitY(target), 0.0)
                set dat.Selection = target
                set IsSelect = true
                if (GetLocalPlayer() == selecter) then
                // Use only local code (no net traffic) within this block to avoid desyncs.
                    call ClearSelection()
                    call SelectUnit(dat.Character, true)
                endif
                set IsSelect = false
            endif
        endif
    endfunction
    
    function OnDoubleSelect takes player selecter, unit target returns nothing
        
    endfunction
    
    private function CheckDist takes nothing returns nothing
        local integer a = 0
        local CharDat dat
        local real dx
        local real dy
        local real dxy
        loop 
        exitwhen a > 9
            set dat = LoadInteger(CD, a, 1)
            set dx = GetUnitX(dat.Selection) - GetUnitX(dat.Character)
            set dy = GetUnitY(dat.Selection) - GetUnitY(dat.Character)
            set dxy = SquareRoot(dx * dx + dy * dy)
            if (dxy >= MAX_DISTANCE) then
                set dat.Selection = null
                call RemoveUnit(dat.SelectionMod)
                set dat.SelectionMod = null
            endif
        set a = a+1
        endloop
        set a = 0
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer a = 0
        loop
        exitwhen a > 9
            call TriggerRegisterPlayerSelectionEventBJ(t, Player(a), true)
        set a = a + 1
        endloop
        set a = 0
        call TriggerAddAction(t, function Select)
        
        set t = CreateTrigger()
        call TriggerRegisterTimerEventPeriodic(t, 0.03)
        call TriggerAddAction(t, function CheckDist)
    endfunction
endlibrary
 
Top