System Talkative! Chat System

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:
  • 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) + &quot;:|r &quot; + s
        
        return s
    endfunction
        
    //**************************************************
    //            END FORMATTING FUNCTIONS             *
    //**************************************************

//_____________________________________________________________________________________________
    
    
    //**************************************************
    //                 MAIN FUNCTIONS                  *
    //**************************************************
    
    //  complicated math...should see a huge memory/cpu usage increase here
    //  and no, this can&#039;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&#039;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 + &quot;You&#039;ve unsquelched|r &quot; + PlayerColours<i>+ &quot;yourself|r&quot;  + Colour_Notify + &quot;. Darn, I was enjoying the silence...&quot;)
            else
                call DisplayTimedTextToPlayer(Player(j), 0., 0., MinDuration, Colour_Notify + &quot;You&#039;ve squelched|r &quot; + PlayerColours<i> + &quot;yourself|r&quot;  + Colour_Notify +  &quot;! I know, sometimes I find you annoying too.&quot;)
            endif
            
        else
        
            if b then
                call DisplayTimedTextToPlayer(Player(j), 0., 0., MinDuration, PlayerColours<i> + GetPlayerName(p) + &quot;|r&quot;   + Colour_Notify + &quot; has unsquelched you!&quot;)
                call DisplayTimedTextToPlayer(Player(i), 0., 0., MinDuration, Colour_Notify + &quot;You have unsquelched &quot; + PlayerColours[j] + GetPlayerName(Player(j)) + &quot;|r&quot;  + Colour_Notify + &quot;!&quot;)
            else
                call DisplayTimedTextToPlayer(Player(j), 0., 0., MinDuration, PlayerColours<i> + GetPlayerName(p) + &quot;|r&quot;  + Colour_Notify +  &quot;has squelched you!&quot;)
                call DisplayTimedTextToPlayer(Player(i), 0., 0., MinDuration, Colour_Notify + &quot;You have squelched|r &quot; + PlayerColours[j] + GetPlayerName(Player(j)) + &quot;|r&quot;  + Colour_Notify + &quot;!&quot;)           
            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, &quot;id&quot;)
        local unit u = GetStoredUnit(TalkativeCache, s, &quot;u&quot;)
        
        if UnitChat_Age[j] &gt;= 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)), &quot;id&quot;, j)
        call StoreInteger(TalkativeCache, I2S(H2I(timmy)), &quot;u&quot;, 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&#039;t bother further formatting or displaying an empty or squelched message
        if s == &quot;&quot; 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&#039;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&#039;t come easy
            if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
            
                call TriggerRegisterPlayerChatEvent(t, Player(i), &quot;&quot;, false)
                
            endif
            
            set i = i + 1
        endloop
        
        call TriggerAddAction(t, function ChatResponse)
        
        // PlayerColours setup
        set PlayerColours[0] = &quot;|cffff0000&quot;  //  red
        set PlayerColours[1] = &quot;|cff0000ff&quot;  //  blue
        set PlayerColours[2] = &quot;|cff00ffff&quot;  //  cyan
        set PlayerColours[3] = &quot;|cff551a8b&quot;  //  purple
        set PlayerColours[4] = &quot;|cffffff00&quot;  //  yellow
        set PlayerColours[5] = &quot;|cffffa500&quot;  //  orange
        set PlayerColours[6] = &quot;|cff00ff00&quot;  //  green
        set PlayerColours[7] = &quot;|cffff00ff&quot;  //  magenta
        set PlayerColours[8] = &quot;|cffbebebe&quot;  //  grey
        set PlayerColours[9] = &quot;|cff00bfff&quot;  //  light blue
        set PlayerColours[10] = &quot;|cff006400&quot; //  dark green
        set PlayerColours[11] = &quot;|cff8b2323&quot; //  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>

 

Kenny

Back for now.
Reaction score
202
So let me get this straight... You neatened up your previous code, added a few cool things and took away the overhead chat (was there any reason to remove it?)? If that is so, this is amazing, lol. Kinda makes me regret trying to make my own. I see your script and i see many things that are almost identical, but these new functions you have put in makes this tops! Good work. For those hidding the instant in-game messages in one of their games this would be there best bet for a replacement message system.

I have learnt a fair bit from this and i hope you dont mind if i use this knowledge in my system, i will give you credits if i take anything straight from yours. Too bad i cant +rep you.'

Oh and i think you can squelch people in normal messaging, i think i did it once. But this is much simpler.

Also i do not fully understand what this "trimming" is... what exactly is this whitespace?
 
D

DsD)Core(

Guest
I'd go on bnet with you for a flame & squelch war :D
Nice system!
 

Drunken_God

Hopes to get back into Mapmaking with SC2 :)
Reaction score
106
hm its not that useful
maybe add an function that lets you activate team talk

squelching is funny
 

quraji

zap
Reaction score
144
So let me get this straight... You neatened up your previous code, added a few cool things and took away the overhead chat (was there any reason to remove it?)? If that is so, this is amazing, lol. Kinda makes me regret trying to make my own. I see your script and i see many things that are almost identical, but these new functions you have put in makes this tops! Good work. For those hidding the instant in-game messages in one of their games this would be there best bet for a replacement message system.

I have learnt a fair bit from this and i hope you dont mind if i use this knowledge in my system, i will give you credits if i take anything straight from yours. Too bad i cant +rep you.'

