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...
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
anyways, that can easily be
local integer int = GetUnitAbilityLevel(udg_AECaster,'A003')
why didnt you do that in the first place?
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
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 )
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
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...
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. ^^