Chat in console

FehaFeha Join Date: 2006-11-16 Member: 58633Members
<div class="IPBDescription">Just a quick mod</div>I have for a long time wanted a chat log of some sort, so I decided to make a mod for it.

Well, I am very lazy, and had decided already before I begun that I would be satisfied with the message printing in console. Thus that is what I did.

It is not really like the chat log you are used to see in consoles. It does not print who said what, just the message, and then "- Client" (even though someone else said something). But as it works I figured it is enough.


Got to:
E:\Program\Steam\steamapps\common\natural selection 2\ns2\lua

and open Chat.lua

At line 101 there is a function named "OnCommandChat", replace it with this code:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function OnCommandChat(teamOnly, playerName, teamNumber, message)

    player = Client.GetLocalPlayer()

    // color, playername, color, message        
    table.insert(chatMessages, GetColorForTeamNumber(tonumber(teamNumber)))
    
    // Pre-pend "team" or "all"
    local preMessageString = string.format("%s%s: ", ConditionalValue(tonumber(teamOnly) == 1, "(Team) ", ""), DecodeStringFromNetwork(playerName))
    
    table.insert(chatMessages, preMessageString)
    table.insert(chatMessages, kChatTextColor)
    
    // Tack on location name if any
    local locationName = GetLocationName(player:GetOrigin())
    if(locationName ~= "") then
        message = string.format("%s (%s)", message, locationName)
    end
    
    table.insert(chatMessages, message)
    
    //Should print chat messages to console - by feha
    Print(message)
    
    // reserved for possible texture name
    table.insert(chatMessages, "")
    // texture x
    table.insert(chatMessages, 0)
    // texture y
    table.insert(chatMessages, 0)
    // entity id
    table.insert(chatMessages, 0)
    
    Shared.PlaySound(self, player:GetChatSound())

end<!--c2--></div><!--ec2-->

If you wonder what I changed, it is line 123, where I just have Print(message).


If you have another chat log, feel free to post it, it ought to be better than this quick fix (I havent even tried to get the players name printed aswell) ;).

