function str_makeempty(var signcounter) //Empty the chat_in and fill it with a given number of spaces
{
str_cpy(chat_in, "");
while(signcounter > 0)
{
str_cat(chat_in, " ");
signcounter -= 1;
}
}
function wo_makeempty(var signcounter) //Empty the write_over and fill it with a given number of spaces
{
str_cpy(write_over, "");
while(signcounter > 0)
{
str_cat(write_over, " ");
signcounter -= 1;
}
}
void check_chathigh() // Check the high of the chat, and delete the upper rows if it is to high.
{
while(chat_check != 0)
{
if(chatpattern.pos_y < max_high)
{
delete_pos = str_stri(chatlog,"\n");
if(delete_pos)
{
str_clip(chatlog,delete_pos);
chatpattern.pos_y = max_high;
}
}
chat_check -= 1;
}
chat_check = 0;
}
void write_in() // Write received strings into the shown chatlog
{
if(str_cmpi(write_login, "") == 0) // write if a client has entered
{
str_cat(chatlog, write_login);
str_cat(chatlog, "\n");
str_cpy(write_login, "");
}
if(str_cmpi(chat_sav, "") == 0) // write messages
{
str_cat(chatlog, chat_sav);
str_cat(chatlog, "\n");
str_cpy(chat_sav, "");
}
}
function start_chatsystem()
{
// create login text
str_cat(write_login, spielername);
str_cat(write_login, " hat das Spiel betreten..! \n");
enet_send_string("write_login", BROADCAST);
// create variables and strings
chatpattern.pos_y = screen_size.y - 84;
chatwrite.pos_y = screen_size.y - 18;
set(chatpattern, SHOW);
set(chatwrite, SHOW);
str_cpy(write_over, "< ");
str_cat(write_over, spielername);
str_cat(write_over, " >");
str_cat(write_over, ": ");
str_cpy(write_name, write_over);
chatstart = 0;
line_len = 0;
delete_pos = 0;
max_high = screen_size.y - 192;
paragraph_len = str_len(write_over);
max_len = 100 - paragraph_len;
wait(1);
str_makeempty(max_len);
wo_makeempty(paragraph_len);
while(1)
{
write_in();
if(chatstart == 0 && inkey_active == 0 && key_m == 1)
{
inkey(chat_in);
chatstart = 1;
}
else if(chatstart == 1 && inkey_active == 0)
{
str_cpy(chat_out, chat_in);
line_len = str_len(chat_in);
if(str_cmpi(chat_in, "\w ")) //====================================== WHISPER Chat
{
// Not implemented yet
error("geflüstert!");
}
else //====================================== PUBLIC Chat
{
if(line_len > 50) // if the text has more than 50 signs
{
line_len -= 50; // cutout the first 50 signs and send them.
str_trunc(chat_in, line_len);
str_cat(chat_sav, write_name);
str_cat(chat_sav, chat_in);
enet_send_string("chat_sav", BROADCAST);
enet_send_var("chat_check", BROADCAST);
write_in();
wait(4);
str_cpy(chat_sav, ""); // cutout the last signs and send them.
str_cpy(chat_in, chat_out);
str_clip(chat_in,50);
str_cat(chat_sav, write_over);
str_cat(chat_sav, chat_in);
chat_check = 2;
enet_send_string("chat_sav", BROADCAST);
enet_send_var("chat_check", BROADCAST);
write_in();
wait(4);
}
else // 1 Line of text (less than 50 signs)
{
str_cat(chat_sav, write_name);
str_cat(chat_sav, chat_in);
wait(4);
chat_check = 1;
enet_send_string("chat_sav", BROADCAST);
enet_send_var("chat_check", BROADCAST);
write_in();
wait(4);
}
str_makeempty(100 - paragraph_len); // empty the chat_in string
str_cpy(chat_out, "");
}
chatstart = 0;
}
if(chat_check == 1)
{
chatpattern.pos_y -= 16;
check_chathigh();
}
else if(chat_check == 2)
{
chatpattern.pos_y -= 32;
check_chathigh();
}
wait(1);
}
}
function start_spieler(var conect_type) // Let the player type in his Name
{
namewrite.pos_x = (screen_size.x / 2) - 160;
namewrite.pos_y = (screen_size.y / 2) - 32;
textbitmaps.pos_x = namewrite.pos_x-20;
textbitmaps.pos_y = namewrite.pos_y-24;
set(namewrite, SHOW);
set(textbitmaps, SHOW);
inkey(spielername);
while(inkey_active == 1){wait(1);}
reset(namewrite, SHOW);
reset(textbitmaps, SHOW);
namewrite.pos_x = -5000;
textbitmaps.pos_x = -5000;
wait(2);
if(conect_type == 2)
{
enet_set_playername(spielername);
}
wait(2);
start_chatsystem();
}