struct DyingHeroWindowTimer
private unit u = null
private player owner = null
private timerdialog timdia
private static method invulnOff takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
call SetUnitInvulnerable(.u, false)
call ReleaseTimer(GetExpiredTimer())
call .destroy()
endmethod
private static method onExpire takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
local integer i = GetRandomInt(1, 5)
local integer index = 0
local item indexItem = null
local unit Bat = null
local real X = 0.00
local real Y = 0.00
local string fxpath = "" //I would recommend using clear variable names ;)
if IsUnitInForce(.u, BloodPack) then
if Teams == 2 or Teams == 3 then
set i = GetRandomInt(1,3)
else
set i = GetRandomInt(1,5)
endif
set X = HavenX[i]
set Y = HavenY[i]
elseif IsUnitInForce(.u, FangSquad) then
if Teams == 2 or Teams == 3 then
set i = GetRandomInt(9,11)
else
set i = GetRandomInt(9,13)
endif
set X = HavenX[i]
set Y = HavenY[i]
elseif IsUnitInForce(.u, HellHorde) then
set i = GetRandomInt(6,8)
set X = HavenX[i]
set Y = HavenY[i]
elseif IsUnitInForce(.u, CrimsonHunters) then
set i = GetRandomInt(12,14)
set X = HavenX[i]
set Y = HavenY[i]
elseif IsUnitInForce(.u, VileLegion) then
set i = GetRandomInt(15,17)
set X = HavenX[i]
set Y = HavenY[i]
elseif IsUnitInForce(.u, ChosenVampire) then
set X = 15879.
set Y = 9892.
else
set X = 2576
set Y = -200
endif
call GroupRemoveUnit(udg_BurnGroup, .u)
call GroupRemoveUnit(udg_RoamingGroup, .u)
call DestroyEffect(FireFX[GetUnitId(.u)])
if lives[GetPlayerId(.owner)] <= 0 then
if LANGUAGE[GetPlayerId(.owner)] == "francais" then
call DisplayTextToPlayer(.owner, 0, 0, "Votre dernière vie a été gaspillée et votre âme de vampire condamnée à l'enfer pour l'éternité. Néanmoins, vous pouvez rester et regarder la partie se dérouler.")
else
call DisplayTextToPlayer(.owner, 0, 0, "Your last life has been wasted, and your vampire soul damned with little hope of salvation. However, feel free to stay and watch the game.")
endif
loop //Check for Item in Inventory
set indexItem = UnitItemInSlot(.u, index)
if indexItem != null and GetItemType(indexItem) == ITEM_TYPE_CAMPAIGN then
call SetItemPosition(indexItem, GetUnitX(.u), GetUnitY(.u))
endif
set index = index + 1
exitwhen index > bj_MAX_INVENTORY
endloop
call GroupAddUnit(Dead, .u)
set Bat = CreateUnit(.owner, 'nshf', GetUnitX(.u), GetUnitY(.u), 270)
call SetUnitInvulnerable(Bat, true)
set i = 0 //no need for another variable for a loop, thus i isn't required anymore
loop
exitwhen i == 13
if Player(i) != .owner then
call SetPlayerAlliance(.owner, Player(i), ALLIANCE_SHARED_VISION, false)
endif
set i = i + 1
endloop
elseif ReviveHero(.u, X, Y, false) then
if GetUnitTypeId(.u) == 'GBaF' or GetUnitTypeId(.u) == 'OC91' then
if GetUnitAbilityLevel(.u, 'fbfl') > 0 then
call UnitAddAbility(.u, 'Hunt')
call SetUnitAbilityLevel(.u, 'Hunt', GetUnitAbilityLevel(.u, 'fbfl'))
endif
if GetUnitAbilityLevel(.u, 'frdr') > 0 then
call UnitAddAbility(.u, 'rend')
call SetUnitAbilityLevel(.u, 'rend', GetUnitAbilityLevel(.u, 'frdr'))
endif
endif
if (GetLocalPlayer() == .owner) then
call TimerDialogDisplay(.timdia, false)
call PanCameraTo(X, Y)
set fxpath = "Abilities\\Spells\\Other\\Incinerate\\FireLordDeathExplode.mdl"
call ClearSelection()
call SelectUnit(.u, true)
else
set fxpath = "Abilities\\Spells\\Human\\ReviveHuman\\ReviveHuman.mdl"
endif
call DestroyEffect(AddSpecialEffectTarget(fxpath, .u, "origin"))
else
call BJDebugMsg("This hero failed to revive for unknown reasons.")
endif
//cleanup struct data
call ReleaseTimer(GetExpiredTimer())
call DestroyTimerDialog(.timdia)
call SetUnitInvulnerable(.u, true)
call TimerStart(NewTimerEx(this), 10, false, function thistype.invulnOff)
set Bat = null
endmethod
private static method create takes unit died returns thistype
local thistype this = thistype.allocate()
local real dur = 5 + 0.2 * GetHeroLevel(died)
local timer tim = NewTimerEx(this)
set .u = died //Store the unit in the struct
set .owner = GetOwningPlayer(.u) //Just store the owner within the struct
set .timdia = CreateTimerDialog(tim)
call GroupRemoveUnit(udg_RoamingGroup, .u)
call GroupRemoveUnit(udg_BurnGroup, .u)
call DestroyEffect(FireFX[GetUnitId(.u)])
call TimerDialogSetTitleColor(.timdia, GetPlayerTagColor(.owner, "red"), GetPlayerTagColor(.owner, "green"), GetPlayerTagColor(.owner, "blue"), 255)
call TimerDialogSetTimeColor(.timdia, 255, 255, 255, 255)
call TimerDialogSetTitle(.timdia, "Respawn")
set lives[GetPlayerId(.owner)] = lives[GetPlayerId(.owner)] - 1
if IsUnitInForce(.u, BloodPack) then
call DisplayTextToPlayer(GetLocalPlayer(), 0.00, 0.00, GetPlayerName(.owner) + " of the Blood Pack has perished. It has " + I2S(lives[GetPlayerId(owner)]) + " lives left." )
elseif IsUnitInForce(.u, FangSquad) then
call DisplayTextToPlayer(GetLocalPlayer(), 0.00, 0.00, GetPlayerName(.owner) + " of the Fang Squad has perished. It has " + I2S(lives[GetPlayerId(owner)]) + " lives left." )
elseif IsUnitInForce(.u, HellHorde) then
call DisplayTextToPlayer(GetLocalPlayer(), 0.00, 0.00, GetPlayerName(.owner) + " of the Hell Horde has perished. It has " + I2S(lives[GetPlayerId(owner)]) + " lives left." )
elseif IsUnitInForce(.u, CrimsonHunters) then
call DisplayTextToPlayer(GetLocalPlayer(), 0.00, 0.00, GetPlayerName(.owner) + " of the Crimson Hunters has perished. It has " + I2S(lives[GetPlayerId(owner)]) + " lives left." )
elseif IsUnitInForce(.u, VileLegion) then
call DisplayTextToPlayer(GetLocalPlayer(), 0.00, 0.00, GetPlayerName(.owner) + " of the Vile Legion has perished. It has " + I2S(lives[GetPlayerId(owner)]) + " lives left." )
else
call DisplayTextToPlayer(GetLocalPlayer(), 0.00, 0.00, GetPlayerName(.owner) + " of the rogue Vampires has perished. It has " + I2S(lives[GetPlayerId(owner)]) + " lives left." )
endif
if GetLocalPlayer() == .owner then
call TimerDialogDisplay(.timdia, true)
endif
call TimerStart(tim, dur, false, function thistype.onExpire) //The timer callback function
return this
endmethod
private static method Actions takes nothing returns nothing
local unit d = GetDyingUnit()
local player p = GetOwningPlayer(d)
if(IsUnitType(d, UNIT_TYPE_HERO) and IsUnitType(d, UNIT_TYPE_UNDEAD))and(GetPlayerController(p) == MAP_CONTROL_USER and GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING) and d != Tynan then
debug call BJDebugMsg(GetUnitName(d) + " is a valid, dying unit.")
if Mode == "Haven Control" then
if LANGUAGE[GetPlayerId(p)] == "francais" then
call DisplayTextToPlayer(p, 0, 0, "Vous êtes mort. Vous devez attendre jusqu'à la tombée de la nuit avant de ressusciter.")
call DisplayTextToPlayer(p, 0, 0, "|cffff0000Tous les refuges sous votre contrôle vous ont été retirés.|r")
else
call DisplayTextToPlayer(p, 0, 0, "You have died. You must wait until nightfall before you revive.")
call DisplayTextToPlayer(p, 0, 0, "|cffff0000All your Havens have been released from your control.|r")
endif
call GroupAddUnit(REVIVE_GROUP, d)
set TEMP = d
call GroupEnumUnitsInRect(ENUM_GROUP, bj_mapInitialPlayableArea, function ReleaseHavensFromPlayer)
else
debug call BJDebugMsg("No haven control.")
call thistype.create(d)
endif
endif
set d = null
set p = null
endmethod
//===========================================================================
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddAction(t, function thistype.Actions )
set HavenX[1] = -11072.//Top Left
set HavenY[1] = 9200.
set HavenX[2] = -4400.//By North Queen
set HavenY[2] = 10400.
set HavenX[3] = -11114.//By the Western Waters
set HavenY[3] = -975.
set HavenX[4] = -5350.//Cliff near Graham
set HavenY[4] = 2200.
set HavenX[5] = -7950.//Forest Village
set HavenY[5] = -1150.
set HavenX[6] = 3958.//Beach
set HavenY[6] = 8763.
set HavenX[7] = 4822.//Eastern Wall North
set HavenY[7] = 1844.
set HavenX[8] = 10090.//QOTD
set HavenY[8] = 10720.
set HavenX[9] = 8652.//Eastern Park
set HavenY[9] = -8843.
set HavenX[10] = 6191.//Near Salamar
set HavenY[10] = -7309.
set HavenX[11] = 0.//Southern Waters
set HavenY[11] = -11400.
set HavenX[12] = -11111.//South West Cliffs
set HavenY[12] = -10000.
set HavenX[13] = -3756.//Southern Trees
set HavenY[13] = -11566.
set HavenX[14] = -2736.//Under Palace
set HavenY[14] = -7340.
set HavenX[15] = -5830.//Near Galant
set HavenY[15] = 5450.
set HavenX[16] = 2514.//East of Palace
set HavenY[16] = -6501.
set HavenX[17] = -4471.//Graveyard
set HavenY[17] = -3195.
endmethod
endstruct