Language Addition [by ?]
Snippet Posted Wednesday, August 12th @ 11:29:43 PM, by George Greer in the Utils dept.
. Click the link below to read it or download it.

                                 LANGUAGE CODE

Some notes: I use skill slots to hold language ability, this coincides
very nicely with my learn_by_use code (stripped out of this example).
If you try to use this, you'll need to make the appropriate entries in
spells.h (I use 190+ for langs), also, you'll need to change one of
the spares in the player structure to be "speaking".

Oh, you'll also need some way to toggle what language you're speaking,
you could use a simple do_speak command or something, I'm not finished
putting this all in yet, so I just made an entry in do_set to toggle
the person's current lang like: SPEAKING(vict) = value

Take note that it might also be a good idea to set the characters'
native language to 100% when they begin.

spells.h

#define LANG_COMMON     190
#define LANG_ELVEN      191
#define LANG_DWARVEN    192
#define LANG_TROLLISH   193
#define LANG_HALFLING   194

utils.h

#define SPEAKING(ch)     ((ch)->player_specials->saved.speaking)

constants.c

const char *languages[] =
{
  "common",
  "elven",
  "dwarven",
  "trollish",
  "halfling",
  "\n"
};

act.comm.c

void garble_text(char *string, int percent)
{
  char letters[] = "aeiousthpwxyz";
  int i;

  for (i = 0; i < strlen(string); ++i)
    if (isalpha(string[i]) && number(0, 1) && number(0, 100) > percent)
      string[i] = letters[number(0, 12)];
}


ACMD(do_lang_say)
{
  extern char *languages[];
  char ibuf[MAX_INPUT_LENGTH];
  char obuf[MAX_INPUT_LENGTH];
  int ofs = 190;              /* offset - should be first language */
  struct char_data *tch;

  skip_spaces(&argument);

  if(!*argument) {
    send_to_char("Say what?\r\n", ch);
    return;
  }

  strcpy(ibuf, argument);     /* preserve original text */

  garble_text(ibuf, GET_SKILL(ch, SPEAKING(ch)));

  for (tch = world[ch->in_room].people; tch; tch = tch->next_in_room) {
    if (tch != ch && AWAKE(tch) && tch->desc) {

      strcpy(obuf, ibuf);     /* preserve the first garble */

      garble_text(obuf, GET_SKILL(tch, SPEAKING(ch)));

      if (GET_SKILL(tch, SPEAKING(ch)) < 1)
        sprintf(buf, "$n says, in an unfamiliar tongue,\r\n     '%s'",  obuf);
      else
        sprintf(buf, "$n says, in the %s tongue,\r\n     '%s'", languages[(SPEA
KING(ch) - ofs)], obuf);
      act(buf, TRUE, ch, 0, tch, TO_VICT);
    }
  }

  sprintf(buf, "You say, in the %s tongue,\r\n     '%s'", languages[(SPEAKING(c
h)- ofs)], argument);
  act(buf, TRUE, ch, 0, 0, TO_CHAR);

}

One funky thing I see here, is that it appears that the garbled text
changes each time. For example, if I say the words "Hello there Sparky,
you're a dead man!" six times, anyone not speaking my language should see
the same string six times, not 6 different ones. I got around this by
assigning each language an index (Say like 5 10 15 20), and in the garble
text routine, I adjust the ascii value of the character by the index. If
I overrun the range of printable characters, I just wrap around. The
result is that the exact same string appears each time the speaker says
the same phrase. One major benefit of this is that it allows a player to
"learn" and recognize certain phrases in foreign tongues, just as in real
life. Therefore players of different races can have at least minimal
verbal interaction. Of course you can also do an:

   > emote says: Hi There!

... But that's not my problem to solve.


<< It reference for objects [by Gary Barnett] | Reply | View as text | Threaded | Language Addition [by Frollo] >>

 


Related Links
  download
Related Articles
More by greerga
 
 

CircleMUD Snippets
 
Note: Not all of these snippets will work perfectly with your version of code, so be prepared to fix one or two bugs that may arise, and please let me know what you needed to do to fix it. Sending a corrected version is always welcome.
Finally, if you wish to use any of the snippets from this page, you are more than welcome, just mention the authors in your credits. If you wish to release any of these snippets to the public on another site, contact me FIRST.