Sonmez

  • Jr. Member
  • Yo! It's time to play the fair game!
  • Posts: 63
Sonmez's New Chat System
«  »Last edited
As most of us know, the original chat in vcmp only supports English letters. So, I have created this custom chat system in order to use Turkish letters. It is also possible to bring support for different languages ​​by changing the font file.   

SERVER SIDE
Code: [Select]
function onClientScriptData( player ) {
  local int=Stream.ReadInt(), str=Stream.ReadString();
  local aColour = player.Colour, pcolor = format("[#%02X%02X%02X]", aColour.r, aColour.g, aColour.b);
  if(int==2022){for(local i = 0; i<100; i++){SendDataToClient(i, 2022, pcolor.tolower()+player.Name+": [#ffffff]"+str);}}
}

function SendDataToClient(p,i,s){
  p=FindPlayer(p);
  if(p){
    Stream.StartWrite();Stream.WriteInt(i);
  }
  if(s!=null){
    Stream.WriteString(s);
  }
  Stream.SendStream(p);
}


CLIENT SIDE
Code: [Select]
// =================== Credits Goes To ysc3839 for Client Timer ==============================
function Script::ScriptProcess(){
  Timer.Process();
}

Timer <- {
 Timers = {}

 function Create(environment, listener, interval, repeat, ...)
 {
  // Prepare the arguments pack
  vargv.insert(0, environment);

  // Store timer information into a table
  local TimerInfo = {
   Environment = environment,
   Listener = listener,
   Interval = interval,
   Repeat = repeat,
   Args = vargv,
   LastCall = Script.GetTicks(),
   CallCount = 0
  };

  local hash = split(TimerInfo.tostring(), ":")[1].slice(3, -1).tointeger(16);

  // Store the timer information
  Timers.rawset(hash, TimerInfo);

  // Return the hash that identifies this timer
  return hash;
 }

 function Destroy(hash)
 {
  // See if the specified timer exists
  if (Timers.rawin(hash))
  {
   // Remove the timer information
   Timers.rawdelete(hash);
  }
 }

 function Exists(hash)
 {
  // See if the specified timer exists
  return Timers.rawin(hash);
 }

 function Fetch(hash)
 {
  // Return the timer information
  return Timers.rawget(hash);
 }

 function Clear()
 {
  // Clear existing timers
  Timers.clear();
 }

 function Process()
 {
  local CurrTime = Script.GetTicks();
  foreach (hash, tm in Timers)
  {
   if (tm != null)
   {
    if (CurrTime - tm.LastCall >= tm.Interval)
    {
     tm.CallCount++;
     tm.LastCall = CurrTime;

     tm.Listener.pacall(tm.Args);

     if (tm.Repeat != 0 && tm.CallCount >= tm.Repeat)
      Timers.rawdelete(hash);
    }
   }
  }
 }
};

// ============================================================================================

local sX = GUI.GetScreenSize().X,sY = GUI.GetScreenSize().Y;
chatbox <-{Box = null EditBox = null}

function Script::ScriptLoad(){
  createChatBox();
}

function Server::ServerData( stream ){
 local readint=stream.ReadInt( ),readstr=stream.ReadString( );
 switch(readint.tointeger()){
  case 2022: chatProcess(readstr); break;
 }
}

function GUI::InputReturn( editbox ){
  if (editbox == chatbox.EditBox){
      if (chatbox.EditBox.Text == "" || chatbox.EditBox.Text == " " || chatbox.EditBox.Text == " " ){
        chatbox.EditBox = null;
      }else{
        if (chatbox.EditBox.Text.len() < 97){
          SendDataToServer(chatbox.EditBox.Text, 2022);
        }chatbox.EditBox = null;
      }         
  }
}

chat_key <- KeyBind( 0x59 );
function KeyBind::OnDown(key){
  if (key == chat_key){
    if(!chatbox.EditBox){
      createChatEditBox();
    }
  }
}

function VScreen(pos_x, pos_y){//Credits goes to Doom_Kill3R for this function
 local
     screenSize = GUI.GetScreenSize( ),
     x = floor( pos_x * screenSize.X / 1920 ),
     y = floor( pos_y * screenSize.Y / 1080 );
  return VectorScreen( x, y );
}
function SendDataToServer(s, i){local msg=Stream();msg.WriteInt(i.tointeger());msg.WriteString(s);Server.SendData(msg);}


function createChatBox(){
  chatbox.Box = GUIMemobox(VScreen( 10 , 25 ), VScreen(1000, 400), Colour(0, 0, 0, 255), GUI_FLAG_MEMOBOX_TOPBOTTOM | GUI_FLAG_VISIBLE | GUI_FLAG_TEXT_TAGS);
  chatbox.Box.RemoveFlags( GUI_FLAG_BACKGROUND | GUI_FLAG_BORDER );
  chatbox.Box.FontSize = floor( 17 * GUI.GetScreenSize( ).Y / 1080 );
  chatbox.Box.FontName = "TR Tahoma Bold"
  chatbox.Box.FontFlags = GUI_FFLAG_OUTLINE;
  chatbox.Box.LineHeight = 0;
}

