• 💀 Happy Halloween! 💀 It's time to vote for the best terrain! Check out the entries to Hive's HD Terrain Contest #2 - Vampire Folklore.❗️Poll closes on November 14, 2023. 🔗Click here to cast your vote!
  • 🏆 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!
  • 🏆 HD Level Design Contest #1 is OPEN! Contestants must create a maze with at least one entry point, and at least one exit point. The map should be made in HD mode, and should not be openable in SD. Only custom models from Hive's HD model and texture sections are allowed. The only exceptions are DNC models and omnilights. This is mainly a visual and design oriented contest, not technical. The UI and video walkthrough rules are there to give everyone an equal shot at victory by standardizing how viewers see the terrain. 🔗Click here to enter!

Does Selecting a Unit Leak?

Status
Not open for further replies.
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
 
Status
Not open for further replies.
Top