Grouping Units Fails Sometimes

WolfieeifloW

WEHZ Helper
Reaction score
372
My spell is a simple dash, but it also does damage and creates an illusion at every enemy hit.

My problem is that sometimes (Usually when going diagonal), units won't get grouped by the spell.
My hero goes right through the middle of them, but still doesn't create an illusion sometimes.
Here's the code:
JASS:
library PhantomDash initializer Init requires TimerUtils optional GTrigger

    globals
        private constant integer ABILITY_ID = 'PHAN'
        private constant integer ILLUSION_ID = 'ILLU'
        private constant integer DUMMY_ID = 'dUMM'
        private constant integer HIT_RANGE = 50
        private constant real SPEED = 500.
        private constant real RADIUS = 50.
        private constant attacktype ATTACK_TYPE = ATTACK_TYPE_MELEE
        private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
        private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS
    endglobals
    
    private function Damage takes integer level returns real
        return level * 50.
    endfunction
    
    struct data
        unit caster
        real casterX
        real casterY
        real targetX
        real targetY
        real facing
        group hit = CreateGroup()
        timer t
        
        method destroy takes nothing returns nothing
            call ReleaseTimer(.t)
            call GroupClear(.hit)
            call .deallocate()
        endmethod
    endstruct
    
    globals
        private constant real PERIOD = 0.03125
        private constant real DSPEED = SPEED * PERIOD
        private group GROUP = CreateGroup()
        private location loc
        private real x
        private real y
        private integer CurrentInstance
    endglobals
    
    private function Conditions takes nothing returns boolean
        local unit u = GetFilterUnit()
        local unit dummy
        local data d = CurrentInstance
        
        call BJDebugMsg("Conditions")
        if IsUnitType(u, UNIT_TYPE_STRUCTURE) == false and GetWidgetLife(u) >= 0.405 and IsUnitEnemy(u, GetOwningPlayer(d.caster)) and IsUnitInGroup(u, d.hit) == false then
            call BJDebugMsg("Passed")
            call UnitDamageTarget(d.caster, u, Damage(GetUnitAbilityLevel(d.caster, ABILITY_ID)), true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
            set dummy = CreateUnit(GetOwningPlayer(d.caster), DUMMY_ID, GetUnitX(u), GetUnitY(u), bj_UNIT_FACING)
            call UnitAddAbility(dummy, ILLUSION_ID)
            call SetUnitAbilityLevel(dummy, ILLUSION_ID, GetUnitAbilityLevel(d.caster, ABILITY_ID))
            call IssueTargetOrderById(dummy, 852274, d.caster)
            call UnitApplyTimedLife(dummy, 'BTLF', 1.)
            call GroupAddUnit(d.hit, u)
        endif
        set dummy = null
        set u = null
        return false
    endfunction
    
    private function Callback takes nothing returns nothing
        local data d = GetTimerData(GetExpiredTimer())
        
        set d.casterX = GetUnitX(d.caster)
        set d.casterY = GetUnitY(d.caster)
        set x = d.targetX - d.casterX
        set y = d.targetY - d.casterY
        if SquareRoot(x * x + y * y) >= HIT_RANGE then
            call BJDebugMsg("Callback")
            set d.facing = Atan2(d.targetY - d.casterY, d.targetX - d.casterX)
            set d.casterX = d.casterX + DSPEED * Cos(d.facing)
            set d.casterY = d.casterY + DSPEED * Sin(d.facing)
            call SetUnitX(d.caster, d.casterX)
            call SetUnitY(d.caster, d.casterY)
            set CurrentInstance = d
            call GroupEnumUnitsInRange(GROUP, GetUnitX(d.caster), GetUnitY(d.caster), RADIUS, Condition(function Conditions))
        else
            call BJDebugMsg("Ending")
            call BJDebugMsg("---------------")
            call SetUnitAnimation(d.caster, "stand")
            call PauseUnit(d.caster, false)
            call d.destroy()
        endif
    endfunction
    
    private function Actions takes nothing returns boolean
        local data d
        
        if GetSpellAbilityId() == ABILITY_ID then
            call BJDebugMsg("Actions")
            set d = data.create()
            set d.caster = GetTriggerUnit()
            set loc = GetSpellTargetLoc()
            set d.casterX = GetUnitX(d.caster)
            set d.casterY = GetUnitY(d.caster)
            set d.targetX = GetLocationX(loc)
            set d.targetY = GetLocationY(loc)
            set d.t = NewTimer()
            call SetTimerData(d.t, d)
            call SetUnitAnimation(d.caster, "walk")
            call PauseUnit(d.caster, true)
            call TimerStart(d.t, PERIOD, true, function Callback)
            set loc = null
        endif
        return false
    endfunction
        
    private function Init takes nothing returns nothing
        local trigger trig = CreateTrigger()
        
        static if(LIBRARY_GTrigger) then
            call TriggerAddCondition(GT_RegisterStartsEffectEvent(trig, ABILITY_ID), Condition(function Actions))
        else
            call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
            call TriggerAddCondition(trig, Condition(function Actions))
        endif
        set trig = null
    endfunction
    
endlibrary

The speed is quite low, for testing purposes, but even at a normal speed (1500), it still errors.

In fact, I just tested it back at 1500, and now it just fails to group, more often then not, even when going in a straight X line.
Oh, and the dummy has 0.00 backswing and cast point; And the illusion wand ability has 0 cooldown and mana cost.
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
Maybe you are ordering too many actions for 0.03215 seconds, but I think that's impossible...

TIP: Try creating group on struct creation to avoid some leaks.
Another one: You may use T32 and see where you made any mistake with yor current timer system, I am on vacation now and I don't have Newgen WE with me, if you wait I will create exactly what you need. Tommorow I'm coming
 

Jedi

New Member
Reaction score
63
50 is very small radius imo, even you touch unit with your hero there is a chance it can't be enumed(depends on unit collisions).

Proof edit:I am picking units in 50 range of left paladin and display it's name.
 
Reaction score
456
Good idea is to go to terrain editor and display grid. Smallest cells have size of 32, then 128, and finally 256.
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
omg now I saw it, 50 radius is nothing, you should use melee range values, like 120-130 to check.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top