library CustomErrorMessage initializer Init
globals
private framehandle array Message_Frame
private timer array Message_Timer
private hashtable Message_Table = InitHashtable()
endglobals
// REQUIRES THESE GUI VARIABLES:
// CEM__Text = String
// CEM__Duration = Real
// CEM__Scale = Real
// CEM__Position_X = Real
// CEM__Position_Y = Real
// CEM__Max_Width = Real
// CEM__Max_Height = Real
// CEM__Player = Player
private function UpdateMessageForPlayer takes integer id returns nothing
call BlzFrameSetScale(Message_Frame[id], udg_CEM__Scale)
call BlzFrameSetAbsPoint(Message_Frame[id], FRAMEPOINT_CENTER, udg_CEM__Position_X, udg_CEM__Position_Y - (-0.04 + (udg_CEM__Scale * 0.04)))
call BlzFrameSetSize(Message_Frame[id], udg_CEM__Max_Width, udg_CEM__Max_Height)
call BlzFrameSetText(Message_Frame[id], udg_CEM__Text)
endfunction
private function RemoveMessageOnExpire takes nothing returns nothing
local integer id = LoadInteger(Message_Table, GetHandleId(GetExpiredTimer()), 0)
call BlzFrameSetText(Message_Frame[id], "")
endfunction
private function SendMessageToAllPlayers takes nothing returns nothing
local player p = GetEnumPlayer()
local integer id = GetPlayerId(p)
if Message_Frame[id] == null then
set p = null
return
endif
call UpdateMessageForPlayer(id)
call TimerStart(Message_Timer[id], udg_CEM__Duration, false, function RemoveMessageOnExpire)
call SaveInteger(Message_Table, GetHandleId(Message_Timer[id]), 0, GetPlayerId(p))
set p = null
endfunction
private function SendMessageToOnePlayer takes nothing returns nothing
local integer id = GetPlayerId(udg_CEM__Player)
if Message_Frame[id] == null then
return
endif
call UpdateMessageForPlayer(id)
call TimerStart(Message_Timer[id], udg_CEM__Duration, false, function RemoveMessageOnExpire)
call SaveInteger(Message_Table, GetHandleId(Message_Timer[id]), 0, id)
endfunction
private function CreateTextFrames takes nothing returns nothing
local integer id = 0
loop
exitwhen id > 23
set Message_Frame[id] = BlzCreateFrameByType("TEXT", "MyTextFrame", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetScale(Message_Frame[id], 1)
call BlzFrameSetAbsPoint(Message_Frame[id], FRAMEPOINT_CENTER, 0.4, 0.3)
call BlzFrameSetSize(Message_Frame[id], 0.3, 0.1)
call BlzFrameSetTextAlignment(Message_Frame[id], TEXT_JUSTIFY_TOP, TEXT_JUSTIFY_CENTER)
call BlzFrameSetText(Message_Frame[id], "")
call BlzFrameSetEnable(Message_Frame[id], false)
call BlzFrameSetVisible(Message_Frame[id], false)
set Message_Timer[id] = CreateTimer()
if GetLocalPlayer() == Player(id) then
call BlzFrameSetVisible(Message_Frame[id], true)
endif
set id = id + 1
endloop
call DestroyTimer(GetExpiredTimer())
endfunction
private function Init takes nothing returns nothing
call TimerStart(CreateTimer(), 0.01, false, function CreateTextFrames)
endfunction
function CEM__SendMessage takes nothing returns nothing
if udg_CEM__Player != Player(27) then
call SendMessageToOnePlayer()
else
call ForForce(bj_FORCE_ALL_PLAYERS, function SendMessageToAllPlayers)
endif
set udg_CEM__Player = Player(27)
endfunction
endlibrary