• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] *Solved* Issue with Knockback library and Hashtables

I'm using Knockback v1.01b to make a dash spell that should continue until the unit hits an enemy hero, however occasionally it will pass straight through an enemy hero. Not entirely sure why it happens because I couldn't re-create it afterwards. The library has a flaw where it will run on hit actions periodically instead of once per collision so I made a setup involving hashtables to fix that. I suspect that's where I'm going wrong. Code for InstantKill function can be found here: Triggers

edit: Bonus points if you can teach me how to use a library like Table Triggers for this spell while still making it MUI

Solved: I don't need a hit tracker for this spell to begin with and only added one out of habit oops

I DO need a hit tracker for this spell because otherwise it would deal damage every period the units are touching

JASS:
//TESH.scrollpos=29
//TESH.alwaysfold=0
scope DashHit initializer onInit

    globals
        private KnockbackType ScopedKnockbackType
    private hashtable hitTracker = InitHashtable()
    private integer AID = 'A00A'
    private real DAMAGE = 1000.
    endglobals

    //when the units hits another unit
    private function onUnitHit takes Knockback kb, unit hit returns nothing
    if IsUnitEnemy(hit,GetOwningPlayer(kb.caster)) and UnitAlive(hit) and not BlzIsUnitInvulnerable(hit) and not IsUnitType(hit,UNIT_TYPE_STRUCTURE) and not HaveSavedBoolean(hitTracker,GetHandleId(kb.target),GetHandleId(hit)) then
        call SaveBoolean(hitTracker,GetHandleId(kb.target),GetHandleId(hit),true)
        if IsUnitType(hit,UNIT_TYPE_HERO) then
            call UnitDamageTargetBJ(kb.target, hit, DAMAGE, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL)
            call SetUnitAnimation(kb.target,"attack slam")
            call kb.destroy()
        else
            call InstantKill(GetOwningPlayer(kb.target),hit,GetUnitX(kb.target),GetUnitY(kb.target))
        endif
    endif
    endfunction

    private function onTargetDeath takes Knockback kb returns boolean
        return false
    endfunction

    private function onLoop takes Knockback kb returns nothing
        if GetUnitCurrentOrder(kb.caster) != OrderId("selfdestruct") or not UnitAlive(kb.caster) or IsUnitPaused(kb.caster) then
            call kb.destroy()
        endif
    endfunction

    private function onEnd takes Knockback kb returns nothing
        call FlushChildHashtable(hitTracker, GetHandleId(kb.target))
        call TriggerSleepAction(1.0)
        call ResetUnitAnimation(kb.target)
    endfunction

    //start the knockback
    private function onCast takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local Knockback kb
    set kb=Knockback.create(u, u, 1000., 1.0, GetUnitFacing(u), ScopedKnockbackType)
    set u=null
    endfunction
    
    //init
    private function onInit takes nothing returns nothing
    call RegisterSpellEffectEvent(AID, function onCast)
        set ScopedKnockbackType = KnockbackType.create()
        set ScopedKnockbackType.onUnitHitAction = onUnitHit
        set ScopedKnockbackType.onLoopAction = onLoop
        set ScopedKnockbackType.onTargetDeathAction = onTargetDeath
    set ScopedKnockbackType.onEndAction = onEnd
    endfunction

endscope
 
Last edited:
Top