function createChatEditBox(){
    chatbox.EditBox = GUIEditbox(VScreen( 15, 370 ), VScreen( 900, 30 ), Colour(0, 0, 0, 255), GUI_FLAG_TEXT_TAGS);
    chatbox.EditBox.FontSize = floor( 17 * GUI.GetScreenSize( ).Y / 1080 );
    chatbox.EditBox.TextColour = Colour(255, 255, 255, 255);
    chatbox.EditBox.FontName = "TR Tahoma Bold"
    chatbox.EditBox.FontFlags = GUI_FFLAG_OUTLINE;
    chatbox.EditBox.RemoveFlags( GUI_FLAG_BACKGROUND | GUI_FLAG_BORDER );
chatbox.EditBox.Text = "";
chatboxTimer <- Timer.Create(this, function(text, int) {
      chatbox.EditBox.Text = "";
  GUI.SetFocusedElement( chatbox.EditBox );
    }, 45, 1, "Timer Text ", 12345);
}
chatTimer <- null;
maxChatLine <- 15;
function chatProcess(readstr){
  if (chatbox.Box.LineHeight == 0){chatbox.Box.LineHeight = 1;}
    chatbox.Box.AddLine(readstr, Colour(255, 255, 255, 255))
    if(chatbox.Box.LineHeight < maxChatLine ){
      chatbox.Box.LineHeight += 1;
    }
    chatTimerProcess();
}

function chatTimerProcess(){
    Timer.Destroy( chatTimer );
    chatTimer <- Timer.Create(this, function(text, int) {
    if (chatbox.Box.LineHeight > 0 ){
      chatbox.Box.LineHeight -=1;
    }
    chatbox.Box.DisplayPos = 0;
 }, 10000, 0, "Timer Text ", 12345);
}


You need add fonts folder to store.


New Chat Key Is -> "Y"

Preview:


Good luck...
if (!perfect) createAgain();

habi

  • Sr. Member
  • Posts: 362
Re: Sonmez's New Chat System
« Reply #1,  »
You didn't tell in your post which key to press so chatbox come. I had to look at the codes = It is 'Y' key.

Now where to place the fonts folder? Inside store/scripts?

I managed to take two screenshots.





As you can see (i don't know if it is because i placed fonts folder rightly or not) the letters are too small.

Again, i 'copy' a chinese character from google and paste into this chatbox, will it work? Or do i need chinese keyboard?

Thanks

Sonmez

  • Jr. Member
  • Yo! It's time to play the fair game!
  • Posts: 63
Re: Sonmez's New Chat System
« Reply #2,  »
It seems you did not place the Font folder correctly thats why the letters are small. True location is store folder. It should have been "store/fonts". Also you can find "floor( 17 * GUI.GetScreenSize( ).Y / 1080 );" this code in 2 places of code. You can change "17" with any other value in order to change your font size.

I haven't tested it with Chinese characters, but it is necessary to add a Chinese font, and change "TR Tahoma Bold" with the font which contains Chinese letters. Each key contains a keycode. If the keycodes supported by vcmp are limited, we can support those keys which are not supported ​​with manually configuring the fonts by changing keycodes.
if (!perfect) createAgain();

habi

  • Sr. Member
  • Posts: 362
Re: Sonmez's New Chat System
« Reply #3,  »
I had pasted it in wrong folder store/scripts/fonts

I am busy with something. I will certainly look into this.

Sebastian

  • VC:MP Beta Tester
  • Something like this: hga hga hga
  • Posts: 1,184
Re: Sonmez's New Chat System
« Reply #4,  »Last edited
Is it the same with the one from your server? :o
I remember it was a perfect alternative. Too bad we cannot actually force stop the default chat to open.


EDIT: Here is a video recorded when were testing it :D back in 2021-01-04-1256

https://youtu.be/bQRcEiZ9E2o

MRSK143

  • Jr. Member
  • Posts: 65
Re: Sonmez's New Chat System
« Reply #5,  »
Hey sonmez, how you have disabled the old chat box? i mean there wasn't showing any text of old box

Sonmez

  • Jr. Member
  • Yo! It's time to play the fair game!
  • Posts: 63
Re: Sonmez's New Chat System
« Reply #6,  »
Quote from Sebastian on May 14th, 07:15 AM
Is it the same with the one from your server? :o
I remember it was a perfect alternative. Too bad we cannot actually force stop the default chat to open.


EDIT: Here is a video recorded when were testing it :D back in 2021-01-04-1256

https://youtu.be/bQRcEiZ9E2o
Hi Sebastian, it's been a long time I hope you're fine, and yes this chatbox is almost the same but unfortunately I lost my old files, and I had to reproduced them.
Re: Sonmez's New Chat System
« Reply #7,  »
Quote from MRSK143 on May 16th, 12:20 PM
Hey sonmez, how you have disabled the old chat box? i mean there wasn't showing any text of old box
There is no method to prevent the default chat to open but you can add return false; in onPlayerChat() in order to disable this function.
if (!perfect) createAgain();

Halilibow

  • Newbie
  • Are you ready to hit the road with the M4?
  • Posts: 5
Tokta Gamer