Name | Type | is_array | initial_value |
library SimError initializer init
//**************************************************************************************************
//*
//* SimError
//*
//* Mimic an interface error message
//* call SimError(ForPlayer, msg)
//* ForPlayer : The player to show the error
//* msg : The error
//*
//* To implement this function, copy this trigger and paste it in your map.
//* Unless of course you are actually reading the library from wc3c's scripts section, then just
//* paste the contents into some custom text trigger in your map.
//*
//**************************************************************************************************
globals
private sound error
endglobals
function SimError takes player ForPlayer, string msg returns nothing
if (GetLocalPlayer() == ForPlayer) then
call ClearTextMessages()
endif
// Barade: This must be outside of GetLocalPlayer due to the hook for DisplayTimedTextToPlayer from Log.
call DisplayTimedTextToPlayer(ForPlayer, 0.52, 0.96, 2.00, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00" + msg + "|r")
if (GetLocalPlayer() == ForPlayer) then
call StartSound(error)
endif
endfunction
private function init takes nothing returns nothing
set error=CreateSoundFromLabel("InterfaceError",false,false,false,10,10)
//call StartSound( error ) //apparently the bug in which you play a sound for the first time
//and it doesn't work is not there anymore in patch 1.22
endfunction
endlibrary
library FrameLoader initializer init_function
// in 1.31 and upto 1.32.9 PTR (when I wrote this). Frames are not correctly saved and loaded, breaking the game.
// This library runs all functions added to it with a 0s delay after the game was loaded.
// function FrameLoaderAdd takes code func returns nothing
// func runs when the game is loaded.
globals
private trigger eventTrigger = CreateTrigger()
private trigger actionTrigger = CreateTrigger()
private timer t = CreateTimer()
endglobals
function FrameLoaderAdd takes code func returns nothing
call TriggerAddAction(actionTrigger, func)
endfunction
private function timerAction takes nothing returns nothing
call TriggerExecute(actionTrigger)
endfunction
private function eventAction takes nothing returns nothing
call TimerStart(t, 0, false, function timerAction)
endfunction
private function init_function takes nothing returns nothing
call TriggerRegisterGameEvent(eventTrigger, EVENT_GAME_LOADED)
call TriggerAddAction(eventTrigger, function eventAction)
endfunction
endlibrary
library StringUtils
function StringReplace takes string source, string match, string replace returns string
local integer i = 0
local integer max = StringLength(source)
local integer matchLength = StringLength(match)
local integer index = 0
local string result = ""
loop
exitwhen (i == max)
set index = i + matchLength
if (SubString(source, i, index) == match) then
set result = result + replace
set i = index
else
set index = i + 1
set result = result + SubString(source, i, index)
set i = index
endif
endloop
return result
endfunction
function StringRemove takes string source, string match returns string
return StringReplace(source, match, "")
endfunction
function StringStartsWith takes string source, string start returns boolean
local integer i = 0
loop
exitwhen (i == StringLength(start) or i >= StringLength(source))
if (SubString(source, i, i + 1) != SubString(start, i, i + 1)) then
return false
endif
set i = i + 1
endloop
return i == StringLength(start)
endfunction
function StringRemoveFromStart takes string source, string start returns string
if (StringStartsWith(source, start)) then
return SubString(source, StringLength(start), StringLength(source))
endif
return source
endfunction
function IndexOfStringEx takes string symbol, string source, integer start returns integer
local integer symbolLength = StringLength(symbol)
local integer length = StringLength(source)
local integer i2 = 0
local integer i = start
//call BJDebugMsg("Checking for symbol: " + symbol + " in source " + source)
loop
set i2 = i + symbolLength
exitwhen (i >= length or i2 > length)
if (SubString(source, i, i2) == symbol) then
//call BJDebugMsg("Index: " + I2S(i))
return i
endif
set i = i + 1
endloop
//call BJDebugMsg("Missing symbol " + symbol + " in source " + source)
return -1
endfunction
function IndexOfString takes string symbol, string source returns integer
return IndexOfStringEx(symbol, source, 0)
endfunction
function StringIndexOf takes string symbol, string source returns integer
return IndexOfString(symbol, source)
endfunction
function StringCount takes string source, string symbol returns integer
local integer result = 0
local integer symbolLength = StringLength(symbol)
local integer length = StringLength(source)
local integer i = 0
//call BJDebugMsg("Checking for symbol: " + symbol + " in source " + source)
loop
exitwhen (i == length)
if (SubString(source, i, i + symbolLength) == symbol) then
//call BJDebugMsg("Index: " + I2S(i))
set result = result + 1
set i = i + symbolLength
else
set i = i + 1
endif
endloop
//call BJDebugMsg("Missing symbol " + symbol + " in source " + source)
return result
endfunction
function StringSplit takes string source, integer index, string separator returns string
local string result = ""
local integer currentIndex = 0
local integer separatorLength = StringLength(separator)
local integer length = StringLength(source)
local integer i = 0
loop
exitwhen (i == length or currentIndex > index)
if (SubString(source, i, i + separatorLength) == separator) then
set currentIndex = currentIndex + 1
set i = i + separatorLength
else
if (currentIndex == index) then
set result = result + SubString(source, i, i + 1)
endif
set i = i + 1
endif
endloop
return result
endfunction
/**
* Useful for getting parts of a chat message to implement chat commands.
* Note that his skips multiple separators next to each other like whitespaces and counts them as one.
*/
function StringTokenEx takes string source, integer index, string separator, boolean toTheEnd returns string
local string result = ""
local boolean inWhitespace = false
local integer currentIndex = 0
local integer separatorLength = StringLength(separator)
local integer length = StringLength(source)
local integer i = 0
loop
exitwhen (i == length or currentIndex > index)
if (SubString(source, i, i + separatorLength) == separator and (not toTheEnd or currentIndex < index)) then
if (not inWhitespace) then
set inWhitespace = true
set currentIndex = currentIndex + 1
set i = i + separatorLength
endif
else
if (currentIndex == index) then
set result = result + SubString(source, i, i + 1)
endif
set inWhitespace = false
set i = i + 1
endif
endloop
return result
endfunction
function StringToken takes string source, integer index returns string
return StringTokenEx(source, index, " ", false)
endfunction
function StringTokenEnteredChatMessageEx takes integer index, boolean toTheEnd returns string
return StringTokenEx(GetEventPlayerChatString(), index, " ", toTheEnd)
endfunction
function StringTokenEnteredChatMessage takes integer index returns string
return StringToken(GetEventPlayerChatString(), index)
endfunction
function RandomizeString takes string source returns string
local string result = ""
local integer sourcePosition = 0
loop
exitwhen (StringLength(source) == 0)
set sourcePosition = GetRandomInt(0, StringLength(source) - 1)
set result = result + SubString(source, sourcePosition, sourcePosition + 1)
set source = SubString(source, 0, sourcePosition) + SubString(source, sourcePosition + 1, StringLength(source))
endloop
return result
endfunction
function StringRandomize takes string source returns string
return RandomizeString(source)
endfunction
function I2SW takes integer i, integer width returns string
local integer a = 0
local string result = ""
local integer max = 0
if (width > 0) then
set a = IAbsBJ(i)
set max = R2I(Pow(R2I(10), R2I(width - 1)))
if (i < 0) then
set result = result + "-"
endif
loop
if (a >= max or max <= 1) then
set result = result + I2S(a)
exitwhen (true)
else
set result = result + "0"
set max = max / 10
endif
endloop
else
set result = I2S(i)
endif
return result
endfunction
function FormatTimeString takes integer seconds returns string
local integer minutes = seconds / 60
local integer hours = minutes / 60
local integer hoursInMinutes = hours * 60
local integer minutesInSeconds = minutes * 60
set minutes = minutes - hoursInMinutes
set seconds = seconds - minutesInSeconds
if (hours > 0) then
return I2SW(hours, 2) + ":" + I2SW(minutes, 2) + ":" + I2SW(seconds, 2)
elseif (minutes > 0) then
return I2SW(minutes, 2) + ":" + I2SW(seconds, 2)
else
return I2S(seconds) + " seconds"
endif
endfunction
function IsCharacterNumber takes string whichCharacter returns boolean
return whichCharacter == "0" or whichCharacter == "1" or whichCharacter == "2" or whichCharacter == "3" or whichCharacter == "4" or whichCharacter == "5" or whichCharacter == "6" or whichCharacter == "7" or whichCharacter == "8" or whichCharacter == "9"
endfunction
function IsStringNumber takes string whichString returns boolean
local integer length = StringLength(whichString)
local integer i = 0
loop
exitwhen (i == length)
if (not IsCharacterNumber(SubString(whichString, i, i + 1))) then
return false
endif
set i = i + 1
endloop
return true
endfunction
endlibrary
library PlayerColorUtils initializer Init requires StringUtils
function GetPlayerColorTexture takes playercolor c returns string
return "ReplaceableTextures\\TeamColor\\TeamColor" + I2SW(GetHandleId(c), 2)
endfunction
function GetPlayerColorRed takes playercolor c returns integer
if c == PLAYER_COLOR_RED then
return 0xFF
elseif c == PLAYER_COLOR_BLUE then
return 0x00
elseif c == PLAYER_COLOR_CYAN then
return 0x1B
elseif c == PLAYER_COLOR_PURPLE then
return 0x53
elseif c == PLAYER_COLOR_YELLOW then
return 0xFF
elseif c == PLAYER_COLOR_ORANGE then
return 0xFE
elseif c == PLAYER_COLOR_GREEN then
return 0x1F
elseif c == PLAYER_COLOR_PINK then
return 0xE4
elseif c == PLAYER_COLOR_LIGHT_GRAY then
return 0x94
elseif c == PLAYER_COLOR_LIGHT_BLUE then
return 0x7D
elseif c == PLAYER_COLOR_AQUA then
return 0x0F
elseif c == PLAYER_COLOR_BROWN then
return 0x4D
elseif c == PLAYER_COLOR_MAROON then
return 0x9B
elseif c == PLAYER_COLOR_NAVY then
return 0x00
elseif c == PLAYER_COLOR_TURQUOISE then
return 0x00
elseif c == PLAYER_COLOR_VIOLET then
return 0xBE
elseif c == PLAYER_COLOR_WHEAT then
return 0xEB
elseif c == PLAYER_COLOR_PEACH then
return 0xF8
elseif c == PLAYER_COLOR_MINT then
return 0xBF
elseif c == PLAYER_COLOR_LAVENDER then
return 0xDC
elseif c == PLAYER_COLOR_COAL then
return 0x28
elseif c == PLAYER_COLOR_SNOW then
return 0xEB
elseif c == PLAYER_COLOR_EMERALD then
return 0x00
elseif c == PLAYER_COLOR_PEANUT then
return 0xA4
else
return 0xFF
endif
return 0
endfunction
function GetPlayerColorGreen takes playercolor c returns integer
if c == PLAYER_COLOR_RED then
return 0x02
elseif c == PLAYER_COLOR_BLUE then
return 0x41
elseif c == PLAYER_COLOR_CYAN then
return 0xE5
elseif c == PLAYER_COLOR_PURPLE then
return 0x00
elseif c == PLAYER_COLOR_YELLOW then
return 0xFC
elseif c == PLAYER_COLOR_ORANGE then
return 0x89
elseif c == PLAYER_COLOR_GREEN then
return 0xBF
elseif c == PLAYER_COLOR_PINK then
return 0x5A
elseif c == PLAYER_COLOR_LIGHT_GRAY then
return 0x95
elseif c == PLAYER_COLOR_LIGHT_BLUE then
return 0xBE
elseif c == PLAYER_COLOR_AQUA then
return 0x61
elseif c == PLAYER_COLOR_BROWN then
return 0x29
elseif c == PLAYER_COLOR_MAROON then
return 0x00
elseif c == PLAYER_COLOR_NAVY then
return 0x00
elseif c == PLAYER_COLOR_TURQUOISE then
return 0xEA
elseif c == PLAYER_COLOR_VIOLET then
return 0x00
elseif c == PLAYER_COLOR_WHEAT then
return 0xCD
elseif c == PLAYER_COLOR_PEACH then
return 0xA4
elseif c == PLAYER_COLOR_MINT then
return 0xFF
elseif c == PLAYER_COLOR_LAVENDER then
return 0xB9
elseif c == PLAYER_COLOR_COAL then
return 0x28
elseif c == PLAYER_COLOR_SNOW then
return 0xF0
elseif c == PLAYER_COLOR_EMERALD then
return 0x78
elseif c == PLAYER_COLOR_PEANUT then
return 0x6F
else
return 0xFF
endif
endfunction
function GetPlayerColorBlue takes playercolor c returns integer
if c == PLAYER_COLOR_RED then
return 0x02
elseif c == PLAYER_COLOR_BLUE then
return 0xFF
elseif c == PLAYER_COLOR_CYAN then
return 0xB8
elseif c == PLAYER_COLOR_PURPLE then
return 0x80
elseif c == PLAYER_COLOR_YELLOW then
return 0x00
elseif c == PLAYER_COLOR_ORANGE then
return 0x0D
elseif c == PLAYER_COLOR_GREEN then
return 0x00
elseif c == PLAYER_COLOR_PINK then
return 0xAF
elseif c == PLAYER_COLOR_LIGHT_GRAY then
return 0x96
elseif c == PLAYER_COLOR_LIGHT_BLUE then
return 0xF1
elseif c == PLAYER_COLOR_AQUA then
return 0x45
elseif c == PLAYER_COLOR_BROWN then
return 0x03
elseif c == PLAYER_COLOR_MAROON then
return 0x00
elseif c == PLAYER_COLOR_NAVY then
return 0xC3
elseif c == PLAYER_COLOR_TURQUOISE then
return 0xFF
elseif c == PLAYER_COLOR_VIOLET then
return 0xFE
elseif c == PLAYER_COLOR_WHEAT then
return 0x87
elseif c == PLAYER_COLOR_PEACH then
return 0x8B
elseif c == PLAYER_COLOR_MINT then
return 0x80
elseif c == PLAYER_COLOR_LAVENDER then
return 0xEB
elseif c == PLAYER_COLOR_COAL then
return 0x28
elseif c == PLAYER_COLOR_SNOW then
return 0xFF
elseif c == PLAYER_COLOR_EMERALD then
return 0x1E
elseif c == PLAYER_COLOR_PEANUT then
return 0x33
else
return 0xFF
endif
endfunction
function GetPlayerColorString takes playercolor c, string text returns string
//Credits to Andrewgosu from TH for the color codes//
if c == PLAYER_COLOR_RED then
return "|cffFF0202" + text + "|r"
elseif c == PLAYER_COLOR_BLUE then
return "|cff0041FF" + text + "|r"
elseif c == PLAYER_COLOR_CYAN then
return "|cff1BE5B8" + text + "|r"
elseif c == PLAYER_COLOR_PURPLE then
return "|cff530080" + text + "|r"
elseif c == PLAYER_COLOR_YELLOW then
return "|cffFFFC00" + text + "|r"
elseif c == PLAYER_COLOR_ORANGE then
return "|cffFE890D" + text + "|r"
elseif c == PLAYER_COLOR_GREEN then
return "|cff1FBF00" + text + "|r"
elseif c == PLAYER_COLOR_PINK then
return "|cffE45AAF" + text + "|r"
elseif c == PLAYER_COLOR_LIGHT_GRAY then
return "|cff949596" + text + "|r"
elseif c == PLAYER_COLOR_LIGHT_BLUE then
return "|cff7DBEF1" + text + "|r"
elseif c == PLAYER_COLOR_AQUA then
return "|cff0F6145" + text + "|r"
elseif c == PLAYER_COLOR_BROWN then
return "|cff4D2903" + text + "|r"
elseif c == PLAYER_COLOR_MAROON then
return "|cff9B0000" + text + "|r"
elseif c == PLAYER_COLOR_NAVY then
return "|cff0000C3" + text + "|r"
elseif c == PLAYER_COLOR_TURQUOISE then
return "|cff00EAFF" + text + "|r"
elseif c == PLAYER_COLOR_VIOLET then
return "|cffBE00FE" + text + "|r"
elseif c == PLAYER_COLOR_WHEAT then
return "|cffEBCD87" + text + "|r"
elseif c == PLAYER_COLOR_PEACH then
return "|cffF8A48B" + text + "|r"
elseif c == PLAYER_COLOR_MINT then
return "|cffBFFF80" + text + "|r"
elseif c == PLAYER_COLOR_LAVENDER then
return "|cffDCB9EB" + text + "|r"
elseif c == PLAYER_COLOR_COAL then
return "|cff282828" + text + "|r"
elseif c == PLAYER_COLOR_SNOW then
return "|cffEBF0FF" + text + "|r"
elseif c == PLAYER_COLOR_EMERALD then
return "|cff00781E" + text + "|r"
elseif c == PLAYER_COLOR_PEANUT then
return "|cffA46F33" + text + "|r"
else
return "|cffFFFFFF" + text + "|r"
endif
endfunction
function GetPlayerNameColoredSimple takes player whichPlayer returns string
return GetPlayerColorString(GetPlayerColor(whichPlayer), GetPlayerName(whichPlayer))
endfunction
function GetPlayerNameColored takes player whichPlayer returns string
return "[" + I2S(GetPlayerId(whichPlayer) + 1) + "]" + GetPlayerNameColoredSimple(whichPlayer)
endfunction
globals
private string array PlayerColorNames
endglobals
private function Init takes nothing returns nothing
set PlayerColorNames[0] = "RED"
set PlayerColorNames[1] = "BLUE"
set PlayerColorNames[2] = "CYAN"
set PlayerColorNames[3] = "PURPLE"
set PlayerColorNames[4] = "YELLOW"
set PlayerColorNames[5] = "ORANGE"
set PlayerColorNames[6] = "GREEN"
set PlayerColorNames[7] = "PINK"
set PlayerColorNames[8] = "LIGHT_GRAY"
set PlayerColorNames[9] = "LIGHT_BLUE"
set PlayerColorNames[10] = "AQUA"
set PlayerColorNames[11] = "BROWN"
set PlayerColorNames[12] = "MAROON"
set PlayerColorNames[13] = "NAVY"
set PlayerColorNames[14] = "TURQUOISE"
set PlayerColorNames[15] = "VIOLET"
set PlayerColorNames[16] = "WHEAT"
set PlayerColorNames[17] = "PEACH"
set PlayerColorNames[18] = "MINT"
set PlayerColorNames[19] = "LAVENDER"
set PlayerColorNames[20] = "COAL"
set PlayerColorNames[21] = "SNOW"
set PlayerColorNames[22] = "EMERALD"
set PlayerColorNames[23] = "PEANUT"
endfunction
function GetPlayerColorName takes player whichPlayer returns string
return StringCase(PlayerColorNames[GetPlayerId(whichPlayer)], false)
endfunction
function GetPlayerColorFromString takes string whichString returns playercolor
local integer i = 0
loop
exitwhen (i == bj_MAX_PLAYERS)
if (whichString == I2S(i + 1) or (PlayerColorNames[i] != null and StringLength(PlayerColorNames[i]) > 0 and StringCase(whichString, true) == PlayerColorNames[i]) or StringStartsWith(GetPlayerName(Player(i)), whichString)) then
return ConvertPlayerColor(i)
endif
set i = i + 1
endloop
return null
endfunction
function GetPlayerFromString takes string whichString returns player
local integer i = 0
loop
exitwhen (i == bj_MAX_PLAYERS)
if (whichString == I2S(i + 1) or (PlayerColorNames[i] != null and StringLength(PlayerColorNames[i]) > 0 and StringCase(whichString, true) == PlayerColorNames[i]) or StringStartsWith(GetPlayerName(Player(i)), whichString)) then
return Player(i)
endif
set i = i + 1
endloop
return null
endfunction
endlibrary
library MathUtils
function Index2D takes integer v1, integer v2, integer max2 returns integer
return v1 * max2 + v2
endfunction
function Index3D takes integer v1, integer v2, integer v3, integer max2, integer max3 returns integer
return v1 * max2 * max3 + v2 * max3 + v3
endfunction
function PolarProjectionX takes real x, real angle, real distance returns real
return x + distance * Cos(angle * bj_DEGTORAD)
endfunction
function PolarProjectionY takes real y, real angle, real distance returns real
return y + distance * Sin(angle * bj_DEGTORAD)
endfunction
function AngleBetweenCoordinatesRad takes real x1, real y1, real x2, real y2 returns real
return Atan2(y2 - y1, x2 - x1)
endfunction
// Utilities already uses the identifier AngleBetweenCoordinates.
function AngleBetweenCoordinatesDeg takes real x1, real y1, real x2, real y2 returns real
return bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
endfunction
function AngleBetweenUnitsDeg takes unit whichUnit0, unit whichUnit1 returns real
return AngleBetweenCoordinatesDeg(GetUnitX(whichUnit0), GetUnitY(whichUnit0), GetUnitX(whichUnit1), GetUnitY(whichUnit1))
endfunction
// Utilities already uses the identifier DistanceBetweenCoordinates.
function DistBetweenCoordinates takes real x1, real y1, real x2, real y2 returns real
local real dx = x2 - x1
local real dy = y2 - y1
return SquareRoot(dx * dx + dy * dy)
endfunction
function DistanceBetweenUnits takes unit whichUnit0, unit whichUnit1 returns real
return DistBetweenCoordinates(GetUnitX(whichUnit0), GetUnitY(whichUnit0), GetUnitX(whichUnit1), GetUnitY(whichUnit1))
endfunction
function DistanceBetweenUnitAndItem takes unit whichUnit, item whichItem returns real
return DistBetweenCoordinates(GetUnitX(whichUnit), GetUnitY(whichUnit), GetItemX(whichItem), GetItemY(whichItem))
endfunction
function DistanceBetweenUnitAndDestructable takes unit whichUnit, destructable whichDestructable returns real
return DistBetweenCoordinates(GetUnitX(whichUnit), GetUnitY(whichUnit), GetDestructableX(whichDestructable), GetDestructableY(whichDestructable))
endfunction
function IntToPrecentage takes integer v, integer max returns real
return I2R(v) * 100.0 / I2R(max)
endfunction
function GetRectFromCircle takes real centerX, real centerY, real radius returns rect
return Rect(centerX - radius, centerY - radius, centerX + radius, centerY + radius)
endfunction
endlibrary
library OnStartGame initializer Init
globals
private trigger startGameTrigger = CreateTrigger()
endglobals
function OnStartGame takes code func returns nothing
call TriggerAddAction(startGameTrigger, func)
endfunction
private function TimerFunctionStartGame takes nothing returns nothing
local timer t = GetExpiredTimer()
call TriggerExecute(startGameTrigger)
call PauseTimer(t)
call DestroyTimer(t)
set t = null
endfunction
private function Init takes nothing returns nothing
call TimerStart(CreateTimer(), 0.0, false, function TimerFunctionStartGame)
endfunction
endlibrary
library Log initializer Init requires MathUtils, StringUtils, PlayerColorUtils
globals
constant boolean LOG_CHAT = true
constant boolean LOG_CINEMATIC_TRANSMISSIONS = true
// This will remove all empty lines at the beginning of a message which helps with SimError.
constant boolean REMOVE_STARTING_EMPTY_LINES = true
constant integer LOG_MAXIMUM = 5000
private string array log
private integer array logCounter
private boolean array logEnabled
private integer array logMaximum
private trigger array callbackTriggers
private integer callbackTriggersCounter = 0
private player triggerLogPlayer = null
private string triggerLogMessage = null
private string tmpMessage = ""
endglobals
function TriggerRegisterLogEvent takes trigger whichTrigger returns nothing
set callbackTriggers[callbackTriggersCounter] = whichTrigger
set callbackTriggersCounter = callbackTriggersCounter + 1
endfunction
function GetTriggerLogPlayer takes nothing returns player
return triggerLogPlayer
endfunction
function GetTriggerLogMessage takes nothing returns string
return triggerLogMessage
endfunction
private function ExecuteCallbackTriggers takes player whichPlayer, string msg returns nothing
local integer i = 0
local player slotPlayer = null
loop
exitwhen (i == callbackTriggersCounter)
if (IsTriggerEnabled(callbackTriggers[i])) then
set triggerLogPlayer = whichPlayer
set triggerLogMessage = msg
call ConditionalTriggerExecute(callbackTriggers[i])
endif
set i = i + 1
endloop
endfunction
private function GetLogEntryIndex takes player whichPlayer, integer index returns integer
return Index2D(index, GetPlayerId(whichPlayer), bj_MAX_PLAYERS)
endfunction
function ClearLog takes player whichPlayer returns nothing
set logCounter[GetPlayerId(whichPlayer)] = 0
endfunction
function IsLogEnabled takes player whichPlayer returns boolean
return logEnabled[GetPlayerId(whichPlayer)]
endfunction
function SetLogEnabled takes player whichPlayer, boolean enabled returns nothing
set logEnabled[GetPlayerId(whichPlayer)] = enabled
endfunction
function GetLogMaximum takes player whichPlayer returns integer
return logMaximum[GetPlayerId(whichPlayer)]
endfunction
function SetLogMaximum takes player whichPlayer, integer maximum returns nothing
set logMaximum[GetPlayerId(whichPlayer)] = maximum
endfunction
function GetLogEntry takes player whichPlayer, integer index returns string
return log[GetLogEntryIndex(whichPlayer, index)]
endfunction
function GetLogCounter takes player whichPlayer returns integer
return logCounter[GetPlayerId(whichPlayer)]
endfunction
static if (REMOVE_STARTING_EMPTY_LINES) then
function RemoveStartingEmptyLines takes string s returns string
local integer i = 0
local integer max = StringLength(s)
if (max > 0) then
loop
exitwhen (i >= max or SubString(s, i, i + 1) != "\n")
set i = i + 1
endloop
return SubString(s, i, max)
endif
return s
endfunction
endif
function AddLog takes player whichPlayer, string msg returns nothing
local integer index = GetLogCounter(whichPlayer)
local integer i = 0
local integer max = 0
if (IsLogEnabled(whichPlayer)) then
// Do this before removing empty lines since StringLength seems to already localize the passed string.
set msg = GetLocalizedString(msg)
static if (REMOVE_STARTING_EMPTY_LINES) then
set msg = RemoveStartingEmptyLines(msg)
endif
set max = GetLogMaximum(whichPlayer)
if (index >= max) then
set i = 1
loop
exitwhen (i >= max)
set log[GetLogEntryIndex(whichPlayer, i - 1)] = log[GetLogEntryIndex(whichPlayer, i)]
set i = i + 1
endloop
set log[GetLogEntryIndex(whichPlayer, max - 1)] = msg
else
set logCounter[GetPlayerId(whichPlayer)] = index + 1
set log[GetLogEntryIndex(whichPlayer, index)] = msg
endif
call ExecuteCallbackTriggers(whichPlayer, msg)
endif
endfunction
private function DisplayTextToPlayerHook takes player toPlayer, real x, real y, string message returns nothing
call AddLog(toPlayer, message)
endfunction
private function DisplayTimedTextToPlayerHook takes player toPlayer, real x, real y, real duration, string message returns nothing
call AddLog(toPlayer, message)
endfunction
private function DisplayTimedTextFromPlayerHook takes player toPlayer, real x, real y, real duration, string message returns nothing
call AddLog(toPlayer, message)
endfunction
private function ForForceAddLog takes nothing returns nothing
call AddLog(GetEnumPlayer(), tmpMessage)
endfunction
private function DisplayTextToForceHook takes force toForce, string message returns nothing
set tmpMessage = message
call ForForce(toForce, function ForForceAddLog)
endfunction
private function DisplayTimedTextToForceHook takes force toForce, real duration, string message returns nothing
set tmpMessage = message
call ForForce(toForce, function ForForceAddLog)
endfunction
private function QuestMessageBJHook takes force f, integer messageType, string message returns nothing
set tmpMessage = " "
call ForForce(f, function ForForceAddLog)
set tmpMessage = message
call ForForce(f, function ForForceAddLog)
endfunction
private function BJDebugMsgHook takes string msg returns nothing
set tmpMessage = msg
call ForForce(GetPlayersAll(), function ForForceAddLog)
endfunction
private function GetChatMessageRecipient takes integer recipient returns string
if (recipient == 0) then
return GetLocalizedString("CHAT_RECIPIENT_ALL")
elseif (recipient == 1) then
return GetLocalizedString("CHAT_RECIPIENT_ALLIES")
elseif (recipient == 2) then
return GetLocalizedString("CHAT_RECIPIENT_OBSERVERS")
endif
return GetLocalizedString("CHAT_RECIPIENT_PRIVATE")
endfunction
// recipient: changes the type of chat channel prefix shown. It has no effect on the message's visibility.
// 0: "All" chat prefix
// 1: "Allies"
// 2: "Observers"
// 3+: "Private"
private function BlzDisplayChatMessageHook takes player whichPlayer, integer recipient, string message returns nothing
set tmpMessage = GetChatMessageRecipient(recipient) + " " + GetPlayerNameColoredSimple(whichPlayer) + ": " + message
call ForForce(GetPlayersAll(), function ForForceAddLog)
endfunction
hook DisplayTextToPlayer DisplayTextToPlayerHook
hook DisplayTimedTextToPlayer DisplayTimedTextToPlayerHook
hook DisplayTimedTextFromPlayer DisplayTimedTextFromPlayerHook
hook DisplayTextToForce DisplayTextToForceHook
hook DisplayTimedTextToForce DisplayTimedTextToForceHook
hook QuestMessageBJ QuestMessageBJHook
hook BJDebugMsg BJDebugMsgHook
hook BlzDisplayChatMessage BlzDisplayChatMessageHook
static if (LOG_CINEMATIC_TRANSMISSIONS) then
private function TransmissionFromUnitWithNameBJHook takes force toForce, unit whichUnit, string unitName, sound soundHandle, string message, integer timeType, real timeVal, boolean wait returns nothing
set tmpMessage = " "
call ForForce(toForce, function ForForceAddLog)
set tmpMessage = "|cffffcc00" + GetLocalizedString(unitName) + ":|r " + GetLocalizedString(message)
call ForForce(toForce, function ForForceAddLog)
endfunction
private function TransmissionFromUnitTypeWithNameBJHook takes force toForce, player fromPlayer, integer unitId, string unitName, location loc, sound soundHandle, string message, integer timeType, real timeVal, boolean wait returns nothing
set tmpMessage = " "
call ForForce(toForce, function ForForceAddLog)
set tmpMessage = "|cffffcc00" + GetLocalizedString(GetObjectName(unitId)) + ":|r " + GetLocalizedString(message)
call ForForce(toForce, function ForForceAddLog)
endfunction
private function SetCinematicSceneHook takes integer portraitUnitId, playercolor color, string speakerTitle, string text, real sceneDuration, real voiceoverDuration returns nothing
set tmpMessage = " "
call ForForce(GetPlayersAll(), function ForForceAddLog)
set tmpMessage = "|cffffcc00" + speakerTitle + ":|r " + GetLocalizedString(text)
call ForForce(GetPlayersAll(), function ForForceAddLog)
endfunction
private function SetCinematicSceneBJHook takes sound soundHandle, integer portraitUnitId, playercolor color, string speakerTitle, string text, real sceneDuration, real voiceoverDuration returns nothing
set tmpMessage = " "
call ForForce(GetPlayersAll(), function ForForceAddLog)
set tmpMessage = "|cffffcc00" + speakerTitle + ":|r " + GetLocalizedString(text)
call ForForce(GetPlayersAll(), function ForForceAddLog)
endfunction
hook TransmissionFromUnitWithNameBJ TransmissionFromUnitWithNameBJHook
hook TransmissionFromUnitTypeWithNameBJ TransmissionFromUnitTypeWithNameBJHook
hook SetCinematicScene SetCinematicSceneHook
hook SetCinematicSceneBJ SetCinematicSceneBJHook
endif
static if (LOG_CHAT) then
private function TriggerActionChatMessage takes nothing returns nothing
call AddLog(GetTriggerPlayer(), GetPlayerNameColoredSimple(GetTriggerPlayer()) + ": " + GetEventPlayerChatString())
endfunction
endif
private function Init takes nothing returns nothing
local trigger t = null
local integer i = 0
local player slotPlayer = null
static if (LOG_CHAT) then
set t = CreateTrigger()
call TriggerAddAction(t, function TriggerActionChatMessage)
endif
loop
exitwhen (i == bj_MAX_PLAYERS)
set slotPlayer = Player(i)
call SetLogEnabled(slotPlayer, GetPlayerController(slotPlayer) == MAP_CONTROL_USER and GetPlayerSlotState(slotPlayer) == PLAYER_SLOT_STATE_PLAYING)
call SetLogMaximum(slotPlayer, LOG_MAXIMUM)
static if (LOG_CHAT) then
call TriggerRegisterPlayerChatEvent(t, slotPlayer, "", false)
endif
set slotPlayer = null
set i = i + 1
endloop
endfunction
endlibrary
library LogUI initializer Init requires Log, OnStartGame, optional FrameLoader
globals
public constant boolean CHAT_COMMAND_ENABLE = true
public constant string CHAT_COMMAND_SHORT = "-l"
public constant string CHAT_COMMAND = "-log"
public constant boolean UPPER_BUTTON_OVERWRITE = true
public constant boolean LOAD_TOC_FILE = true
public constant string TOC_FILE = "war3mapImported\\LogTOC.toc"
public constant real FULLSCREEN_HEIGHT = 0.6
public constant real FULLSCREEN_WIDTH = 0.8
// UI/FrameDef/UI/LogDialog.fdf
public constant real WIDTH = 0.384
public constant real HEIGHT = 0.432
public constant real X = FULLSCREEN_WIDTH / 2.0 - (WIDTH / 2.0)
public constant real Y = FULLSCREEN_HEIGHT - 0.0335
public constant real TITLE_X = X
public constant real TITLE_Y = Y - 0.028
public constant real TITLE_HEIGHT = 0.015
public constant real TEXT_AREA_SPACE = 0.02
public constant real TEXT_AREA_X = X + TEXT_AREA_SPACE
public constant real TEXT_AREA_Y = TITLE_Y - TITLE_HEIGHT - TEXT_AREA_SPACE
public constant real TEXT_AREA_WIDTH = WIDTH - 2.0 * TEXT_AREA_SPACE
public constant real TEXT_AREA_HEIGHT = 0.29
public constant real CLOSE_BUTTON_WIDTH = 0.13
public constant real CLOSE_BUTTON_HEIGHT = 0.035
public constant real CLOSE_BUTTON_X = FULLSCREEN_WIDTH / 2.0 - (CLOSE_BUTTON_WIDTH / 2.0)
public constant real CLOSE_BUTTON_Y = TEXT_AREA_Y - TEXT_AREA_HEIGHT - TEXT_AREA_SPACE
private framehandle BackgroundFrame = null
private framehandle TextAreaFrame = null
private trigger closeTrigger = null
private trigger clickUpperButtonTrigger = null
private trigger upperButtonHotkeyTrigger = null
private trigger chatCommandTrigger = CreateTrigger()
private trigger logTrigger = CreateTrigger()
private sound logSound = CreateSound("Sound\\Interface\\BigButtonClick", false, false, true, 12700, 12700, "")
endglobals
function EnableLogUI takes nothing returns nothing
call EnableTrigger(closeTrigger)
call EnableTrigger(chatCommandTrigger)
call EnableTrigger(logTrigger)
endfunction
function DisableLogUI takes nothing returns nothing
call DisableTrigger(closeTrigger)
call DisableTrigger(chatCommandTrigger)
call DisableTrigger(logTrigger)
endfunction
function UpdateLogUIVisible takes nothing returns nothing
local integer max = GetLogCounter(GetLocalPlayer())
local integer i = 0
call BlzFrameSetText(TextAreaFrame, "")
loop
exitwhen (i == max)
call BlzFrameAddText(TextAreaFrame, GetLogEntry(GetLocalPlayer(), i))
set i = i + 1
endloop
endfunction
function SetLogUIVisible takes boolean visible returns nothing
if (visible) then
call UpdateLogUIVisible()
endif
call BlzFrameSetVisible(BackgroundFrame, visible)
endfunction
function ShowLogUI takes nothing returns nothing
call SetLogUIVisible(true)
endfunction
function HideLogUI takes nothing returns nothing
call SetLogUIVisible(false)
endfunction
function SetLogUIVisibleForPlayer takes player whichPlayer, boolean visible returns nothing
if (whichPlayer == GetLocalPlayer()) then
call SetLogUIVisible(visible)
endif
endfunction
function ShowLogUIForPlayer takes player whichPlayer returns nothing
if (whichPlayer == GetLocalPlayer()) then
call SetLogUIVisible(true)
endif
endfunction
function HideLogUIForPlayer takes player whichPlayer returns nothing
if (whichPlayer == GetLocalPlayer()) then
call SetLogUIVisible(false)
endif
endfunction
private function CloseFunction takes nothing returns nothing
call HideLogUIForPlayer(GetTriggerPlayer())
endfunction
private function ClickUpperButtonFunction takes nothing returns nothing
call ForceUIKeyBJ(GetTriggerPlayer(), "F12")
call ShowLogUIForPlayer(GetTriggerPlayer())
if (GetTriggerPlayer() == GetLocalPlayer()) then
call StartSound(logSound)
endif
endfunction
private function CreateUpperButtonUI takes nothing returns nothing
local integer i = 0
local player slotPlayer = null
if (clickUpperButtonTrigger != null) then
call DestroyTrigger(clickUpperButtonTrigger)
endif
set clickUpperButtonTrigger = CreateTrigger()
call BlzTriggerRegisterFrameEvent(clickUpperButtonTrigger, BlzGetFrameByName("UpperButtonBarChatButton", 0), FRAMEEVENT_CONTROL_CLICK)
call TriggerAddAction(clickUpperButtonTrigger, function ClickUpperButtonFunction)
if (upperButtonHotkeyTrigger != null) then
call DestroyTrigger(upperButtonHotkeyTrigger)
endif
set upperButtonHotkeyTrigger = CreateTrigger()
loop
exitwhen (i == bj_MAX_PLAYERS)
set slotPlayer = Player(i)
if (GetPlayerController(slotPlayer) == MAP_CONTROL_USER and GetPlayerSlotState(slotPlayer) == PLAYER_SLOT_STATE_PLAYING) then
call BlzTriggerRegisterPlayerKeyEvent(upperButtonHotkeyTrigger, slotPlayer, OSKEY_F12, 0, true)
endif
set i = i + 1
endloop
call TriggerAddAction(upperButtonHotkeyTrigger, function ClickUpperButtonFunction)
endfunction
private function CreateUI takes nothing returns nothing
local framehandle f = null
set BackgroundFrame = BlzCreateFrame("EscMenuBackdrop", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0),0,0)
call BlzFrameSetAbsPoint(BackgroundFrame, FRAMEPOINT_TOPLEFT, X, Y)
call BlzFrameSetAbsPoint(BackgroundFrame, FRAMEPOINT_BOTTOMRIGHT, X + WIDTH, Y - HEIGHT)
call BlzFrameSetLevel(BackgroundFrame, 1)
set f = BlzCreateFrame("EscMenuTitleTextTemplate", BackgroundFrame, 0, 0)
call BlzFrameSetAbsPoint(f, FRAMEPOINT_TOPLEFT, TITLE_X, TITLE_Y)
call BlzFrameSetAbsPoint(f, FRAMEPOINT_BOTTOMRIGHT, TITLE_X + WIDTH, TITLE_Y - TITLE_HEIGHT)
call BlzFrameSetTextAlignment(f, TEXT_JUSTIFY_TOP, TEXT_JUSTIFY_CENTER)
call BlzFrameSetText(f, GetLocalizedString("MESSAGE_LOG"))
set TextAreaFrame = BlzCreateFrame("EscMenuTextAreaTemplate", BackgroundFrame, 0, 0)
call BlzFrameSetAbsPoint(TextAreaFrame, FRAMEPOINT_TOPLEFT, TEXT_AREA_X, TEXT_AREA_Y)
call BlzFrameSetAbsPoint(TextAreaFrame, FRAMEPOINT_BOTTOMRIGHT, TEXT_AREA_X + TEXT_AREA_WIDTH, TEXT_AREA_Y - TEXT_AREA_HEIGHT)
call BlzFrameSetFont(TextAreaFrame, "MasterFont", 0.011, 0)
set f = BlzCreateFrame("ScriptDialogButton", BackgroundFrame, 0, 0)
call BlzFrameSetAbsPoint(f, FRAMEPOINT_TOPLEFT, CLOSE_BUTTON_X, CLOSE_BUTTON_Y)
call BlzFrameSetAbsPoint(f, FRAMEPOINT_BOTTOMRIGHT, CLOSE_BUTTON_X + CLOSE_BUTTON_WIDTH, CLOSE_BUTTON_Y - CLOSE_BUTTON_HEIGHT)
call BlzFrameSetText(f, "|cffffcc00" + GetLocalizedString("OK") + "|r")
if (closeTrigger != null) then
call DestroyTrigger(closeTrigger)
endif
set closeTrigger = CreateTrigger()
call BlzTriggerRegisterFrameEvent(closeTrigger, f, FRAMEEVENT_CONTROL_CLICK)
call TriggerAddAction(closeTrigger, function CloseFunction)
static if (UPPER_BUTTON_OVERWRITE) then
call CreateUpperButtonUI()
endif
call HideLogUI()
endfunction
private function TriggerActionShowLogUI takes nothing returns nothing
call ShowLogUIForPlayer(GetTriggerPlayer())
endfunction
private function TriggerActionLog takes nothing returns nothing
if (GetTriggerLogPlayer() == GetLocalPlayer()) then
if (BlzFrameIsVisible(BackgroundFrame)) then
call UpdateLogUIVisible()
endif
endif
endfunction
private function Start takes nothing returns nothing
local integer i = 0
local player slotPlayer = null
static if (CHAT_COMMAND_ENABLE) then
loop
exitwhen (i == bj_MAX_PLAYERS)
set slotPlayer = Player(i)
if (GetPlayerController(slotPlayer) == MAP_CONTROL_USER and GetPlayerSlotState(slotPlayer) == PLAYER_SLOT_STATE_PLAYING) then
if (StringLength(CHAT_COMMAND_SHORT) > 0) then
call TriggerRegisterPlayerChatEvent(chatCommandTrigger, slotPlayer, CHAT_COMMAND_SHORT, true)
endif
if (StringLength(CHAT_COMMAND) > 0) then
call TriggerRegisterPlayerChatEvent(chatCommandTrigger, slotPlayer, CHAT_COMMAND, true)
endif
endif
set slotPlayer = null
set i = i + 1
endloop
call TriggerAddAction(chatCommandTrigger, function TriggerActionShowLogUI)
endif
call TriggerRegisterLogEvent(logTrigger)
call TriggerAddAction(logTrigger, function TriggerActionLog)
static if (LOAD_TOC_FILE) then
call BlzLoadTOCFile(TOC_FILE)
endif
call CreateUI()
endfunction
private function Init takes nothing returns nothing
call OnStartGame(function Start)
// Prevents crashes on loading save games:
static if (LIBRARY_FrameLoader) then
call FrameLoaderAdd(function CreateUI)
endif
endfunction
endlibrary