- Joined
- Jul 15, 2009
- Messages
- 40
Hey there, all.
I am trying to learn JASS, and so I'm working on a spell to get some practice. However, I am having trouble figuring out exactly what I need to do to complete it.
The spell should work as follows:
Here is the code:
(Please note that I left out the references for the Handle Vars functions.)
The easy thing to do was have the attacker become frozen and then unfreeze. The hard part is making it so that both the attacker and the subsequent units freeze and then unfreeze after the appropriate amount of time.
The problem I am having right now is that some of the units do not unfreeze. I believe this problem is due to the fact that the data I'm storing (the special effect and the unit) are not always unique.
As I said, this will be my first JASS spell, so be gentle.
I am trying to learn JASS, and so I'm working on a spell to get some practice. However, I am having trouble figuring out exactly what I need to do to complete it.
The spell should work as follows:
Flash-Freeze
Whenever the caster is attacked, there is a chance that the attacking unit will be frozen instantly for several seconds. If the attacking unit is frozen, there will be a chance that any enemy units next to it will also become frozen, possibly triggering other units next to them to become frozen. This process continues until a unit does not freeze.
Level 1: 10% chance to freeze attacker for 3 seconds; 5% chance to freeze subsequent units for 3 seconds.
Level 2: 15% chance to freeze attacker for 5 seconds; 10% chance to freeze subsequent units for 5 seconds.
Level 3: 20% chance to freeze attacker for 7 seconds; 15% chance to freeze subsequent units for 7 seconds.
Here is the code:
JASS:
function Flash_Freeze_Condition takes nothing returns boolean
return (GetUnitTypeId(GetTriggerUnit()) == 'H000') and (GetUnitAbilityLevel(GetTriggerUnit(),'A000')) > 0
endfunction
function UnfreezeAttacker takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit frozen_unit = GetHandleUnit(t,"frozen_unit")
local effect sfx = GetHandleEffect(t,"sfx")
call UnitRemoveAbility(frozen_unit, 'A001')
call DestroyEffect(sfx)
call PauseUnit(frozen_unit, false)
call SetUnitTimeScalePercent(frozen_unit,100)
call DestroyTimer(t)
set frozen_unit = null
set sfx = null
set t = null
endfunction
function UnfreezeSub takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit frozen_unit = GetHandleUnit(t,"frozen_unit2")
local effect sfx = GetHandleEffect(t,"sfx2")
call UnitRemoveAbility(frozen_unit, 'A001')
call DestroyEffect(sfx)
call PauseUnit(frozen_unit, false)
call SetUnitTimeScalePercent(frozen_unit,100)
call DestroyTimer(t)
set frozen_unit = null
set sfx = null
set t = null
endfunction
function FilterUnit takes unit source, unit temp returns boolean
if (IsUnitAlly(temp, GetOwningPlayer(source))) and (GetUnitAbilityLevel(temp, 'A001') == 0) and not (IsUnitType(temp,UNIT_TYPE_STRUCTURE)) then
return true
else
return false
endif
endfunction
function FreezeAdjacent takes unit source returns nothing
local location source_loc = GetUnitLoc(source)
local group enemies = CreateGroup()
local unit temp
local effect sfx
local timer t = CreateTimer()
call GroupEnumUnitsInRangeOfLoc(enemies, source_loc, 100.0, null)
loop
set temp = FirstOfGroup(enemies)
exitwhen temp == null
if (FilterUnit(source,temp) == true) then
if GetRandomInt(1,100) <= 5 * (GetUnitAbilityLevel(GetTriggerUnit(),'A000') then
set sfx = AddSpecialEffectTarget("Abilities\\Spells\\Undead\\FreezingBreath\\FreezingBreathTargetArt.mdl",temp,"origin")
call UnitAddAbility(temp, 'A001')
call PauseUnit(temp, true)
call SetUnitTimeScalePercent(temp, 0)
call SetHandleHandle(t,"frozen_unit2",temp)
call SetHandleHandle(t,"sfx2",sfx)
call TimerStart(t,(1. + 2 * (GetUnitAbilityLevel(GetTriggerUnit(), 'A000'))), false, function UnfreezeSub)
call FreezeAdjacent(temp)
endif
endif
call GroupRemoveUnit(enemies, temp)
endloop
call RemoveLocation(source_loc)
call DestroyGroup(enemies)
set temp = null
set source_loc = null
set enemies = null
endfunction
function Flash_Freeze_Actions takes nothing returns nothing
local unit attacker = GetAttacker()
local effect sfx
local timer t = CreateTimer()
if GetRandomInt(1,100) <= (10 + 5*(GetUnitAbilityLevel(GetTriggerUnit(),'A000') - 1)) then
set sfx = AddSpecialEffectTarget("Abilities\\Spells\\Undead\\FreezingBreath\\FreezingBreathTargetArt.mdl",attacker,"origin")
call UnitAddAbility(attacker, 'A001')
call PauseUnit(attacker, true)
call SetUnitTimeScalePercent(attacker,0)
call SetHandleHandle(t,"frozen_unit",attacker)
call SetHandleHandle(t,"sfx",sfx)
call TimerStart(t,(1. + 2 * (GetUnitAbilityLevel(GetTriggerUnit(),'A000'))), false, function UnfreezeAttacker)
call FreezeAdjacent(attacker)
endif
set attacker = null
endfunction
function InitTrig_Flash_Freeze takes nothing returns nothing
set gg_trg_Flash_Freeze = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Flash_Freeze, EVENT_PLAYER_UNIT_ATTACKED)
call TriggerAddCondition(gg_trg_Flash_Freeze, Condition(function Flash_Freeze_Condition))
call TriggerAddAction(gg_trg_Flash_Freeze, function Flash_Freeze_Actions)
endfunction
The easy thing to do was have the attacker become frozen and then unfreeze. The hard part is making it so that both the attacker and the subsequent units freeze and then unfreeze after the appropriate amount of time.
The problem I am having right now is that some of the units do not unfreeze. I believe this problem is due to the fact that the data I'm storing (the special effect and the unit) are not always unique.
Help I Need
_______________________________________________________
_______________________________________________________
- First, I'd like to fix the problem with the units not unfreezing. Should I use a queue structure to keep track of units that are frozen? Are there other methods of doing this?
- I'd like to make this spell MUI, but I'm not sure what would need changing. The majority of the spell is instant, and only the timers controlling unfreezing will linger. If I correctly create a structure to make the units unfreeze properly, would that, essentially, render the spell MUI?
- Are there any leaks that I'm failing to catch?
- Any other constructive criticism on the spell's functionality?
As I said, this will be my first JASS spell, so be gentle.
Last edited: