MasterOfRa
New Member
- Reaction score
- 10
Im working on a spell for a game im making but it has a glitch.
If you already have a creature out, it kills the old one, but it doesnt create a new one.
I also imagine there is a better way to do this, but i couldnt think of a better way.
If you already have a creature out, it kills the old one, but it doesnt create a new one.
I also imagine there is a better way to do this, but i couldnt think of a better way.
JASS:
library LavaSpawn initializer Init uses AID,LavaLord
EDIT: i forgot to remove the units from the group after checking, making an endless loop. never mind
globals
private constant integer AID_SPELL = AID_LAVA_SPAWN
private constant string FX = "Abilities\\Spells\\Human\\MarkOfChaos\\MarkOfChaosTarget.mdl"
private constant integer SPAWN_ONE = UID_LAVA_SPAWN
private constant integer SPAWN_TWO = UID_LAVA_LORD
endglobals
//===========================================================================
private function Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local location targetLoc = GetSpellTargetLoc()
local real x = GetLocationX(targetLoc)
local real y = GetLocationY(targetLoc)
local integer level = GetUnitAbilityLevel(caster, AID_SPELL)
local player cPlayer = GetOwningPlayer(caster)
local group g = GetUnitsOfPlayerAndTypeId(cPlayer,SPAWN_ONE)
local unit u
loop
set u = FirstOfGroup(g)
exitwhen u == null
if (GetUnitState(u,UNIT_STATE_LIFE) != 0.)then
call KillUnit(u)
call DestroyEffect(AddSpecialEffectTarget(FX,u,"origin"))
endif
endloop
set g = GetUnitsOfPlayerAndTypeId(cPlayer,SPAWN_TWO)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if (GetUnitState(u,UNIT_STATE_LIFE) != 0.)then
call KillUnit(u)
call DestroyEffect(AddSpecialEffectTarget(FX,u,"origin"))
endif
endloop
if (level == 1)then
set u = CreateUnit(cPlayer,SPAWN_ONE,x,y,0.)
elseif (level == 2)then
set u = CreateUnit(cPlayer,SPAWN_TWO,x,y,0.)
call LavaLord_Register(u) // initilizes the spells it can periodicly cast
else
call BJDebugMsg("ERROR: Unexpected LavaSpawn Level")
endif
call DestroyEffect(AddSpecialEffectTarget(FX,u,"origin"))
call RemoveLocation (targetLoc)
set u = null
set cPlayer = null
set targetLoc = null
set caster = null
set g = null
endfunction
//===========================================================================
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == AID_SPELL
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition( trig, Condition( function Conditions ) )
call TriggerAddAction( trig, function Actions )
endfunction
endlibrary