library Vehicle initializer Event uses SpellEffectEvent
globals
private integer spawnInterval
private unit array driver
endglobals
private function Timed takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetTimerData(t)
if UnitAlive(udg_UDexUnits[id]) then
call SetUnitInvulnerable(udg_UDexUnits[id], true)
endif
call ReleaseTimer(t)
set t = null
endfunction
private function OnUnload takes nothing returns boolean
call SetUnitOwner(udg_CargoTransportUnit[udg_UDex], Player(PLAYER_NEUTRAL_PASSIVE), true)
call SetUnitMoveSpeed(udg_CargoTransportUnit[udg_UDex], 0)
call UnitAddAbility(udg_CargoTransportUnit[udg_UDex], ABILITY_DETECTION)
call TimerStart(NewTimerEx(GetUnitUserData(udg_CargoTransportUnit[udg_UDex])), 0, false, function Timed)
if (GetLocalPlayer() == GetOwningPlayer(udg_UDexUnits[udg_UDex])) then
call ClearSelection()
call SelectUnit(udg_UDexUnits[udg_UDex], true)
endif
set driver[GetUnitUserData(udg_CargoTransportUnit[udg_UDex])] = null
return false
endfunction
private function OnLoad takes nothing returns boolean
local player p = GetOwningPlayer(udg_UDexUnits[udg_UDex])
call PauseUnit(udg_CargoTransportUnit[udg_UDex], true)
call SetUnitOwner(udg_CargoTransportUnit[udg_UDex], p, true)
call PauseUnit(udg_CargoTransportUnit[udg_UDex], false)
call SetUnitMoveSpeed(udg_CargoTransportUnit[udg_UDex], 290)
call UnitRemoveAbility(udg_CargoTransportUnit[udg_UDex], ABILITY_DETECTION)
call SetUnitInvulnerable(udg_CargoTransportUnit[udg_UDex], false)
if (GetLocalPlayer() == p) then
call ClearSelection()
call SelectUnit(udg_CargoTransportUnit[udg_UDex], true)
endif
set driver[GetUnitUserData(udg_CargoTransportUnit[udg_UDex])] = udg_UDexUnits[udg_UDex]
return false
endfunction
private function OnDestroy takes nothing returns boolean
if IsUnitType(udg_DamageEventTarget, UNIT_TYPE_MECHANICAL) and udg_DamageEventAmount >= GetUnitState(udg_DamageEventTarget, UNIT_STATE_LIFE) then
call UnitDamageTarget(udg_DamageEventSource, driver[GetUnitUserData(udg_DamageEventTarget)], 1000.00, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
endif
return false
endfunction
private function OnDeath takes nothing returns boolean
local unit u = GetTriggerUnit()
local unit vehicle
if GetUnitTypeId(u) == 'h00V' then
set vehicle = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), vehicleType[GetRandomInt(0, 2)], GetUnitX(u), GetUnitY(u), 0)
call SetUnitMoveSpeed(vehicle, 0)
call UnitAddAbility(vehicle, ABILITY_DETECTION)
call SetUnitInvulnerable(vehicle, true)
set vehicle = null
endif
set u = null
return false
endfunction
private function SpawnVehicles takes nothing returns nothing
local unit u
local real x
local real y
local integer rnd
if isEvent == false then
set spawnInterval = spawnInterval - 1
if spawnInterval == 0 then
set rnd = GetRandomInt(0, 7)
set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'h00V', GetRandomX(rnd), GetRandomY(rnd), 0.00)
call SetUnitAnimation(u, "birth")
call UnitApplyTimedLife(u, 'BTLF', 5.00)
set spawnInterval = SETTINGS_VEHICLE_INTERVAL
set u = null
endif
endif
endfunction
function RunVehicleEvent takes nothing returns nothing
call TimerStart(NewTimer(), 1.00, true, function SpawnVehicles)
set spawnInterval = SETTINGS_VEHICLE_INTERVAL
endfunction
private function Event takes nothing returns nothing
local trigger load = CreateTrigger()
local trigger unload = CreateTrigger()
local trigger ondestroy = CreateTrigger()
call TriggerRegisterVariableEvent(load, "udg_CargoEvent", EQUAL, 1.00)
call TriggerAddCondition(load, Condition(function OnLoad))
call TriggerRegisterVariableEvent(unload, "udg_CargoEvent", EQUAL, 2.00)
call TriggerAddCondition(unload, Condition(function OnUnload))
call TriggerRegisterVariableEvent(ondestroy, "udg_DamageEvent", EQUAL, 1.00)
call TriggerAddCondition(ondestroy, Condition(function OnDestroy))
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function OnDeath)
set load = null
set unload = null
set ondestroy = null
endfunction
endlibrary