- Joined
- Aug 7, 2013
- Messages
- 1,338
Hi,
So I made a custom spell based off of channel and triggered it.
The spell works fine, except there are two problems:
1. if a hero levels up while using the spell, it will not pick up its Attack Tome
the tome will be left on the ground for anyone to pick up
2. if a ranged hero kills another unit while using spell, the cooldown will not reset
this means the hero can immediately use the spell again!
The spell is based off of Channel (ANcl) and has two versions: a melee based one and a ranged based one. How can I fix the two problems above with minimal changes to the code, and hopefully no dummy units.
So I made a custom spell based off of channel and triggered it.
The spell works fine, except there are two problems:
1. if a hero levels up while using the spell, it will not pick up its Attack Tome
the tome will be left on the ground for anyone to pick up
2. if a ranged hero kills another unit while using spell, the cooldown will not reset
this means the hero can immediately use the spell again!
The spell is based off of Channel (ANcl) and has two versions: a melee based one and a ranged based one. How can I fix the two problems above with minimal changes to the code, and hopefully no dummy units.
JASS:
scope AttackTrig initializer init
globals
constant integer ATTACK_MELEE = 'ATT0'
constant integer ATTACK_RANGED = 'ATT1'
constant integer BASE_DAMAGE = 5
constant integer MELEE_MULTIPLIER = 6
constant integer RANGED_MULTIPLIER = 5
endglobals
private function main takes nothing returns boolean
local integer spellId = GetSpellAbilityId()
local unit target
local unit caster
local player p
local integer pid
local real damage
local Monster m
if spellId == ATTACK_MELEE or spellId == ATTACK_RANGED then
set target = GetSpellTargetUnit()
if target == null then
call printl("thinks the target is null")
endif
set caster = GetTriggerUnit()
set p = GetOwningPlayer(caster)
set pid = GetPlayerId(p)
set m = playerDatum[pid].party.getMonsterByUnit(caster)
if spellId == ATTACK_MELEE then
set damage = BASE_DAMAGE + (m.attrPts[ATT] * MELEE_MULTIPLIER)
else
set damage = BASE_DAMAGE + (m.attrPts[ATT] * RANGED_MULTIPLIER)
endif
call UnitDamageTarget(caster, target, damage, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL, null)
//call KillUnit(target)
call printl("did : " + R2S(damage) + " damage.")
endif
return false
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
call TriggerAddCondition(t, Condition(function main))
endfunction
endscope