Warcraft III resources & community, 2003–2006 · archived

Help with this code - Game crashes!!

32 posts
#1

Help with this code - Game crashes!!

I am just starting - this is my first code after reading Daelin's perfect tutorial. This trigger is supposed to cause a certain damage to the attacked unit, when a unit of type H000 attacks and the target takes the damage. Unfortunately the game is closed right after being attacked.

function ManaLeakCond1 takes nothing returns boolean
    return GetUnitTypeId(GetAttacker()) == 'H000'
endfunction

function ManaLeakCond2 takes nothing returns boolean
   return udg_AE_ManaLeakActive
endfunction

function ManaLeakAndCond takes nothing returns boolean
    return GetBooleanAnd(ManaLeakCond1(), ManaLeakCond2())
endfunction

function ManaLeakDamage takes nothing returns nothing
    local integer Level
    local integer Int
    set udg_AE_ManaLeakDamage = 1.00
    set Int = 0
    set Level = GetUnitAbilityLevelSwapped('A003', udg_AECaster)
    loop
        exitwhen Int >= Level
        set udg_AE_ManaLeakDamage = udg_AE_ManaLeakDamage * 2
        set Int = Int + 1
    endloop
    call UnitDamageTargetBJ( udg_AECaster, udg_AE_ManaLeakTarget, udg_AE_ManaLeakDamage, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
    call SetUnitManaBJ (udg_AE_ManaLeakTarget, GetUnitStateSwap( UNIT_STATE_MANA, udg_AE_ManaLeakTarget) - udg_AE_ManaLeakDamage )
    call SetUnitManaBJ (udg_AECaster, GetUnitStateSwap( UNIT_STATE_MANA, udg_AECaster) - 1 )
    call DestroyTrigger(udg_AE_ManaLeakTrigger)
    set udg_AE_ManaLeakTrigger = null
    set udg_AE_ManaLeakTarget = null
    set udg_AECaster = null
endfunction

function ManaLeakAct takes nothing returns nothing
    set udg_AE_ManaLeakTarget = GetAttackedUnitBJ()
    set udg_AECaster = GetAttacker()
    set udg_AE_ManaLeakTrigger = CreateTrigger()
    call TriggerRegisterUnitEvent (udg_AE_ManaLeakTrigger, udg_AE_ManaLeakTarget, EVENT_UNIT_DAMAGED)
    call TriggerAddAction (udg_AE_ManaLeakTrigger, function ManaLeakDamage )
endfunction

//===========================================================================
function InitTrig_AE_Mana_Leak takes nothing returns nothing
    set gg_trg_AE_Mana_Leak = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_AE_Mana_Leak, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition (gg_trg_AE_Mana_Leak, Condition(function ManaLeakAndCond))
    call TriggerAddAction( gg_trg_AE_Mana_Leak, function ManaLeakAct )
endfunction


The spell name is Mana Leak. It's based on Defend, so I can activate and deactivate it. There's a trigger that changes AE_ManaLeakActive (I'm sure that the problem is not with that one). Hope I'm not wasting your time, maybe it's an idiot spelling mistake...

Already THANKS
Hossomi

[edit: Jass codes in this site looks beautiful :P]
#2
Try this. I got no specific idea, where your fault could be, but maybe it is already fixed now...

function ManaLeakDamage takes nothing returns nothing
  local integer int
  set udg_AE_ManaLeakDamage = 1.00
  set int = GetUnitAbilityLevel(udg_AECaster,'A003')
  set udg_AE_ManaLeakDamage = udg_AE_ManaLeakDamage * Pow(2,int)
  call UnitDamageTarget(udg_AECaster,udg_AE_ManaLeakTarget,udg_AE_ManaLeakDamage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
  call SetUnitState(udg_AE_ManaLeakTarget,UNIT_STATE_MANA,RMaxBJ(0,GetUnitState(udg_AE_ManaLeakTarget,UNIT_STATE_MANA) - udg_AE_ManaLeakDamage))
  call SetUnitState(udg_AECaster,UNIT_STATE_MANA,RMaxBJ(0,GetUnitState(udg_AECaster,UNIT_STATE_MANA) - 1))
  set udg_AE_ManaLeakTarget = null
  set udg_AECaster = null
  call DestroyTrigger(udg_AE_ManaLeakTrigger)
endfunction
 
function ManaLeakAct takes nothing returns nothing
  if GetUnitTypeId(GetAttacker()) == 'H000' and udg_AE_ManaLeakActive then
    set udg_AE_ManaLeakTarget = GetTriggerUnit()
    set udg_AECaster = GetAttacker()
    set udg_AE_ManaLeakTrigger = CreateTrigger()
    call TriggerRegisterUnitEvent(udg_AE_ManaLeakTrigger,udg_AE_ManaLeakTarget,EVENT_UNIT_DAMAGED)
    call TriggerAddAction(udg_AE_ManaLeakTrigger,function ManaLeakDamage)
  endif
endfunction

function InitTrig_AE_Mana_Leak takes nothing returns nothing
  set gg_trg_AE_Mana_Leak = CreateTrigger()
  call TriggerRegisterAnyUnitEventBJ(gg_trg_AE_Mana_Leak,EVENT_PLAYER_UNIT_ATTACKED)
  call TriggerAddAction(gg_trg_AE_Mana_Leak,function ManaLeakAct)
endfunction


If it still does not work, write this into some places of the code:
call BJDebugMsg("Part: <something, that identifies the part of code, we are inside now> ")

Then try and tell me, which of these messages appeared last before your game crashes.
#3
local integer int
      [...]
      set int = GetUnitAbilityLevel(udg_AECaster,'A003')


thank god that you fixed 99% of the BJ calls, etc, etc in that code... i was dreading doing it :D

anyways, that can easily be

local integer int = GetUnitAbilityLevel(udg_AECaster,'A003')


why didnt you do that in the first place? :P

also, GetBooleanAnd = WTF

instead of using those 3 functions, with the


function a takes nothing returns boolean
return ThisIsACondition
endfunction

function b takes nothing returns boolean
return ThisIsAnotherCondition
endfunction

function And takes nothing returns boolean
return GetBooleanAnd( a,b )
endfunction


just write

function And takes nothing returns boolean
return ThisIsACondition and ThisIsAnotherCondition
endfunction
#4
hehahaha sorry PurplePoot, and thanks both for help :D
because, as I said, this is my first code, so I based on Converted GUI-JASS heheh

Sorry LordZsar1 for your work, rewriting almost all the code!

Well.. I've tried this many times to find where the problem is, and it is exactly in the UnitDamageTarget call.

Some questions LordZsar, why do you use RMaxBJ to change mana? And what are those 'true' and 'false' in DamageTarget?
#5
UnitDamageTarget is weird, and sometimes gets a litlle buggy

Anyways, idk what hes doing with the RMaxBJ, but for the UnitDamageTarget, try replacing WEAPON_TYPE_WHOKNOWS with null, and making sure the variables are all correctly assigned.

(and that Thank God You Cleaned Up The Script was direced to you, Zsar :P)
#6
It doesn't work yet, but I've discovered more about this problem: it crashes just because the event of the local trigger is EVENT_UNIT_DAMAGED. I had another spell almost the same, and then I put everything in just one, with EVENT_PLAYER_UNIT_ATTACKED event, and it worked. The same happened with Mana Leak.

So I'll make Mana Leak with 'A unit is attacked' event, to finish with this :D
#7
The crash is caused by a deadly circle. The trigger fires when the unit is damaged, but the trigger damages that unit, tre trigger fires again, damages the unit, and so on.... This way, the trigger would run infinite times.
Solution:
Destroy the trigger first, and THEN damage the unit. If you destroy the trigger right after you declare the locals, the trigger will still run, it will not break the action.

And forget EVENT_UNIT_ATTACKED. That is what causes strange things and not UnitDamageTarget...
#8
I really dont know how i missed that :shock:

anyways, lol, you could also make sure GetEventDamageSource() != AE_whatever
#9
uhuuullll that's it!!!! *jumping happy*
Thank you three for help! I learned many things with this topic :P



(AE is because the hero name is Aeria, and there will be only one)
#10
Well, in that case, you should probably use a dummy o do the dmg, or donut's way, so that Ae can normally do dmg.
#11
Rewriting code (or writing code from description) is my way to have fun. ^^

That is the only cause, that makes me visiting this forum: One may ask for code, I may write.
I lack the stamina to create a whole map and metascript by myself. ^^
(started 12 maps, 3 AIs, 2 metascripts... finished none)

Hell, I should have seen this! ~~
As I wrote somewhere else: Sometimes I feel very stupid. ^^
#12
*i meant pasks way, just reading multiple posts at once and thinking donut for some reason :roll:
#13
Rewrite the script, use locals instead of globals. They aren't needed here.
#14
Uh.. no? I think they are since I use the same variable in many functions...
#15
Handle Vars.