- Joined
- Mar 21, 2011
- Messages
- 1,611
Hi,
if i create a trigger with locals on the top of the function and with a EVENT_PLAYER_UNIT_DEATH event for example, how would i initialize the locals?
OR
wouldnt the second solution be better? because i only need to set it up if it is a certain unit type.
if i create a trigger with locals on the top of the function and with a EVENT_PLAYER_UNIT_DEATH event for example, how would i initialize the locals?
JASS:
local unit u = GetTriggerUnit()
local real x = GetUnitX(u)
...
if IsUnitType(....)
endif
set u = null
return false
OR
JASS:
local unit u
local real x
...
if IsUnitType(....)
set u = GetTriggerUnit()
set x = GetUnitX(u)
...
endif
set u = null
return false
wouldnt the second solution be better? because i only need to set it up if it is a certain unit type.
JASS:
function Trig_Bear_Trap_Conditions takes nothing returns boolean
local unit u = GetTriggerUnit()
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local player p = GetTriggerPlayer()
local unit d
local item it
local group g = CreateGroup()
local unit l
if GetUnitTypeId(u) == 'n00A'then
set d = CreateUnit(p, 'h00Q', x, y, 0.00)
set it = CreateItem('I007', x, y)
call UnitAddItem(d, it)
call UnitUseItem(d, it)
call UnitApplyTimedLife(d, 'BTLF', 1.00)
call GroupEnumUnitsInRange(g, x, y, 140.00, null)
loop
set l = FirstOfGroup(g)
exitwhen l == null
if (GetUnitState(l, UNIT_STATE_LIFE) > 0) and (IsUnitEnemy(l, p)) and (IsUnitType(l, UNIT_TYPE_UNDEAD) == false) then
call IssueTargetOrder(d, "purge", l)
call IssueTargetOrder(d, "faeriefire", l)
call UnitDamageTarget(u, l, 100.00, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
endif
call GroupRemoveUnit(g, l)
endloop
endif
call DestroyGroup(g)
set u = null
set p = null
set d = null
set it = null
set g = null
set l = null
return false
endfunction
//===========================================================================
function InitTrig_Bear_Trap takes nothing returns nothing
local integer index
set index = 0
set gg_trg_Bear_Trap = CreateTrigger( )
loop
call TriggerRegisterPlayerUnitEvent(gg_trg_Bear_Trap, Player(index), EVENT_PLAYER_UNIT_DEATH, null)
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition( gg_trg_Bear_Trap, Condition( function Trig_Bear_Trap_Conditions ) )
endfunction