- Joined
- Jul 26, 2008
- Messages
- 1,009
Alright I made a spell called Drain. The unit channels it (Based off channel, orderID "magicleash", follow through 10.) after targeting a unit.
It transfers HP to allies and can drain life from enemies. More effective when you're closer to 100% HP. Problem is it refuses to show the lightning, and right now it refuses to drain life period.
Could someone help me out by giving me optomization tips and perhaps pinpointing the bugs that I seem to be overlooking? Thanks!
It transfers HP to allies and can drain life from enemies. More effective when you're closer to 100% HP. Problem is it refuses to show the lightning, and right now it refuses to drain life period.
Could someone help me out by giving me optomization tips and perhaps pinpointing the bugs that I seem to be overlooking? Thanks!
JASS:
scope Drain initializer InitTrig_Drain
globals
private constant integer SPELLID = 'drai'
private constant real tick = 0.1
private constant attacktype atk = ATTACK_TYPE_NORMAL
private constant damagetype dmg = DAMAGE_TYPE_MAGIC
endglobals
private struct Data
unit c
unit t
lightning lig
real dur
static method onLoop takes nothing returns nothing
local timer tim = GetExpiredTimer()
local Data D = Data(GetTimerData(tim))
local real HDrain = GetWidgetLife(D.c)/GetUnitState(D.c, UNIT_STATE_MAX_LIFE)
local real lvl = GetUnitAbilityLevel(D.c, SPELLID)
local real EHp = GetWidgetLife(D.t)
set HDrain = lvl*SpellStat(D.c, true)*HDrain
call MoveLightning(D.lig, true, GetUnitX(D.c), GetUnitY(D.c), GetUnitX(D.t), GetUnitY(D.t))
if not(IsUnitType(D.t, UNIT_TYPE_DEAD)) and not(IsUnitType(D.c, UNIT_TYPE_DEAD)) and D.dur <= 10 and IsUnitEnemy(D.t, GetOwningPlayer(D.c)) and GetUnitCurrentOrder(D.c) == OrderId("chainlightning") then
if IsUnitEnemy(D.t, GetOwningPlayer(D.c)) then
call DamageUnitByTypes(D.c, D.t, HDrain*tick, atk, dmg)
set EHp = EHp - GetWidgetLife(D.t)
call SetWidgetLife(D.c, GetWidgetLife(D.c)+EHp)
else
call SetWidgetLife(D.c, GetWidgetLife(D.c) - HDrain)
call SetWidgetLife(D.t, (GetWidgetLife(D.t) + HDrain)*0.75)
endif
else
call DestroyLightning(D.lig)
set D.lig = null
set D.c = null
set D.t = null
call ReleaseTimer(tim)
call D.destroy()
endif
set D.dur = D.dur + tick
endmethod
static method create takes unit caster, unit target returns Data
local timer tim = NewTimer()
local Data D = Data.allocate()
set D.c = caster
set D.t = caster
set D.lig = AddLightning("AFOD", true, GetUnitX(D.c), GetUnitY(D.c), GetUnitX(D.t), GetUnitY(D.t))
set D.dur = 0
call SetTimerData(tim,D)
call TimerStart(tim, tick, true, function Data.onLoop)
return D
endmethod
endstruct
private function Conditions takes nothing returns boolean
if GetSpellAbilityId() == SPELLID then
call Data.create(GetTriggerUnit(), GetSpellTargetUnit())
endif
return false
endfunction
//===========================================================================
public function InitTrig_Drain takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( t, Condition( function Conditions ) )
endfunction
endscope