Code Check

Ayanami

칼리
Reaction score
288
Need help finding out why this happens. So basically, I have a spell where it forms a straight path. Then after 1 second, the path explodes, stunning and damaging all enemies within the area of the path. Note that damage is dealt during the stun duration, so over time. Note that I used firebolt with 99999 stun seconds for the stun. I manually remove the stun buff when the stun duration is up.

What I've been wondering is that sometimes, very rarely, the enemies do get stunned, however, they don't receive damage and they're stunned forever. Can't seem to figure out where I went wrong. Thanks in advance!

JASS:
scope AquaField // uses T32, TimerUtils, GroupUtils 
                // optional Damage

native UnitAlive takes unit id returns boolean

//===========================================================================
//                           CONFIGURABLES                        
//===========================================================================

globals
    private constant integer ABILID = 'ABAF' // raw code of ability "Aqua Field"
    private constant integer DUMABILID = 'AAF0' // raw code of ability "Aqua Field (Stun)"
    private constant integer BUFFID = 'BAF0' // raw code of buff "Aqua Field"
    private constant integer DUMMYID = 'duAF' // raw code of unit "Aqua Field Dummy"
    private constant integer CASTERID = 'cAST' // raw code of unit "Caster Dummy"
    
    private constant real DINTERVAL = 50.0 // every distance interval where an effect will be created
                                           // smaller value is more accurate, but might cause framerate to drop
    private constant string EFFECT = "Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl" // effect used for explosion
    
    private constant boolean USE_DAMAGE = true // true if you want to this spell to support the Damage library
    
    private constant attacktype ATK = ATTACK_TYPE_NORMAL // attack type of damage dealt
    private constant damagetype DMG = DAMAGE_TYPE_NORMAL // damage type of damage dealt
    private constant weapontype WEP = WEAPON_TYPE_WHOKNOWS // weapon type of damage dealt
endglobals

private function TargetFilter takes unit caster, unit target returns boolean
    return IsUnitEnemy(target, GetOwningPlayer(caster)) /* target is an enemy
           */ and UnitAlive(target) /* target is alive
           */ and not IsUnitType(target, UNIT_TYPE_STRUCTURE) /* target is not a structure
           */
endfunction

private function GetArea takes integer level returns real
    return 200.0 // radius of field
endfunction

private function GetDamage takes integer level returns real
    return 100.0 // damage dealt per second
endfunction

private function GetDelay takes integer level returns real
    return 1.0 // delay time before aqua field explodes
endfunction

private function GetDistance takes integer level returns real
    return 1000.0 // distance of the field
endfunction

private function GetDuration takes integer level returns real
    return 0.6 + (0.4 * level) // duration of stun
endfunction

//===========================================================================
//                          END CONFIGURABLES                        
//===========================================================================

