- Joined
- Oct 26, 2007
- Messages
- 15
Hey everyone, I'm just starting to use JASS instead of GUI and I would ask a favour. I figure the best way to learn is from the experts, and so I was wondering if you guys could tell me how I could make this code more efficient:
(Basically it's for a spell that is like Force of Nature, but for corpses instead of trees)
One thing I can think of but don't know how to do is when I set the unit group 'corpses' to all units in an area, then check if they are dead, I figure that last field 'boolexpr' or something in GroupEnumUnitsInRangeOfLoc() could be used to only add dead units to the group. Like I said though, I don't know how to do that.
(Basically it's for a spell that is like Force of Nature, but for corpses instead of trees)
JASS:
function RaiseMinionsYesNo takes nothing returns boolean
return GetSpellAbilityId() == 'A00P'
endfunction
function RaiseMinionsDo takes nothing returns nothing
local unit caster = GetSpellAbilityUnit()
local location target_pos = GetSpellTargetLoc()
local group corpses = CreateGroup()
local unit temp
local integer count = GetUnitAbilityLevel(caster, 'A00P')
local location temp_loc
local effect raiseEffect
local unit minion
call GroupEnumUnitsInRangeOfLoc(corpses, target_pos, 100+50*count, null)
loop
set temp = FirstOfGroup(corpses)
exitwhen temp == null or count == -1
if GetUnitState(temp, UNIT_STATE_LIFE) <= 0 then
set temp_loc = GetUnitLoc(temp)
call RemoveUnit(temp)
set raiseEffect = AddSpecialEffectLoc("Objects\\Spawnmodels\\Human\\HumanLargeDeathExplode\\HumanLargeDeathExplode.mdl", temp_loc)
set minion = CreateUnitAtLoc(GetOwningPlayer(caster), 'n001', temp_loc, GetRandomInt(0, 360))
call SetUnitAnimation(minion, "birth")
call UnitApplyTimedLife(minion, 'B002', 60.)
set count = count - 1
endif
call GroupRemoveUnit(corpses, temp)
call DestroyEffect(raiseEffect)
set raiseEffect = null
endloop
call DestroyGroup(corpses)
call RemoveLocation(target_pos)
call RemoveLocation(temp_loc)
set corpses = null
set target_pos = null
set temp_loc = null
set caster = null
set temp = null
set minion = null
endfunction
function RaiseMinionsCant takes nothing returns nothing
local unit caster = GetSpellAbilityUnit()
local location target_pos = GetSpellTargetLoc()
local group corpses = CreateGroup()
local group allUnits = CreateGroup()
local integer count = GetUnitAbilityLevel(caster, 'A00P')
local unit temp
call GroupEnumUnitsInRangeOfLoc(allUnits, target_pos, 100+50*count, null)
loop
set temp = FirstOfGroup(allUnits)
exitwhen temp == null
if GetUnitState(temp, UNIT_STATE_LIFE) <= 0 then
call GroupAddUnit(corpses, temp)
endif
call GroupRemoveUnit(allUnits, temp)
endloop
if IsUnitGroupEmptyBJ(corpses) then
call IssueImmediateOrder(caster, "stop")
call DisplayTextToPlayer(GetOwningPlayer(caster), 0., 0., "Must target at least one corpse")
endif
call DestroyGroup(corpses)
call DestroyGroup(allUnits)
call RemoveLocation(target_pos)
set corpses = null
set allUnits = null
set target_pos = null
set caster = null
set temp = null
endfunction
One thing I can think of but don't know how to do is when I set the unit group 'corpses' to all units in an area, then check if they are dead, I figure that last field 'boolexpr' or something in GroupEnumUnitsInRangeOfLoc() could be used to only add dead units to the group. Like I said though, I don't know how to do that.