- Joined
- May 21, 2009
- Messages
- 994
hello, i wanted to make a spell ( not for this site ) but for a site which doesnt have that many spells. So i decided to make a simple one along with some others.. its supposed to heal every unit around the caster but it only heals the caster but the effect still spawns on the units. I did this mostly for practising jass.
Here is the code:
Here is the code:
JASS:
scope healarea initializer Init
globals
//The spell ID of the casted ability. If you dont know how to get it go in
//object editor and click CTRL + D and you can see the raw id of your spell
private constant integer SPELL_ID = '#000'
//The spell effect which appear on every of the target units
private constant string HEALSFX = "Abilities\\Spells\\Human\\Heal\\HealTarget.mdl"
//This is just needed in a function where i destroy it.. just dont touch it
private effect HEAL_SFX_EF
//below you can change the AoE and the amount that is being healed. If you use any custom damage
//or whatever then you can change the formular to also affect the strength etc..
endglobals
private function GetHeal takes integer lvl returns integer
return 80 * lvl
endfunction
private function GetAoE takes integer lvl returns real AoE
return (250 * I2R(lvl))
endfunction
private function ReturnTrue takes nothing returns boolean
return true
endfunction
private function DestroyEffectZ takes nothing returns nothing
call DestroyEffect(HEAL_SFX_EF)
endfunction
private function Healing takes nothing returns nothing
local timer t = CreateTimer()
local unit u = GetEnumUnit()
local integer l = GetUnitAbilityLevel(u, SPELL_ID)
local real chp = GetWidgetLife(u)
local real nv = chp + GetHeal(l)
local real x = GetUnitX(u)
local real y = GetUnitY(u)
call SetWidgetLife(u, nv)
set HEAL_SFX_EF = AddSpecialEffect(HEALSFX, x, y)
call TimerStart( t, 0.50, false, function DestroyEffectZ )
set u = null
endfunction
private function HealAll takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer l = GetUnitAbilityLevel(u, SPELL_ID)
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local group g = CreateGroup()
//then just do the normal
call GroupEnumUnitsInRange(g, x, y, GetAoE(l), Filter( function ReturnTrue))
call GroupAddUnit(g, GetEnumUnit())
call ForGroup(g, function Healing)
call DestroyGroup(g)
set u = null
set g = null
endfunction
private function HealAllCondition takes nothing returns boolean
if GetSpellAbilityId() == SPELL_ID then
call ExecuteFunc("HealAll")
return true
else
return false
endif
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition(t, Condition(function HealAllCondition))
call TriggerAddAction( t, function HealAll )
endfunction
endscope