Author Topic: Client Sise- chat functions.  (Read 1450 times)

Client sends chat message to server
Server relays chat message to clients
Client receives chat message and outputs in in chat.

What function handles input of chat messages from server. Eg "Client receives chat message and outputs in in chat."

There are a couple you can use.
A lot of people use newchathud_addline(%text) because it doesn't have other arguments that you need to deal with.
Other alternatives are clientcmdchatmessage() which has like a bajillion arguments that I'm not really familiar with, but the one that is printed to chat is the fourth one.
Also there is onChatMessage(%message, %something1, %something2) which is probably your best bet if you just want to know when someone says something.



There is also clientCmdServerMessage. I think it handles every line to chat but I'm not sure. clientCmdChatMessage() only handles chat from players, not from the server. clientCmdServerMessage can be finnicky though.

There are a couple you can use.
A lot of people use newchathud_addline(%text) because it doesn't have other arguments that you need to deal with.
Other alternatives are clientcmdchatmessage() which has like a bajillion arguments that I'm not really familiar with, but the one that is printed to chat is the fourth one.
Also there is onChatMessage(%message, %something1, %something2) which is probably your best bet if you just want to know when someone says something.

function clientCmdChatMessage(%sender, %voice, %pitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
{
   onChatMessage(detag(%message), %voice, %pitch);
}

function onChatMessage(%message, %voice, %pitch)
{
  if (strlen(%message) > 0)
    newChatHud_AddLine(%message);
}

Can someone finally explain what the point of "voice" and "pitch" is?

Can someone finally explain what the point of "voice" and "pitch" is?

From the TGE racing example:

// Only play sound files that are <= 5000ms in length.
$MaxMessageWavLength = 5000;

// Helper function to play a sound file if the message indicates.
// Returns starting position of wave file indicator.
function playMessageSound(%message, %voice, %pitch)
{
   // Search for wav tag marker.
   %wavStart = strstr(%message, "~w");
   if (%wavStart == -1) {
      return -1;
   }

   %wav = getSubStr(%message, %wavStart + 2, 1000);
   if (%voice !$= "") {
      %wavFile = "~/data/sound/voice/" @ %voice @ "/" @ %wav;
   }
   else {
      %wavFile = "~/data/sound/" @ %wav;
   }
   if (strstr(%wavFile, ".wav") != (strlen(%wavFile) - 4)) {
      %wavFile = %wavFile @ ".wav";
   }
   // XXX This only expands to a single filepath, of course; it
   // would be nice to support checking in each mod path if we
   // have multiple mods active.
   %wavFile = ExpandFilename(%wavFile);

   if ((%pitch < 0.5) || (%pitch > 2.0)) {
      %pitch = 1.0;
   }

   %wavLengthMS = alxGetWaveLen(%wavFile) * %pitch;
   if (%wavLengthMS == 0) {
      error("** WAV file \"" @ %wavFile @ "\" is nonexistent or sound is zero-length **");
   }
   else if (%wavLengthMS <= $MaxMessageWavLength) {
      if ($ClientChatHandle[%sender] != 0) {
         alxStop($ClientChatHandle[%sender]);
      }
      $ClientChatHandle[%sender] = alxCreateSource(AudioMessage, %wavFile);
      if (%pitch != 1.0) {
         alxSourcef($ClientChatHandle[%sender], "AL_PITCH", %pitch);
      }
      alxPlay($ClientChatHandle[%sender]);
   }
   else {
      error("** WAV file \"" @ %wavFile @ "\" is too long **");
   }

   return %wavStart;
}

function onChatMessage(%message, %voice, %pitch)
{
   // XXX Client objects on the server must have voiceTag and voicePitch
   // fields for values to be passed in for %voice and %pitch... in
   // this example mod, they don't have those fields.

   // Clients are not allowed to trigger general game sounds with their
   // chat messages... a voice directory MUST be specified.
   if (%voice $= "") {
      %voice = "default";
   }

   // See if there's a sound at the end of the message, and play it.
   if ((%wavStart = playMessageSound(%message, %voice, %pitch)) != -1) {
      // Remove the sound marker from the end of the message.
      %message = getSubStr(%message, 0, %wavStart);
   }

   // Chat goes to the chat HUD.
   if (getWordCount(%message)) {
      ChatHud.addLine(%message);
   }
}


Plays sound files. This functionality is not present in Blockland.
« Last Edit: April 11, 2014, 06:45:33 AM by Port »

Plays sound files. This functionality is not present in Blockland.
If they do basically nothing, why not call them %blah1 and %blah2 so people don't get the impression they are useful?

If they do basically nothing, why not call them %blah1 and %blah2 so people don't get the impression they are useful?

Is renaming them to confusing things that people are going to spend time trying to figure out what means more helpful?

Is renaming them to confusing things that people are going to spend time trying to figure out what means more helpful?
Call them %empty1 and %empty2?