• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Strange bug ?

Status
Not open for further replies.
Level 12
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:
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
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Oh dear, please learn the proper indenting conventions. Also, your condition should just return whether the spell cast was SPELL_ID, rather than executing the action (seeing as the action will be automatically executed due to being attached to the trigger).

The null boolexpr leak bug is fixed as of 1.24c and thus you don't need the ReturnTrue thing. Also, why are you adding GetEnumUnit() (which is null) to g?

Next, your timer is not multiinstanceable.

Finally, your problem is likely this line in "Healing":

JASS:
local integer l = GetUnitAbilityLevel(u, SPELL_ID)

It should be:

JASS:
local integer l = GetUnitAbilityLevel(GetTriggerUnit(), SPELL_ID)
 
Status
Not open for further replies.
Top