• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Jass quesion

Status
Not open for further replies.
Level 6
Joined
Oct 1, 2012
Messages
166
Heloes Hive Workshop

I have a problem with my code:

JASS:
function dostal_f takes nothing returns nothing
    local unit cel = GetTriggerUnit()
    local unit atak = GetEventDamageSource()
    local integer nr = GetConvertedPlayerId(GetOwningPlayer(atak))
    call DisplayTextToForce(GetPlayersAll(), "ta")
    if (GetUnitAbilityLevel(atak, 'A020') == 1) and (UnitHasBuffBJ(cel, 'B001') and GetUnitAbilityLevel(atak, 'A000') == 1) then
     call UnitRemoveAbility(atak, 'A020')
    endif
    if IsUnitType(atak, UNIT_TYPE_SUMMONED) then
    call DisplayTextToForce(GetPlayersAll(), "tak")
     if GetUnitAbilityLevel(udg_Bohater_gracza[nr], 'A024') == 1 then
     call DisplayTextToForce(GetPlayersAll(), "takk")
      call UnitDamageTargetBJ(atak, cel, obrmag(nr, udg_Bohater_gracza[nr], 0.3), ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL)
     endif
    endif
    set cel = null
    set atak = null
endfunction

function Trig_Strzal_Actions takes nothing returns nothing
    local trigger dostal = CreateTrigger()
    local unit cel = GetTriggerUnit()
    call DisplayTextToForce(GetPlayersAll(), "t")
    call TriggerRegisterUnitEvent(dostal, cel, EVENT_UNIT_DAMAGED)
    call TriggerAddAction(dostal, function dostal_f)
    call DestroyTrigger(dostal)
    set cel = null
    set dostal = null
endfunction

//===========================================================================
function InitTrig_DMG takes nothing returns nothing
    set gg_trg_DMG = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_DMG, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddAction( gg_trg_DMG, function Trig_Strzal_Actions )
endfunction


The upper function is no matter, it works. But about the middle one - the DestroyTrigger causes the upper function to not work (as the trigger is destroyed). When I tried TriggerSleepAction, it simply turned wc3 off for some reason.

Any ideas how to make it work?

(The "tak" massages are debug massages)
 
Level 6
Joined
Oct 1, 2012
Messages
166
But when I do, it doesn' see the trigger. I mean, the wc3 editor says

'Name required' (or sth lile that)

The damage detection is pretty much too complex, this one would work nicely, as far as I'm concerned.
 
Level 6
Joined
Oct 1, 2012
Messages
166
Thanks for that.

It was not the problem, though.

For some reason, the summoned unit, when I called UnitDamageTargetBJ, would crash the game. I simply changed the damaging unit to the summoner, it doesn't matter actually.

+rep, topic solved
 
Level 6
Joined
Oct 1, 2012
Messages
166
Well, the trigger destroying function isn't crashing the game, the UnitDamageTargetBJ is and I don't know why. With the summon there was no problem, I just changed the damaging unit to the summoner, but when it came to damaging with the hero himself, the game would crash too.

Any ideas?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Infinite loop? Damaging a unit with triggers does fire any damage events the unit has. I think it goes as far as to interrupt the current trigger thread to run the event handling trigger. This causes recursion to occur and will deplete the system or game of resources (crash).

You should avoid using BJ functions. They are often wrappers (adapters) to native functions. Calling these native functions directly is considerably faster.
 
Status
Not open for further replies.
Top