Comments

  • FehaFeha Join Date: 2006-11-16 Member: 58633Members
    edited November 2010
    Ok, so I have been working a lil on this thing, and adding name and even (team) was easy. I also noticed Shaerd.Message() is better than Print().

    But when it came to make the location added to chat, I couldnt make it use right locations. What the current build do is using local player.
    But when I tried to make it find all players (to later find player by name), I only got a small table, as if I only get those I can see (understandable but annoying). And at times I didnt get any at all, not even myself!
    The code I use to get table of players is taken from Game.lua

    This is my code so far (commented away my fail code, if you think you can help, please do so ;D):
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->/*
    --
    -- Returns a table of all the entities in the world with the specified class name. Taken from Game.lua
    --/
    local function GetEntitiesWithClassname(className)

        local entities = { }
        local startEntity = nil

        repeat

            startEntity = Shared.FindEntityWithClassname(className, startEntity)

            if (startEntity ~= nil) then
                table.insert(entities, startEntity)
            end

        until (startEntity == nil)

        return entities

    end


    //So I can get players by name - By feha
    local function GetPlayerByName(playerName)
        local players = GetEntitiesWithClassname("player")
        local player
        Print("getting by name")
        //It had a tendency to not contain any player, not even the local player!
        for k,v in pairs(players) do
            Print(k)
            Print(v:GetName())
            Print(playerName)
            if (v:GetName() == playerName) then
                Print(v:GetName())
                player = v
                break
            end
        end
        
        return player
    end
    */

    /**
    * This function is called when the client receives a chat message.
    */
    function OnCommandChat(teamOnly, playerName, teamNumber, message)

        local player = Client.GetLocalPlayer()

        // color, playername, color, message        
        table.insert(chatMessages, GetColorForTeamNumber(tonumber(teamNumber)))
        
        // Pre-pend "team" or "all"
        local preMessageString = string.format("%s%s: ", ConditionalValue(tonumber(teamOnly) == 1, "(Team) ", ""), DecodeStringFromNetwork(playerName))
        
        table.insert(chatMessages, preMessageString)
        table.insert(chatMessages, kChatTextColor)
        
        // Tack on location name if any
        
        //Fixed to get location of player who actually talked and not client. Except it doesnt work for some reason. - By feha
        //THINK it fails because engine dont send all players to clients, only sends a few, but the way it determines which to send fails.
        /*local realPlayer = GetPlayerByName(DecodeStringFromNetwork(playerName))
        //Players dont exist clientside if you cant see them for some odd reason, so we must add safety checks
        local locationName
        if (realPlayer ~= nil) then
            locationName = realPlayer:GetLocationName()
        else
            locationName = "Out of Sight"
        end
        //Players that are joining doesnt seem to have a location or something similar.
        if (locationName == nil or locationName == "") then locationName = "Unknown" end
        */
        local locationName = player:GetLocationName()
        if(locationName ~= "") then
            message = string.format("%s (%s)", message, locationName)
        end
        
        table.insert(chatMessages, message)
        
        //Print chat in console. Shared.Message is better than Print, as it does not append "- Client" at the end - By Feha
        Shared.Message(string.format("%s%s", preMessageString, message))
        
        // reserved for possible texture name
        table.insert(chatMessages, "")
        // texture x
        table.insert(chatMessages, 0)
        // texture y
        table.insert(chatMessages, 0)
        // entity id
        table.insert(chatMessages, 0)
        
        Shared.PlaySound(self, player:GetChatSound())

    end<!--c2--></div><!--ec2-->

    EDIT: gnight ;)
  • devicenulldevicenull Join Date: 2003-04-30 Member: 15967Members, NS2 Playtester, Squad Five Blue
    I'm not sure why you have all that extra code, this diff is all you need:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->diff --git a/Chat.lua b/Chat.lua
    index 2dc8231..2a931a5 100644
    --- a/Chat.lua
    +++ b/Chat.lua
    @@ -118,6 +118,7 @@ function OnCommandChat(teamOnly, playerName, teamNumber, message)
         end
        
         table.insert(chatMessages, message)
    +    Shared.Message(string.format("%s %s", preMessageString, message))
        
         // reserved for possible texture name
         table.insert(chatMessages, "")<!--c2--></div><!--ec2-->

    All you need is that one line with the + in front of it
  • ObraxisObraxis Subnautica Animator & Generalist, NS2 Person Join Date: 2004-07-24 Member: 30071Super Administrators, Forum Admins, NS1 Playtester, Forum Moderators, NS2 Developer, Constellation, NS2 Playtester, Squad Five Silver, WC 2013 - Supporter, Subnautica Developer, Pistachionauts
    Along the line of Chat, it would be nice to be able to scroll through previous text like in Source.
  • FehaFeha Join Date: 2006-11-16 Member: 58633Members
    edited November 2010
    You mean a chat window with scrollbar? I could try and make a .swf for it, altough I dont think I will. Last time I tried flash for ns2 I got problems. And they use AS2, not AS3 (learnt atleast some AS3) :P.
    I also heard that the flash system will be replaced (http://www.unknownworlds.com/ns2/forums/index.php?showtopic=111339&st=20&p=1804265&#entry1804265), so it would feel stupid to make something just before it gets useless.

    EDIT:
    <!--quoteo(post=1804449:date=Nov 4 2010, 05:59 AM:name=devicenull)--><div class='quotetop'>QUOTE (devicenull @ Nov 4 2010, 05:59 AM) <a href="index.php?act=findpost&pid=1804449"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I'm not sure why you have all that extra code, this diff is all you need:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->diff --git a/Chat.lua b/Chat.lua
    index 2dc8231..2a931a5 100644
    --- a/Chat.lua
    +++ b/Chat.lua
    @@ -118,6 +118,7 @@ function OnCommandChat(teamOnly, playerName, teamNumber, message)
         end
        
         table.insert(chatMessages, message)
    +    Shared.Message(string.format("%s %s", preMessageString, message))
        
         // reserved for possible texture name
         table.insert(chatMessages, "")<!--c2--></div><!--ec2-->

    All you need is that one line with the + in front of it<!--QuoteEnd--></div><!--QuoteEEnd-->

    The other code is because message contains location for localplayer, no matter who talks. I found it annoying and tried to fix, but failed (reason it is all commented away). Posted it anyway incase someone could see why it fails. I Also changed the first line of that function aswell (player is a local var in my version), so 2 lines XD.

    But why doesnt Shared.FindEntityWithClassname(className, nil) always give an entity? I could understand if it didnt include those you cant see (even thought that would be plain stupid, its understandable as ns2 is meant for competitive gameplay), but the local player should atleast always be included!
  • fsfodfsfod uk Join Date: 2004-04-09 Member: 27810Members, NS2 Developer, Constellation, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    On the talk of a flash chat interface, i've done quick port of one i made for the engine test it has mostly working chat history scrolling <a href="http://www.fsfod.vivaciti.net/files/chat.zip" target="_blank">chat.zip</a>
    To use it create folder called "flashchat" in the Natural Selection 2 directory and extract the contents of the zip there.
    Then create a shortcut to ns2.exe open it properties add " -game flashchat" without the quotes to the end of the target path.

    Theres some tweakable values at the top of newchat.lua like the size and position of the chat frame and text fade delay

    Feha your free to improve on if you want the fla files are included in the zip, idk if will be worth the time it depends if there new chat interface in the next build will lack history scrolling
  • SgtBarlowSgtBarlow Level Designer Join Date: 2003-11-13 Member: 22749Members, NS2 Developer
    I too would like to see chat in console, I keep bringing it up cause I missed something only to remember its not dumped there.

    I have asked if it could be made a recent side task to impliment it while the front end for this is actually being worked on porting from flash to their own Hud.
Sign In or Register to comment.