Well I created my first vJASS spell but it doesn't work, can you find the problem in my code?
I also recommend checking the map too, but its your choice. I see the AOE_EFFECT but it wont damage the units. There should be an effect showing that the units are being damaged, so. Here it is!
I also recommend checking the map too, but its your choice. I see the AOE_EFFECT but it wont damage the units. There should be an effect showing that the units are being damaged, so. Here it is!
JASS:
scope HitlnS initializer init
//**************************************************************************
//
// Hitling 1.0
// =======
// SPELL_ID : Rawcode of the custom ability found in the object editor based
// on the spell Cluster Rockets, change the SPELL_ID code found
// in the first globals section, remember to avoid editing all
// the codes after it. It might mess the spell up, so avoid
// editing the core itself.
//
// DUMMY_ID : Rawcode of the custom unit found in the object editor based on
// the unit footman, it appears invisible because it has no model
// in it. I didn't used the dummy.mdx since I dont have it ATM,
// anyway. This is only used to preload the ability itself to
// avoid lags ingame.
//
// AOE_EFFECT : This is only used for effects, you can change it to anything you
// want, replace all '\' to '\\' in order for it to work.
//
// DAMAGE_EFFECT : This is the effect that appears on the origin of the damaged
// /affected unit. If you want to change the effect, replace all '\'
// to '\\' in order for it to work.
//
// D_TYPE : This is the damage type of the ability, you can change it to what-
// ever you want, basically, this is the one if the spell is magic or
// sonic or what element is it (cold, fire, darkness, etc.).
//
// A_TYPE : This is the attack type of the ability, you can change it to what-
// ever you want, but, I recomment normal since it might be weird in-
// game if you change it to something else.
//
// Please give me comments, tips, or suggestions to help me improve my vJASSing
// skill, thank you for taking a look for my code.
//
//**************************************************************************
//===========================================================================
//Globals Start (you can edit the things below here).
globals
// RawCODE of the ability. Change it to the rawcode of your ability in the object editor if you have more than one spell.
private constant integer SPELL_ID = 'A000'
private constant integer DUMMY_ID = 'h000'
private constant string AOE_EFFECT = "Abilities\\Spells\\Other\\Incinerate\\FireLordDeathExplode.mdl"
private constant string DAMAGE_EFFECT = "Abilities\\Spells\\Other\\Incinerate\\IncinerateBuff.mdl"
private constant damagetype D_TYPE = DAMAGE_TYPE_SONIC
private constant attacktype A_TYPE = ATTACK_TYPE_NORMAL
endglobals
private function Range takes integer level returns real
return level * 300.
endfunction
private function Damage takes integer level returns real
return level * 100.
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_FLYING) == false) and (IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE) == false) and (IsUnitType(target, UNIT_TYPE_MECHANICAL) == false)
endfunction
//Globals End (you can't edit the things below here).
globals
private group all
private group copy
private boolexpr b
endglobals
private function CopyGroup takes group g returns group
set bj_groupAddGroupDest = CreateGroup()
call ForGroup(g, function GroupAddGroupEnum)
return bj_groupAddGroupDest
endfunction
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 location l = GetSpellTargetLoc()
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local unit c = GetTriggerUnit()
local integer level = GetUnitAbilityLevel(c, SPELL_ID)
local unit f
local integer enemies = 0
call DestroyEffect(AddSpecialEffect(AOE_EFFECT, x, y))
call GroupEnumUnitsInRange(all, x, y, Range(level), b)
loop
set f = FirstOfGroup(copy)
exitwhen(f == null)
call GroupRemoveUnit(copy, f)
if IsUnitEnemy(f, GetOwningPlayer(c)) then
set enemies = enemies + 1
endif
endloop
if enemies > 0 then
loop
set f = FirstOfGroup(all)
exitwhen(f == null)
call GroupRemoveUnit(copy, f)
if IsUnitEnemy(f, GetOwningPlayer(c)) then
call DestroyEffect(AddSpecialEffectTarget(DAMAGE_EFFECT, f, "origin"))
call UnitDamageTarget(c, f, Damage(level), true, false, A_TYPE, D_TYPE, null)
endif
endloop
endif
call RemoveLocation(l)
set l = null
set c = 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)
//Setting Globals
set all = CreateGroup()
set copy = CreateGroup()
set b = Condition(function Pick)
//Preloading Effects
call Preload(AOE_EFFECT)
call Preload(DAMAGE_EFFECT)
//Preloading the ability
set bj_lastCreatedUnit = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), DUMMY_ID, 0, 0, 0)
call UnitAddAbility(bj_lastCreatedUnit, SPELL_ID)
call KillUnit(bj_lastCreatedUnit)
endfunction
endscope