//////////////////////////////////////////////////////////////////////////////////
// Used to produce speech text above a unit. Argument definitions are below.
//
// string msg - The text to be displayed above a unit.
// unit u - The unit to display the text over.
// boolean centerText - If true, the text will be centered over the unit,
// rather than left justified on the unit location.
// boolean thoughtBubble - If true, the text will appear to be a thought bubble
// using the form: . o O ( <msg> ). Also note, that
// setting this to true, will override centerText and
// force the text to be left justified on the unit location.
// integer moodIndex - The mood to be used. Valid range is 0 .. n-1, where n is
// the maximum number of moods you have defined.
// real delay - Delay is the amount of time to wait after having typed
// out all of the text, and before fading it.
//////////////////////////////////////////////////////////////////////////////////
function Speech takes string msg, unit u, boolean centerText, boolean thoughtBubble, integer moodIndex, real delay returns boolean
local integer index = 0
local integer numMoods = 4 // Set to the number of moods that are used
local location l = GetUnitLoc(u) // Get location of unit to apply floating text
local real array mood
local texttag tt
local real offsetX = 0.0 // The offset used for floating text
// Initialize Mood colors - Add more by adding to the array and setting numMoods.
// Informational
set mood[0] = 100.0 // red percentage
set mood[1] = 100.0 // green precentage
set mood[2] = 100.0 // blue percentage
// Angry
set mood[3] = 100.0
set mood[4] = 0.0
set mood[5] = 0.0
// Help!
set mood[6] = 100.0
set mood[7] = 60.0
set mood[8] = 20.0
// Warning!
set mood[9] = 100.0
set mood[10] = 100.0
set mood[11] = 0.0
// Verify that moodIndex is not set to an invalid number
if (moodIndex < 0 or moodIndex > numMoods) then
set moodIndex = 0 // default to mood 0
endif
// Determine if normal text, or thought bubble is used
if (thoughtBubble == true) then
set msg = ". o O ( " + msg + " )"
else
// Setup for text positioning...only do this if thought bubble isn't used
if (centerText == true) then
if (StringLength(msg) > 44) then
set offsetX = -220
else
set offsetX = 0.0 - (StringLength(msg) * 5.0) // generates negative value to shift text to left
endif
endif
endif
set moodIndex = moodIndex * 3 // used to reference position in the mood array
// Display the text (typed out)
set index = 1
loop
exitwhen index > StringLength(msg)
set tt = CreateTextTagLocBJ(SubStringBJ(msg,1,index), OffsetLocation(l, offsetX, 0), 150.00, 8, mood[moodIndex], mood[moodIndex+1], mood[moodIndex+2], 0)
call TriggerSleepAction(0.1)
if (index < StringLength(msg)) then
call DestroyTextTagBJ(tt)
endif
set index = index + 1
endloop
call TriggerSleepAction(delay)
call DestroyTextTagBJ(tt)
// Fade the text
set index = 1
loop
exitwhen index > 20
set tt = CreateTextTagLocBJ(msg, OffsetLocation(l, offsetX, 0), 150.00, 8, mood[moodIndex], mood[moodIndex+1], mood[moodIndex+2], index*5)
call TriggerSleepAction(0.1)
call DestroyTextTagBJ(tt)
set index = index + 1
endloop
// Destroy the local location
call RemoveLocation(l)
return true
endfunction