Hi!
I'm trying to get "cleaving attack" work with ranged attacks.
I use this armor detection system: http://www.wc3c.net/showthread.php?t=105849
This is the first time I use JASS, so I'm not sure how to handle these problems:
The code is working so far, spreading damage the way it should. The problem with #1 is, this will trigger with EVERY attack and spell. It should trigger only when using the "normal" attack.
This is the code I got so far:
I'm trying to get "cleaving attack" work with ranged attacks.
I use this armor detection system: http://www.wc3c.net/showthread.php?t=105849
This is the first time I use JASS, so I'm not sure how to handle these problems:
- How do I figure out if the damaged unit was attacked by a melee/ranged attack
OR
How do I figure out if the attack type was not spell/magic/chaos...
- will this be MUI? what do I need to change?
The code is working so far, spreading damage the way it should. The problem with #1 is, this will trigger with EVERY attack and spell. It should trigger only when using the "normal" attack.
This is the code I got so far:
JASS:
scope CleaveSplash initializer Init
globals
private trigger TRG = CreateTrigger()
boolean already_cleaved = false // this shall prevent the "UnitIsDamaged" event to be called infinite by "call UnitDamageTarget"
endglobals
private function PreloadUnits takes nothing returns boolean
call TriggerRegisterUnitEvent(TRG, GetFilterUnit(), EVENT_UNIT_DAMAGED)
return true
endfunction
private function RunConditions takes nothing returns boolean
return (GetUnitAbilityLevel(GetEventDamageSource(),'ANca') > 0) and (already_cleaved == false)
endfunction
private function Run takes nothing returns nothing
//local real f = GetFullDamage(d, a)
//local real r = GetReducedDamage(f, a)
local unit target = GetTriggerUnit() // attacked unit
local location loc = GetUnitLoc(target) // position of attacked unit, from where the AE will be applied
local unit attacker = GetEventDamageSource() // attacking unit
local integer ab_lvl = GetUnitAbilityLevel(attacker,'ANca') // the ability level of the attacking unit; the higher, the more dmg is spread
local real d = GetEventDamage() // used for GetFullDamage()
local real a = GetUnitArmor(target) // used for GetFullDamage, T is used to calculate armor
local real dmg = GetFullDamage(d,a) // FULL damage or REDUCED damage to spread nearby??
local real cleave_dmg
local group enemies = CreateGroup() // ALL units around the attacked unit (allies included)
local real aoe = 200. // Area of effect
local unit temp_unit // temp unit used in the loop
local integer i = 0 // loop integer
// damage code here ---------------------------->
call GroupEnumUnitsInRangeOfLoc(enemies, loc, aoe, null) // pickes all units in "aoe" range of "target" unit
call GroupRemoveUnit(enemies,attacker) // removes the "attacker", so he won't harm himself
set cleave_dmg = ((I2R(ab_lvl)*25 + 5)/100)*dmg // recalculates the spread dmg, based on the ability level [1: 30%; 2: 55%; 3: 80%]
set already_cleaved = true
loop
set temp_unit = FirstOfGroup(enemies)
exitwhen temp_unit == null
call UnitDamageTarget(attacker, temp_unit, cleave_dmg, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
call GroupRemoveUnit(enemies, temp_unit)
endloop
set already_cleaved = false
// damage code end ---------------------------->
call BJDebugMsg("------------------------")
call BJDebugMsg("Damage spread: "+R2S(cleave_dmg))
//call BJDebugMsg("Base Damage: "+R2S(f))
//call BJDebugMsg("Calc'd Damage: "+R2S(r))
// -------------- Leaks
call RemoveLocation(loc)
call DestroyGroup(enemies)
// null
set loc = null
set target = null
set temp_unit = null
set attacker = null
set enemies = null
endfunction
private function Init takes nothing returns nothing
local rect r = GetWorldBounds()
local group g = CreateGroup()
call GroupEnumUnitsInRect(g, r, Condition(function PreloadUnits))
call TriggerAddCondition(TRG, Condition(function RunConditions))
call TriggerAddAction(TRG, function Run)
call RemoveRect(r)
call DestroyGroup(g)
set g = null
set r = null
endfunction
endscope

the trigger will work on all bounces. same with splash and line damage. my solution to your problem here id to re-structure the way you are thinking about your spell. If you want cleave to work on a ranged unit you must store his angle every time he shoots. good luck with that. you should stick with an aoe spell. (this spell is possible but you will always have bugs and glitches with it even if it is coded perfect) systems dont allow it.