Chat Colors

Posted By: ISG

Chat Colors - 07/25/06 12:47

I've recently adapted Locoweeds chat script to my MP game (online not LAN). I was wondering if anyone had any idea how to make YOUR text YOU type one color, and the clients (or other players) that type on your screen another color. Code is below:

Code:

bmap pcxChat = <Chat.pcx>; // Chat Panel

// Chat strings
string strChat0[100]; // Chat entries
string strChat1[100];
string strChat2[100];
string strChat3[100];
string strChat4[100];
string strChat5[100];
string strChat6[100];
string strChat7[100];
string strChat8[100];
string strChatEntry[80]; // current chat entry
string strSendChat[100]; // chat to send

// text for chat panel
text txtChat
{
pos_x = 2;
pos_y = 0;
layer = 30;
font _a4font;
strings = 9;
string = strChat0, strChat1, strChat2, strChat3, strChat4,
strChat5, strChat6, strChat7, strChat8;
}

// text for chat entry
text txtChatEntry
{
pos_x = 2;
pos_y = 0;
layer = 30;
font _a4font;
string strChatEntry;
}

// chat panel
panel pnlChat
{
bmap = pcxChat;
layer = 18;
pos_x = 0;
pos_y = 0;
flags = overlay,transparent,refresh;
}

// Call this in your main function,..
function init_chat()
{
// if host or client set up chat
if (connection == 2 || connection == 3)
{
pnlChat.pos_y = screen_size.y - 100;
txtChat.pos_y = screen_size.y - 100;
txtChatEntry.pos_y = screen_size.y - 15;
pnlChat.visible = ON;
txtChat.visible = ON;
txtChatEntry.visible = OFF;
}
}

function chat_entry()
{
// if host or client
if (connection == 2 || connection == 3)
{
// if inkey already open return
if (inkey_active == 1) { return; }

txtChatEntry.visible = ON;
inkey(strChatEntry); // get chat entry

// if entry was empty don't process
if(str_cmp(strChatEntry,"")) { return; }

txtChatEntry.visible = OFF;

str_cpy(strSendChat,player_name); // put players name before entry
str_cat(strSendChat,": ");
str_cat(strSendChat,strChatEntry);

// if Host go ahead and do chat manipulation
if (connection == 3)
{
send_string(strSendChat);
str_cpy(strChat0, strChat1);
str_cpy(strChat1, strChat2);
str_cpy(strChat2, strChat3);
str_cpy(strChat3, strChat4);
str_cpy(strChat4, strChat5);
str_cpy(strChat5, strChat6);
str_cpy(strChat6, strChat7);
str_cpy(strChat7, strChat8);
str_cpy(strChat8, strSendChat);
str_cpy(strSendChat,"");
}
else // if client send entry to server for processing
{
send_string(strSendChat);
}

str_cpy(strSendChat,""); // clear the strings for client and
str_cpy(strChatEntry,""); // server called functions
}
}

//--------------------------------------------------------------------
// Function Server_Called(): server was called
//--------------------------------------------------------------------

function server_called()
{
// chat stuff
if (event_type == event_string)
{
if (!str_cmp(strSendChat,""))
{
ifdef server;

send_string(strSendChat); // send string to clients
str_cpy(strChat0, strChat1); // move old chat entries up 1
str_cpy(strChat1, strChat2);
str_cpy(strChat2, strChat3);
str_cpy(strChat3, strChat4);
str_cpy(strChat4, strChat5);
str_cpy(strChat5, strChat6);
str_cpy(strChat6, strChat7);
str_cpy(strChat7, strChat8);
str_cpy(strChat8, strSendChat);
str_cpy(strSendChat,"");

endif;
}
}
}

//--------------------------------------------------------------------
// Function Client_Called(): client was called
//--------------------------------------------------------------------

function client_called()
{
// string event
if (event_type == event_string)
{
// chat entry sent from server, process
if (!str_cmp(strSendChat,""))
{
str_cpy(strChat0, strChat1); // move old chat entries up 1
str_cpy(strChat1, strChat2);
str_cpy(strChat2, strChat3);
str_cpy(strChat3, strChat4);
str_cpy(strChat4, strChat5);
str_cpy(strChat5, strChat6);
str_cpy(strChat6, strChat7);
str_cpy(strChat7, strChat8);
str_cpy(strChat8, strSendChat);
str_cpy(strSendChat,"");
}
}
}

on_server = server_called; // on server event, call server_called()
on_client = client_called; // on client event, call client_called()
on_enter = chat_entry; // on <enter> start chat entry


Posted By: Dutchie666

Re: Chat Colors - 07/25/06 12:51

how i am doing that is with draw_text.
just make a loop somewhere wich just acts like the text panels but than just writes it on the screen. en you can do with a check who has send a message if you are that guy and than change the color...
i think that that is the best way to do it.
Posted By: FoxHound

Re: Chat Colors - 07/26/06 01:39

One idea I have is to have 10 different panels for each line of the chat window, When you update the strings, also update an array which holds which color the font is, at which point update the font in each of those panels.

I'm not sure if that will work, but it's an idea.
Posted By: D3D

Re: Chat Colors - 09/05/06 00:19

I like this idea because it looks more flexible with draw_text:

Code:
draw_text("Test!",100,10,vector(100,100,255)); // red text



All the best,

Dusty
Posted By: Captain_Kiyaku

Re: Chat Colors - 09/05/06 06:41

yeah it would work with draw_text. hmm i should try that too. in my chat system, i use one color for all persons, then one color for system messages, and one color for picking up something, etc. but i defined new strings all the time so it really sucks.
Posted By: FoxHound

Re: Chat Colors - 09/05/06 17:10

Remeber that you can't change the font with draw_text, it is Arial 20 bold, to change the font you need "draw_textmode" and it is a slow instrunction.
Posted By: D3D

Re: Chat Colors - 09/06/06 03:11

Slow is not good for multiplayer games played over the internet. So if copy & paste and using 10 different panels would be faster, that route should be better. I'll try both.

All the best,

Dusty
Posted By: Michael_Schwarz

Re: Chat Colors - 09/06/06 12:24

the draw_textmode instuction is only executed locally and has no influence on the online expereience, the way you can use it without any problems in multiplayer games
Posted By: sheefo

Re: Chat Colors - 09/06/06 18:08

You don't need 'draw_textmode' to change the colour of the text. It's done in the last argument of 'draw_text'.
Posted By: D3D

Re: Chat Colors - 09/07/06 03:38

Sheefo I guess Michael responded to my reply on what FoxHound said:

Quote:

Remeber that you can't change the font with draw_text, it is Arial 20 bold, to change the font you need "draw_textmode" and it is a slow instruction.





So you are right Sheefo, about draw_mode not needed to change the font color. This is done in the last argument of the draw_text instruction. but, the standard font type is arial. To be able to change that. You need draw_mode, which is told to be slow and therefore not recommended.

However Michael said it doesn't influence the online gameplay, because the draw_mode instruction is only executed locally.

Dusty
Posted By: Michael_Schwarz

Re: Chat Colors - 09/07/06 12:28

first time someone defends something I said, yay
Posted By: sheefo

Re: Chat Colors - 09/09/06 11:24

I was just saying that you don't need 'draw_textmode' to change the colour. Thats what you wanted, to change the colour, so why do you need 'draw_textmode'? If you want 'draw_textmode' in multiplayer you can define it once to set the font, it's not needed in a loop which will slow down multiplayer which you were worried about.

Who cares anyway. Have you got it working by the way?
© 2024 lite-C Forums