- Joined
- May 12, 2017
- Messages
- 28
Hello, I was wondering if anyone could give me some insight in how I can make this system better. Right now it feels very wasteful and inefficient as every Player has a unique respawn timer and dialog attached to them. Which means that I have 12 "Timer Expired" events hooked up in the background to revive every player's hero when their respective timer runs out :/
Note: My code makes use of PlayerUtils
My code for the primary scope is as follows
Code for X Timer Expired is as follows
Note: My code makes use of PlayerUtils
My code for the primary scope is as follows
JASS:
scope HeroRevive initializer onInit
globals
timer array HeroReviveTimer
timerdialog array HeroReviveTimerDialog
endglobals
private function Conditions takes nothing returns boolean
return GetTriggerUnit() == PlayerHero[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))]
endfunction
private function Actions takes nothing returns nothing
local real respawnTime = 5.00
local User p = User(GetPlayerId(GetOwningPlayer(GetTriggerUnit())))
call StartTimerBJ(HeroReviveTimer[p.id], false, respawnTime)
call CreateTimerDialogBJ(HeroReviveTimer[p.id], PlayerColor[p.id] + p.name + "|r")
set HeroReviveTimerDialog[p.id] = bj_lastCreatedTimerDialog
call DisplayTimedTextToPlayer(GetOwningPlayer(GetTriggerUnit()), 0.0, 0.0, 2.0, "Your hero will be respawned in |c00DFFB4F" + I2S(R2I(respawnTime)) + "|r seconds.")
call NormalToAlpha(GetTriggerUnit(), 0.15)
endfunction
private function onInit takes nothing returns nothing
local trigger t = CreateTrigger()
local User p = User.first
loop
exitwhen p == User.NULL
call TriggerRegisterPlayerUnitEvent(t, p.toPlayer(), EVENT_PLAYER_UNIT_DEATH, null)
set p = p.next
endloop
call TriggerAddCondition(t, Condition(function Conditions))
call TriggerAddAction(t, function Actions)
endfunction
endscope
Code for X Timer Expired is as follows
JASS:
scope TimerHeroRevive1 initializer onInit
private function Actions takes nothing returns nothing
local location loc = null
local User p = User(GetPlayerId(0))
call PauseTimer(GetExpiredTimer())
call DestroyTimerDialog(HeroReviveTimer[p.id])
set loc = GetStartLocationLoc(GetPlayerStartLocation(p.toPlayer()))
call ReviveHeroLoc(PlayerHero[p.id], loc, true)
if (User.fromLocal().id == p.id) then
call ClearSelection()
call SelectUnit(PlayerHero[p.id], true)
call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), 0.50)
endif
call RemoveLocation(loc)
call AlphaToNormal(PlayerHero[p.id], 0.07)
set loc = null
endfunction
private function onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterTimerExpireEvent(t, HeroReviveTimer[0])
call TriggerAddAction(t, function Actions)
endfunction
endscope