• 🏆 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!

Unit Has Locust But Still Can Be Selected

Status
Not open for further replies.
Level 11
Joined
Jun 30, 2008
Messages
580
I'm having this problem. The dummy unit has locust, but when the function is ran it suddenly doesn't have it anymore. But I have a regular placed dummy that is not affected by the code, and it still has locust.

Basically the code is suppose to create this dummy unit at the unit you left clicked. I have another code that moves that dummy unit to the targeted unit. But when I select a group around that unit, it selects the dummy unit and then the code is ran on that and it moves and disappears.

Here is the code:

JASS:
library DamageTargSys initializer Init
    globals
        constant integer SELECTER_MODEL         = 'h004'
        private constant integer MAX_DISTANCE   = 1000
        
        private boolean IsSelect = false
    endglobals
    
    private function OnLeftClick 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 ShowUnit(dat.SelectionMod, true)
                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
        set selecter = null
        set target = null
    endfunction
    
    function OnDoubleLeftClick takes nothing returns nothing
        
    endfunction
    
    function OnRightClick takes nothing 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 ShowUnit(dat.SelectionMod, false)
            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 OnLeftClick)
        call TimerStart(CreateTimer(), 0.03, true, function CheckDist)
    endfunction
endlibrary
 
Level 11
Joined
Jun 30, 2008
Messages
580
JASS:
                // Use only local code (no net traffic) within this block to avoid desyncs.

-_-

That's what we get for mindlessly telling people to inline all "evil" BJ's.

I don't like BJ's, not because they are evil. Only because I like to read all the code. Also I'm going to end up putting more in that block, so its easier for me so I don't have extra blocks calling the same thing. Its an efficiency thing for me :p

How ya doin Bribe? xD

And to watermelon, I will try that thank you

+rep for Bribe
+rep for Watermelon
 
Status
Not open for further replies.
Top