private struct Data
    unit caster
    group dummyGroup
    group targetGroup
    real area
    real damage
    real duration
    static thistype tempData
    static hashtable dataHash = InitHashtable()
    static unit tempCaster
    
    private static method groupFlush takes nothing returns nothing
        local unit u = GetEnumUnit()
        
        call UnitRemoveAbility(u, BUFFID)
        call FlushChildHashtable(dataHash, GetHandleId(u))
        
        set u = null
    endmethod
    
    private static method periodicFunc takes nothing returns nothing
        local thistype this = tempData
        local unit u = GetEnumUnit()
        
        if not UnitAlive(u) or GetUnitAbilityLevel(u, BUFFID) == 0 then
            call GroupRemoveUnit(this.targetGroup, u)
            call FlushChildHashtable(dataHash, GetHandleId(u))
        else
            static if USE_DAMAGE then
                call UnitDamageTargetEx(this.caster, u, this.damage, true, false, ATK, DMG, WEP)
            else
                call UnitDamageTarget(this.caster, u, this.damage, true, false, ATK, DMG, WEP)
            endif
        endif
        
        set u = null
    endmethod
    
    private method periodic takes nothing returns nothing
        if this.duration <= 0 then
            call ForGroup(this.targetGroup, function thistype.groupFlush)
            call ReleaseGroup(this.targetGroup)
            call this.stopPeriodic()
            call this.deallocate()
        else
            set tempData = this
            call ForGroup(this.targetGroup, function thistype.periodicFunc)
            set this.duration = this.duration - T32_PERIOD
        endif
    endmethod
    implement T32x
    
    private static method filterFunc takes nothing returns boolean
        local thistype this = tempData
        local thistype that
        local unit u = GetFilterUnit()
        local integer id = GetHandleId(u)
        
        if TargetFilter(this.caster, u) and not IsUnitInGroup(u, this.targetGroup) then
            if HaveSavedInteger(dataHash, id, 0) then
                set that = LoadInteger(dataHash, id, 0)
                call GroupRemoveUnit(that.targetGroup, u)
            endif
            
            call SaveInteger(dataHash, id, 0, this)
            call GroupAddUnit(this.targetGroup, u)
            call IssueTargetOrder(tempCaster, "firebolt", u)
        endif
        
        set u = null
        return false
    endmethod
    
    private static method groupFunc takes nothing returns nothing
        local thistype this = tempData
        local unit u = GetEnumUnit()
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        
        call DestroyEffect(AddSpecialEffect(EFFECT, x, y))
        call GroupEnumUnitsInArea(ENUM_GROUP, x, y, this.area, Filter(function thistype.filterFunc))
        
        call GroupRemoveUnit(this.dummyGroup, u)
        call RemoveUnit(u)
        set u = null
    endmethod
    
    private static method timeOut takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local thistype this = GetTimerData(t)
        
        set tempData = this
        call ForGroup(this.dummyGroup, function thistype.groupFunc)
        call this.startPeriodic()
        
        call ReleaseGroup(this.dummyGroup)
        call ReleaseTimer(t)
        set t = null
    endmethod

    private static method actions takes nothing returns boolean
        local thistype this
        local timer t
        local player p
        local integer i
        local real a
        local real x
        local real y
        local real r
    
        if GetSpellAbilityId() == ABILID then
            set this = thistype.allocate()
            set this.caster = GetTriggerUnit()
            set i = GetUnitAbilityLevel(this.caster, ABILID)
            set this.area = GetArea(i)
            set this.damage = GetDamage(i) * T32_PERIOD
            set this.duration = GetDuration(i)
            set this.dummyGroup = NewGroup()
            set this.targetGroup = NewGroup()
            set p = GetOwningPlayer(this.caster)
            set x = GetUnitX(this.caster)
            set y = GetUnitY(this.caster)
            set a = Atan2(GetSpellTargetY() - y, GetSpellTargetX() - x)
            
            set t = NewTimer()
            call SetTimerData(t, this)
            call TimerStart(t, GetDelay(i), false, function thistype.timeOut)
            
            set i = R2I(GetDistance(i) / DINTERVAL)
            loop
                exitwhen i == 0
                set r = DINTERVAL * i
                call GroupAddUnit(this.dummyGroup, CreateUnit(p, DUMMYID, x + r * Cos(a), y + r * Sin(a), 0))
                set i = i - 1
            endloop
        endif
        
        set t = null
        set p = null
        return false
    endmethod

    private static method onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t, Condition(function thistype.actions))
        set tempCaster = CreateUnit(Player(13), CASTERID, 0, 0, 0)
        call UnitAddAbility(tempCaster, DUMABILID)
        set t = null
    endmethod
endstruct

endscope
 

Sevion

The DIY Ninja
Reaction score
413
A little advice, instead of using a constant boolean for Damage, use [ljass]static if LIBRARY_DAMAGE[/ljass].

Also, there are a few things that can be made more efficient.

I.E. In filterFunc:

JASS:
// blah blah
            if HaveSavedInteger(dataHash, id, 0) then
                //set that = LoadInteger(dataHash, id, 0)
                //call GroupRemoveUnit(that.targetGroup, u) These two lines can be turned into:
                call GroupRemoveUnit(thistype(LoadInteger(dataHash,id,0)).targetGroup, u)
                // Which also removes the need for that extra "that" variable
            endif
// blah blah


As for the original problem, we can tell that the reason the stun is not being removed is because something happened with the timer or a variable (probably the unit variable).

Try finding all the points in which you destroy timers or remove units from groups etc. and displaying some data like the unit's name or type id etc.

See what's going down in the code.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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