quraji
zap
- Reaction score
- 144
Talkative is discontinued for now.
What is Talkative?
It's simply a system to handle chatting/messaging, to be used alongside with modifying your UI to not show normal messages.
What does it do?
Like I've said, it mimics normal messaging. It also allows for other features not included in normal messaging. Right now the feature list includes:
What is Talkative?
It's simply a system to handle chatting/messaging, to be used alongside with modifying your UI to not show normal messages.
What does it do?
Like I've said, it mimics normal messaging. It also allows for other features not included in normal messaging. Right now the feature list includes:
- Squelching - Is a player annoying you? Squelch the bastard!
- Ally Chat - Easily send messages to only your allies (perfect for scheming!)
- Unit Chat! - Magical moving floating text above units!
Code retained for historical reasons (take what you want):
JASS:
library Talkative initializer Init
//___________________________________________________
// Talkative! by quraji
//_________________________v2.0______________________
//_________________________UnitChat is back!_________
globals
public unit array UnitChat_Units [12] // set this to desired unit chat unit, you can change this any time
// UnitChat_Units[0] = Player One (red)'s unit
// UnitChat_Units[1] = Player Two (blue)'s unit
// etc.
//***************************************************
// CONFIGURATION GLOBALS *
//***************************************************
//
// Gamecache
private constant gamecache TalkativeCache = InitGameCache("TalkativeCache")
//
// The minimum amount of time to display entered messages
// Actual time will be this + calculated extra
private constant real MinDuration = 6.
//
// Desired speed for the timer moving unit text (recommend .01 to .05)
private constant real UnitChat_TimerPeriod = .03
//
// Desired offset for text tags above units
private constant real UnitChat_Offset = 10.
//
// String constants:
//
// Desired notification text colour
private constant string Colour_Notify = "|cffb0b0b0"
//
// Desired squelching command
private constant string Command_Squelch = "!s"
//
// Desired ally chat command
private constant string Command_AllyChat = "!a"
//
// Desired unit chat command
private constant string Command_UnitChat = "!u"
//
// Desired prefix for talking to allies
private constant string Prefix_Allies = "[Allies] "
//
// Desired prefix for talking to all
private constant string Prefix_All = "[All] "
//
//***************************************************
endglobals
// don't touch these! don't even look!
type boolarray extends boolean array [12]
type boolarray_ar extends boolarray [12]
globals
private string array PlayerColours [12]
private boolarray array SquelchList [12]
private boolean array AllyChatOn [12]
private boolean array UnitChatOn [12]
endglobals
globals
private texttag array UnitChat_Tags [12]
private real array UnitChat_Lifespan [12]
private real array UnitChat_Age [12]
endglobals
//_____________________________________________________________________________________________
//***************************************************
// FORMATTING FUNCTIONS *
//***************************************************
// reverses a string
// Example:
// Input - lol
// Output - lol
function Format_Reverse takes string s returns string
local integer i = 0
local integer j = StringLength(s)
local string t = ""
loop
set t = t + SubString(s, j-i, j-i+1)
exitwhen i == j
set i = i + 1
endloop
return t
endfunction
// trim whitespace from the left of a string
function Format_TrimLeft takes string s returns string
local integer i
local string t
loop
set i = StringLength(s)
set t = SubString(s, 0, 1)
if t == " " then
set s = SubString(s, 1, i)
else
return s
endif
endloop
return s
endfunction
// trim whitespace from the, you guessed it - right - of a string
function Format_TrimRight takes string s returns string
// some fancy footwork...
set s = Format_Reverse(s)
set s = Format_TrimLeft(s)
return Format_Reverse(s)
endfunction
// trim whitespace from both sides of a string
// it's like liposuction for a string
function Format_Trim takes string s returns string
set s = Format_TrimRight(s)
return Format_TrimLeft(s)
endfunction
// add fromplayer's name (Coloured) to the front of the string
// no, this can't be inlined, damnit!
private function Format_AddName takes string s, player fromplayer returns string
local integer i = GetPlayerId(fromplayer)
set s = PlayerColours<i> + GetPlayerName(fromplayer) + ":|r " + s
return s
endfunction
//**************************************************
// END FORMATTING FUNCTIONS *
//**************************************************
//_____________________________________________________________________________________________
//**************************************************
// MAIN FUNCTIONS *
//**************************************************
// complicated math...should see a huge memory/cpu usage increase here
// and no, this can't be inlined either! Why? Because I said so!
private function CalcDuration takes string s returns real
local integer i = StringLength(s)
local real r = 12 // .12 being an arbitrary good looking value
return r*i + MinDuration
endfunction
private function H2I takes handle h returns integer
return h
return 0
endfunction
private function GetStoredUnit takes gamecache gc, string mk, string k returns unit
return GetStoredInteger(gc, mk, k)
return null
endfunction
// squelch a player, because he's an annoying moron <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue :p" loading="lazy" data-shortname=":p" />
private function Squelch takes string s, player p returns boolean
local integer i = StringLength(s)
local integer j = StringLength(Command_Squelch)
local boolean b
// cut off the prefix and trim
set s = Format_Trim(SubString(s, j, i))
set i = 0
set j = -1
loop
exitwhen i == 12
if GetPlayerName(Player(i)) == s then
set j = i
endif
set i = i + 1
endloop
set i = GetPlayerId(p)
// if no matches were found, return false
if j == -1 then
return false
// else switch the squelch value
else
set b = SquelchList<i>[j]
set SquelchList<i>[j] = not b
endif
if Player(j) == p then //make fun of the player for being a smartass
if b then
call DisplayTimedTextToPlayer(Player(j), 0., 0., MinDuration, Colour_Notify + "You039;ve unsquelched|r " + PlayerColours<i>+ "yourself|r" + Colour_Notify + ". Darn, I was enjoying the silence...")
else
call DisplayTimedTextToPlayer(Player(j), 0., 0., MinDuration, Colour_Notify + "You039;ve squelched|r " + PlayerColours<i> + "yourself|r" + Colour_Notify + "! I know, sometimes I find you annoying too.")
endif
else
if b then
call DisplayTimedTextToPlayer(Player(j), 0., 0., MinDuration, PlayerColours<i> + GetPlayerName(p) + "|r" + Colour_Notify + " has unsquelched you!")
call DisplayTimedTextToPlayer(Player(i), 0., 0., MinDuration, Colour_Notify + "You have unsquelched " + PlayerColours[j] + GetPlayerName(Player(j)) + "|r" + Colour_Notify + "!")
else
call DisplayTimedTextToPlayer(Player(j), 0., 0., MinDuration, PlayerColours<i> + GetPlayerName(p) + "|r" + Colour_Notify + "has squelched you!")
call DisplayTimedTextToPlayer(Player(i), 0., 0., MinDuration, Colour_Notify + "You have squelched|r " + PlayerColours[j] + GetPlayerName(Player(j)) + "|r" + Colour_Notify + "!")
endif
endif
return true
endfunction
private function AllyChat takes string s, player p returns nothing
local integer i = StringLength(s)
local integer j = StringLength(Command_AllyChat)
local real r
// cut off prefix and trim
set s = Format_Trim(SubString(s, j, i))
set r = CalcDuration(s)
set s = Format_AddName(s, p)
set i = GetPlayerId(p)
set j = GetPlayerId(GetLocalPlayer())
if IsPlayerAlly(p, GetLocalPlayer()) or GetLocalPlayer() == p and SquelchList<i>[j] == false then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0., 0., r, Prefix_Allies + s)
endif
endfunction
private function UnitChat_Callback takes nothing returns nothing
local timer timmy = GetExpiredTimer()
local string s = I2S(H2I(timmy))
local integer j = GetStoredInteger(TalkativeCache, s, "id")
local unit u = GetStoredUnit(TalkativeCache, s, "u")
if UnitChat_Age[j] >= UnitChat_Lifespan[j] then
call DestroyTextTag(UnitChat_Tags[j])
call PauseTimer(timmy)
call DestroyTimer(timmy)
call FlushStoredMission(TalkativeCache, s)
return
endif
call SetTextTagPosUnit(UnitChat_Tags[j], u, UnitChat_Offset)
set UnitChat_Age[j] = UnitChat_Age[j] + UnitChat_TimerPeriod
endfunction
private function UnitChat takes string s, player p returns nothing
local integer i = StringLength(s)
local integer j = GetPlayerId(p)
local timer timmy = CreateTimer()
local unit u = UnitChat_Units[j]
if u == null then
return
endif
call DestroyTextTag(UnitChat_Tags[j])
set UnitChat_Tags[j] = CreateTextTag()
set UnitChat_Lifespan[j] = CalcDuration(s)
set UnitChat_Age[j] = 0.
call StoreInteger(TalkativeCache, I2S(H2I(timmy)), "id", j)
call StoreInteger(TalkativeCache, I2S(H2I(timmy)), "u", H2I(u))
call SetTextTagText(UnitChat_Tags[j], s, .023)
call SetTextTagPosUnit(UnitChat_Tags[j], UnitChat_Units[j], UnitChat_Offset)
call TimerStart(timmy, UnitChat_TimerPeriod, true, function UnitChat_Callback)
set timmy = null
endfunction
// the response function for when a player enters a message
private function ChatResponse takes nothing returns nothing
local player p = GetTriggerPlayer()
local string s = GetEventPlayerChatString()
local integer i = GetPlayerId(GetTriggerPlayer())
local integer j = GetPlayerId(GetLocalPlayer())
local real r = 0.
// check to see if the player wants to squelch someone
if SubString(s, 0, StringLength(Command_Squelch)) == Command_Squelch then
call Squelch(s, p)
return
// check to see if the player wants to switch modes
elseif s == Command_AllyChat then
set AllyChatOn<i> = not AllyChatOn<i>
return
elseif s == Command_UnitChat then
set UnitChatOn<i> = not UnitChatOn<i>
return
endif
//check prefixes
if SubString(s, 0, StringLength(Command_AllyChat)) == Command_AllyChat then
if AllyChatOn<i> then
if SquelchList<i>[j] != true then
set s = Format_Trim(SubString(s, StringLength(Command_AllyChat), StringLength(s)))
set r = CalcDuration(s)
set s = Format_AddName(s, p)
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0., 0., r, Prefix_All + s)
endif
return
else
call AllyChat(s, p)
return
endif
elseif SubString(s, 0, StringLength(Command_UnitChat)) == Command_UnitChat then
set s = Format_Trim(SubString(s, StringLength(Command_UnitChat), i))
call UnitChat(s, p)
return
endif
if UnitChatOn<i> then
call UnitChat(s, p)
return
endif
// give the string a haircut
set s = Format_Trim(s)
// don't bother further formatting or displaying an empty or squelched message
if s == "" or SquelchList<i>[j] == true then
return
endif
// calculate duration of the string (remember: huge cpu usage increase)
set r = CalcDuration(s)
// add the player's name to the message
set s = Format_AddName(s, p)
if AllyChatOn<i> then
if IsPlayerAlly(p, GetLocalPlayer()) or GetLocalPlayer() == p then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0., 0., r, Prefix_Allies + s)
endif
else
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0., 0., r, Prefix_All + s)
endif
endfunction
//**************************************************
// END MAIN FUNCTIONS *
//**************************************************
//_____________________________________________________________________________________________
// Initialize stuff + register the chat event from players
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
local integer j = 0
loop
exitwhen i == 12
// this function call is necessary to save a function call! Remember, efficiency doesn't come easy
if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
call TriggerRegisterPlayerChatEvent(t, Player(i), "", false)
endif
set i = i + 1
endloop
call TriggerAddAction(t, function ChatResponse)
// PlayerColours setup
set PlayerColours[0] = "|cffff0000" // red
set PlayerColours[1] = "|cff0000ff" // blue
set PlayerColours[2] = "|cff00ffff" // cyan
set PlayerColours[3] = "|cff551a8b" // purple
set PlayerColours[4] = "|cffffff00" // yellow
set PlayerColours[5] = "|cffffa500" // orange
set PlayerColours[6] = "|cff00ff00" // green
set PlayerColours[7] = "|cffff00ff" // magenta
set PlayerColours[8] = "|cffbebebe" // grey
set PlayerColours[9] = "|cff00bfff" // light blue
set PlayerColours[10] = "|cff006400" // dark green
set PlayerColours[11] = "|cff8b2323" // brown
// end PlayerColours
set i = 0
set SquelchList = boolarray_ar.create()
loop
exitwhen i == boolarray_ar.size()
set SquelchList<i> = boolarray.create()
set j = 0
loop
exitwhen j == boolarray.size()
set SquelchList<i>[j] = false
set j = j + 1
endloop
set i = i + 1
endloop
endfunction
// you finished, good job!
endlibrary</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>