• 🏆 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!

[JASS] Spell doesn't work

Status
Not open for further replies.
Level 8
Joined
Jul 28, 2008
Messages
211
I've wanted to make a spell so here it is

JASS:
scope MindBlast initializer Init

//========================================SETUP========================================

globals

    constant integer SPELL_ID           = 'A000'
    constant integer DUMMY_ID           = 'h000'
    constant string ATTACHMENT_POINT    = "overhead"
    constant string DAMAGE_EFFECT       = "Abilities\\Spells\\Undead\\DeathPact\\DeathPactTarget.mdl"
    constant string AOE_EFFECT          = "Abilities\\Spells\\Undead\\ReplenishMana\\ReplenishManaCasterOverhead.mdl"
    constant attacktype ATTACK_TYPE     = ATTACK_TYPE_MAGIC
    constant damagetype DAMAGE_TYPE     = DAMAGE_TYPE_MIND
    
endglobals

private function Damage takes integer level returns real
    return I2R(75 + 25 * level)
endfunction

private function Area takes integer level returns real
    return I2R(175 + level * 75)
endfunction

private function Targets takes unit target returns boolean
    return (GetWidgetLife(target) > 0.405) and (IsUnitType(target, UNIT_TYPE_STRUCTURE) == false ) and (IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE) == false) and (IsUnitType(target, UNIT_TYPE_MECHANICAL) == false)
endfunction

//=====================================END OF SETUP=====================================

globals

    group all
    boolexpr b
    
endglobals

private function Pick takes nothing returns boolean
    return Targets( GetFilterUnit() )
endfunction
    
private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID
endfunction

private function Actions takes nothing returns nothing
    local unit temp
    local unit caster = GetTriggerUnit()
    local integer lvl = GetUnitAbilityLevel( caster, SPELL_ID )
    local location spellTarget = GetSpellTargetLoc()
    local real spellX = GetLocationX(spellTarget)
    local real spellY = GetLocationY(spellTarget)
    call DestroyEffect( AddSpecialEffect( AOE_EFFECT, spellX, spellY ) )
    call GroupEnumUnitsInRange(all, spellX, spellY, Area(lvl), b )
    loop
      set temp = FirstOfGroup(all)
      exitwhen temp == null
      if IsUnitAlly(temp, GetOwningPlayer(caster)) then
        call DestroyEffect( AddSpecialEffectTarget( DAMAGE_EFFECT, temp, ATTACHMENT_POINT ) )
        call UnitDamageTarget(caster, temp, Damage * lvl, false, true, ATTACK_TYPE, DAMAGE_TYPE, null )
      endif
      call GroupRemoveUnit(all, temp)
    endloop
    call RemoveLocation(spellTarget) 
    set caster = null
    set spellTarget = null
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 Conditions ) )
    call TriggerAddAction(t, function Actions )
    
    set all = CreateGroup()
    set b = Condition( function Pick )
    
    call Preload(DAMAGE_EFFECT)
    call Preload(AOE_EFFECT)
    call CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), DUMMY_ID, 0, 0, 0 )
    call UnitAddAbility( bj_lastCreatedUnit, SPELL_ID )
    call KillUnit(bj_lastCreatedUnit)
endfunction

endscope

The problem is, when i cast the spell, it doesn't effect the units in the aoe. When i cast it near the caster, the effect is created above his head, but it doesn't damage him. Can someone tell me why does this happen?

Oh, and i have another problem. I based my ability on channel. I set it to unit target, and later i changed it to point target and set the area of effect. But it doesn't show the area when i cast the spell. Like its just point target without aoe.

So can someone help me?
 

Attachments

  • Mind Blast.w3x
    30.9 KB · Views: 43
Level 16
Joined
Oct 12, 2008
Messages
1,570
i think a unit cant damage itself? And why would you damage allys?
if IsUnitAlly(temp, GetOwningPlayer(caster)) then

Why does it need to be ally if you want to Damage? I would guess it should be this:?
if IsUnitEnemy(temp, GetOwningPlayer(caster)) then

Though this is only from my point of view.. Otherwise i dont know what could be wrong,,

EDIT: Dang,, EoW was first =\ xD
 
Level 8
Joined
Feb 15, 2009
Messages
463
Also why u use the pick function as boolexpr and not just the Targets function as one? this is just useless stretching of code coz it does the same

i would save the effects in variables and destroy then coz a destroyed effect still leaks for ca. 0.69 kb , an nulled for 0.066 kb(not a big improve but in masses this affects 2 )
setting caster null is useless and just lengthens your code

Also this line
JASS:
    return (GetWidgetLife(target) > 0.405) and (IsUnitType(target, UNIT_TYPE_STRUCTURE) == false ) and (IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE) == false) and (IsUnitType(target, UNIT_TYPE_MECHANICAL) == false)

can be shortened to
JASS:
    return (GetWidgetLife(target) > 0.405) and (IsUnitType(target, UNIT_TYPE_STRUCTURE)  and IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE)and IsUnitType(target, UNIT_TYPE_MECHANICAL) ) == false

Also get system xe to have a better preload ( if u want one then take this ,but i never use coz this will improve my loading time and i rather preload them at hero picking having a small lag there)
 
Status
Not open for further replies.
Top