Oh and i think you can squelch people in normal messaging, i think i did it once. But this is much simpler.

Also i do not fully understand what this "trimming" is... what exactly is this whitespace?

Yes, that is what I did, and yes it is amazing ;)

Sure, I don't mind.

You probably can, I'm an expert at reinventing stuff that's already been done. But for now I'll assume that you can't, as it is one of the things that makes this system purposeful :thup:

Whitespace is empty space...spaces. When I trim the whitespace it just makes things neater so if someone messages this:
Code:
Someone:                           HAI I LIEK TO TYPE WITH LOTS OF SPACES
it comes out as:
Code:
Someone: HAI I LIEK TO TYPE WITH LOTS OF SPACES


I'd go on bnet with you for a flame & squelch war :D
Nice system!

Thanks for the compliment, and what's your name/realm?

hm its not that useful
maybe add an function that lets you activate team talk

You are correct my friend ;)
Thanks for the suggestion, and yes I will be adding team talk.


Thanks for the comments/suggestions folks, keep them coming :thup:
Expect an update today!
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
It's spelled gray, not everyone is from the US you know =/
 

quraji

zap
Reaction score
144
Update! I've put up Talkative v2.0 :)

What's new?

Ally Chat! Now you can talk to your allies by typing the Ally Chat command then your message, or just type the command by itself to turn Ally Chat mode on! When you're in Ally Chat mode, type the Ally Chat command plus a message to send the message in All Chat, while staying in Ally chat. Type the command by itself again to go back in to AllChat mode.

Unit Chat! Now you can talk from your unit! Type the Unit Chat command plus a message to add your message over a unit, or type the command alone to enter Unit Chat mode. Use the Ally Chat command to type in normal chat. Use the Unit Chat command again to exit Unit Chat mode.

As always, comments/suggestions/questions are welcome :thup:
 

XxShadyxX

I abused the rep system.
Reaction score
81
Lol gj!
um here is a Idea!!
-shout blue text

makes a floating text of what you typed and it is really big and for the length of the text = time of the text it will follow a unit around that you say it to?

Like i say -shout blue Im going to get you!!
and it creates a large floating text that chases blue around until it fades away.
what do you think?
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
You should look into the combination of WC3 and fonts.
From what I recall, it is possible to use custom fonts, if so: try implementing a smaller font so a small conversation doesn't clog up your entire screen.
 

quraji

zap
Reaction score
144
You should look into the combination of WC3 and fonts.
From what I recall, it is possible to use custom fonts, if so: try implementing a smaller font so a small conversation doesn't clog up your entire screen.

That would work well with this system, but I think it's up to the user to do that themselves ;)


About the shouting suggestion, I think that's a little too specific :p
But I may very well add yelling for unit talk (similar to WoW).
Thank you for the suggestion!
 

quraji

zap
Reaction score
144
what do you mean by too specific?

I mean that it's applications would be very limited, not many people would use it I don't think.
Also, it could be easily abused. You could just constantly shout at someone, and it could get very annoying (maybe then you would VoteOwn them....hmmm :rolleyes:)

Thank you for the suggestion though (+rep)

edit: Seems I have already given you rep recently...luck you :p
 

XxShadyxX

I abused the rep system.
Reaction score
81
yea you did :p
for my my hero selection system
anyway this would be very fun
just when someone does it destroy the last one they made as the first part of the function
it is really funny I have it in one of my single player maps lol

think about it
you type in a angry face
and a large angry face is chaseing a player around it would be hilarious!

for your VoteOwn you can have it say
you can live if you beat this challange!
it creates a large angry face that chases you and when it catches you it owns you lol
it will be so funny to see the noob running around the map being chased by a angry face
LMAO its funny just thinking about it!!!
 

Kenny

Back for now.
Reaction score
202
OMG! You updated and i didnt notice. I think i will officially delete my system, this thing is amazing. I may actually think about making player messages in my game even though it doesnt need it just for this :p. Good to see unit chat is back, but as for the system it is now above my head. So i will just say good job :).

EDIT

JASS:
    //Desired squelching command
        private constant string Command_Squelch = &quot;!s&quot;
    //
    //  Desired ally chat command
        private constant string Command_AllyChat = &quot;!a&quot;
    //
    //  Desired unit chat command
        private constant string Command_UnitChat = &quot;!u&quot;
    //
    //  Desired prefix for talking to allies
        private constant string Prefix_Allies = &quot;[Allies] &quot;
    //
    //  Desired prefix for talking to all
        private constant string Prefix_All = &quot;[All] &quot;


Whats the difference between Command_AllyChat and Prefix_Allies?
 

quraji

zap
Reaction score
144
Whats the difference between Command_AllyChat and Prefix_Allies?

The command is to type in allies, the prefix is appended to the beginning of the message, like in a normal game.

Say I type:
Code:
!a Yo what's up homies
It comes out as:
Code:
[Allies] quraji: Yo what's up homies
"!a" is the command, "[Allies]" is the prefix...you might have been confused because I previously named the commands as prefixes.
Of course you can change this to whatever you want...such as [Homies]...or nothing at all.

Fixed the smiley since you asked so nicely.
OMFG U FKIN IDOT WRONG SMILEY I WANTED THE :D OMG1!!!1
No, just kidding, thanks very much! The other one was depressing...


Um...what smiley? :eek:
I accidentally clicked :( as my icon for the post, but now it's a :) thanks to Jindo.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top