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

[JASS] Need help once again

Status
Not open for further replies.
Level 8
Joined
Jul 28, 2008
Messages
211
I made a spell:

JASS:
scope Echo initializer Init

globals

    private constant integer SPELL_ID = 'A000'
    private constant real DURATION = 10.00
    private hashtable h = InitHashtable()

endglobals

private function Damage takes integer lvl returns real
    return I2R(lvl)
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID
endfunction

private function Echo_Child takes nothing returns nothing
    local trigger t = GetTriggeringTrigger()
    local unit c = LoadUnitHandle(h, GetHandleId(t), 0)
    local unit target = LoadUnitHandle(h, GetHandleId(t), 1)
    local integer lvl = LoadInteger(h, GetHandleId(t), 2)
    local real d = GetEventDamage() * Damage(lvl)
    local texttag text = CreateTextTag()
    
    call UnitDamageTarget(c, target, d, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    call SetTextTagPos(text, GetUnitX(target), GetUnitY(target), 10.00 * 0.023 / 10)
    call SetTextTagText(text, I2S(R2I(d)), 10.00 * 0.023 / 10)
    call SetTextTagColor(text, 190, 45, 45, 0)
    call SetTextTagLifespan(text, 2.00)
    call SetTextTagVelocityBJ( text, 64, 90 )
    call SetTextTagVisibility(text, true)
    set t = null
    set c = null
    set target = null
    call TriggerSleepAction(2.00)
    call DestroyTextTag(text)
    set text = null
endfunction

private function Actions takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local unit targ = GetSpellTargetUnit()
    local trigger t = CreateTrigger()
    local triggeraction a = TriggerAddAction(t, function Echo_Child)
    call TriggerRegisterUnitEvent(t, targ, EVENT_UNIT_DAMAGED)
    
    call SaveUnitHandle(h, GetHandleId(t), 0, c)
    call SaveUnitHandle(h, GetHandleId(t), 1, targ)
    call SaveInteger(h, GetHandleId(t), 2, GetUnitAbilityLevel(c, SPELL_ID))
    
    call TriggerSleepAction(DURATION)
    call FlushChildHashtable(h, GetHandleId(t))
    call TriggerRemoveAction(t, a)
    call DestroyTrigger(t)
    set t = null
    set c = null
    set targ = null
    set a = null
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Conditions))
    call TriggerAddAction(t, function Actions)
endfunction

endscope

It crashes the game when the unit gets attacked.

But, when i change the
JASS:
call UnitDamageTarget(c, target, d, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
into
JASS:
call UnitDamageTarget(c, c, d, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
it works fine. So what's the problem?

Thanks in advance.

PS: I know about the BJ but I was too lazy to replace it. I'll do that later.
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
This is just a guess, but I think you're creating an infinite loop.
You're damaging the target in an event that's checking when the target gets damaged. I think you need to disable the trigger for a while.

By the way, there's a better way to destroying texttags:
JASS:
call SetTextTagFadepoint(YourTextTag,FadeTime) //When the texttag should start fading.         
call SetTextTagLifespan(YourTextTag,LifeTime) //How long you want the texttag to last
call SetTextTagPermanent(YourTextTag,false) //Do this so that it can be destroyed
 
Status
Not open for further replies.
Top