This snippet will add race/skill based languages to your mud. If a player speaks a language at 60%, then only UP TO 60% of what they said will be sent, and if the listener only speaks the language at 30%, then only (UP TO) 30% of the 60% that was sent will be understood by the listener. Creates a realistic language barrier :-) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!! PLEASE READ OVER THIS WHOLE FILE BEFORE YOU BEGIN !!! !!! BACK UP YOUR CODE BEFORE ATTEMPTING TO ADD !!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! A few notes on this snippet: * The code is commented thru-out so you can see what is going on, and change any factor that is not working/you don't like * It was designed to work on a modified ROM, although this should work in stock rom perfectly. * The language names and race names are easy to change, simply substitue the word when it appears in the code, i.e. if you want dwarvish to be something else, find every mention of the word 'dwarvish' in this code and change it to what you want. Make sure if you are changing things around to modify the nanny.c (or your creation code, wherever it may be) code to reflect your changes. i.e. You want dwarves to create being able to speak dwarvish at 100% from the get-go... * In this version, players can use practices to improve on language, or improve by speaking or hearing it. In a future version, I plan on limiting language improvement to prevent practices being used. Its an idea you may want to consider, the only reason it isn't in this version is that I can't decide. * I use the " - " character as the shortcut for the command 'translate' as say uses the shortcut " ' ". If the " - " key is used for something else, be sure to change this to what you need. * Please leave the credits on the file. Thats all I ask for credit :-) * This snippet should be fairly easy to install, just follow the directions *carefully*, and READ OVER THE CODE FIRST (thats BEFORE you drop it in) in case anything on your server is so different that it may cause problems. All INSTUCTIONS are preceded by ##, everything else goes in the code. ********************************************************************** **** ACT_COMM.C ******************************************* ********************************************************************* ## at the top, right under the #include statements, add the following code: /* Language code by Forridean - Local Functions */ char *translation_parser args ((char *text , int spk_skill)); void improve_lang args ((CHAR_DATA *ch, char *language)); char *translation_parser (char *text, int spk_skill) { char buf[MAX_INPUT_LENGTH]; char spc[2]; char arg[MAX_INPUT_LENGTH]; int count; int chance; int skill_mod; if (spk_skill > 95) return text; sprintf(buf, " "); sprintf(spc, " "); count = count_args(text); skill_mod = (spk_skill * .01) * count; while (count_args(text) > 0) { text = one_argument(text, arg); chance = number_range (1, 2); if (chance == 2 && skill_mod != 0) { skill_mod -= 1; strcat(buf, arg); strcat(buf, spc); } } sprintf(text, "%s", buf); return text; } void improve_lang (CHAR_DATA *ch, char *language) { if (!str_cmp(language, "elvish")) { check_improve (ch, gsn_elvish, TRUE, 1); } else if (!str_prefix(language, "dwarvish")) { check_improve (ch, gsn_dwarvish, TRUE, 1); } else if (!str_prefix(language, "common")) { check_improve (ch, gsn_common, TRUE, 1); } } /* [ END OF CODE ] */ ********************************************************************* ## find do_say, and replace it with the following code: /* [ Language Code by Forridean ] */ void do_say (CHAR_DATA * ch, char *argument) { CHAR_DATA *vch; CHAR_DATA *vch_next; char full_argument[MAX_STRING_LENGTH]; char *parsed; char spk_language[MAX_STRING_LENGTH]; char skill_desc[MAX_STRING_LENGTH]; int oSkill; int pSkill; oSkill = 0; pSkill = 0; if (argument[0] == '\0') { send_to_char ("Say what?\n\r", ch); return; } sprintf(spk_language, "%s", ch->pcdata->language); pSkill = get_skill (ch, skill_lookup(spk_language)); sprintf(full_argument, "%s", argument); sprintf(skill_desc, "perfect"); /* cycle thru listeners, and establish what they see based on their skill in the language being spoken, then send it to them */ for (vch = char_list; vch != NULL; vch = vch_next) { vch_next = vch->next; if (vch->in_room == NULL) continue; if (vch->in_room == ch->in_room) { if (vch == ch) continue; oSkill = get_skill (vch, skill_lookup(spk_language)); parsed = translation_parser(argument, oSkill); if (!str_cmp(parsed, " ")) { printf_to_char(vch,"%s speaks in a strange tounge, and you do not understand a single word.{x\n\r",ch->name); improve_lang(vch, spk_language); continue; } printf_to_char(vch,"%s speaks in %s %s. You understand the words '{7%s{6{x'\n\r", ch->name, skill_desc, spk_language, parsed); improve_lang(vch, spk_language); continue; } continue; } /* send it to the speaker */ printf_to_char(ch, "You speak in %s, '{7%s{6{x'\n\r", spk_language, full_argument); return; } void do_translate (CHAR_DATA * ch, char *argument) { CHAR_DATA *vch; CHAR_DATA *vch_next; char full_argument[MAX_STRING_LENGTH]; char arg1[MAX_STRING_LENGTH]; char *parsed; char spk_language[MAX_STRING_LENGTH]; char skill_desc[MAX_STRING_LENGTH]; int oSkill; int pSkill; oSkill = 0; pSkill = 0; if (argument[0] == '\0') { send_to_char ("Say what in what language?\n\r", ch); send_to_char ("Syntax: translate [language] [text]\n\r", ch); return; } /* what language do they want? */ argument = one_argument(argument, arg1); if (!str_prefix(arg1, "dwarvish")) { sprintf(spk_language, "dwarvish"); } else if (!str_prefix(arg1, "elfish")) { sprintf(spk_language, "elfish"); } else if (!str_prefix(arg1, "common")) { sprintf(spk_language, "common"); } else { printf_to_char(ch, "No such language.\n\r"); return; } /* now that we know the language, are there any more arguments? */ if (argument[0] == '\0') { printf_to_char(ch, "What do you want to try and say in %s?\n\r", spk_language); return; } /* Check out the speaker's skill, and parse the text accordingly. We keep the full argument in full_argument for later use (if you have mob triggers for speech, pass the full_argument to them so you don't have to screw with checking mob's skills in the given language) */ pSkill = get_skill (ch, skill_lookup(spk_language)); sprintf(full_argument, "%s", argument); argument = translation_parser(argument, pSkill); /* now we set up the adjectives for the speaker's skill */ if (pSkill == 1) { sprintf(skill_desc, "incoherant"); } else if (pSkill <= 5) { sprintf(skill_desc, "barely comprehendable"); } else if (pSkill <= 10) { sprintf(skill_desc, "sloppy"); } else if (pSkill <= 15) { sprintf(skill_desc, "awful"); } else if (pSkill <= 20) { sprintf(skill_desc, "uneducated"); } else if (pSkill <= 25) { sprintf(skill_desc, "halting"); } else if (pSkill <= 30) { sprintf(skill_desc, "mottled"); } else if (pSkill <= 35) { sprintf(skill_desc, "stuttering"); } else if (pSkill <= 40) { sprintf(skill_desc, "poor"); } else if (pSkill <= 45) { sprintf(skill_desc, "stammering"); } else if (pSkill <= 50) { sprintf(skill_desc, "decent"); } else if (pSkill <= 55) { sprintf(skill_desc, "decent"); } else if (pSkill <= 60) { sprintf(skill_desc, "fair"); } else if (pSkill <= 65) { sprintf(skill_desc, "fair"); } else if (pSkill <= 70) { sprintf(skill_desc, "good"); } else if (pSkill <= 75) { sprintf(skill_desc, "good"); } else if (pSkill <= 80) { sprintf(skill_desc, "nearly textbook"); } else if (pSkill <= 85) { sprintf(skill_desc, "textbook"); } else if (pSkill <= 90) { sprintf(skill_desc, "almost perfect"); } else if (pSkill <= 95) { sprintf(skill_desc, "almost perfect"); } else if (pSkill == 100) { sprintf(skill_desc, "perfect"); } /* now cycle thru the chars that can hear the speaker. */ for (vch = char_list; vch != NULL; vch = vch_next) { vch_next = vch->next; if (vch->in_room == NULL) continue; if (vch->in_room == ch->in_room) { if (vch == ch) continue; /* check the listener's skill level, and parse the text accordingly */ oSkill = get_skill (vch, skill_lookup(spk_language)); parsed = translation_parser(argument, oSkill); /* if it works out so no text gets thru all the parsing, deal with that */ if (!str_cmp(parsed, " ")) { printf_to_char(vch,"%s speaks in a strange tounge, and you do not understand a single word.{x\n\r",ch->name); improve_lang(vch, spk_language); continue; } /* otherwise, format it up and send it to the listener */ printf_to_char(vch,"%s speaks in %s %s. You understand the words '{7%s{6{x'\n\r", ch->name, skill_desc, spk_language, parsed); improve_lang(vch, spk_language); continue; } continue; } /* if the player's skill is less than 50 in the language, let them know they might not be understood very well */ if (pSkill < 50) { printf_to_char(ch, "You try and speak in %s, but you aren't sure if you are saying the words correctly.\n\r", spk_language); } /* show the char EVERYTHING they said, whether others understand it or not */ improve_lang(ch, spk_language); printf_to_char(ch, "You try and speak in %s, '{7%s{6{x'\n\r", spk_language, full_argument); return; } /* [ END OF CODE ] */ ********************************************************************** ************* MERC.H ********************************************* ********************************************************************** ## in the pc_data structure, *find* the code: char * bamfin; ## add char * language; /* Language Code by Forridean */ ********************************************************************* ## *find* the following code: /* interp.c */ void interpret args( ( CHAR_DATA *ch, char *argument ) ); ## and add this below it: int count_args args( ( char *argument) ); /* Language Code by Forridean */ ********************************************************************** ## find the code: extern sh_int gsn_recall; ## and add this below it: extern sh_int gsn_common; extern sh_int gsn_elfish; extern sh_int gsn_dwarvish; ********************************************************************** ************* INTEP.C ********************************************* ********************************************************************** ## find the code: {"say", do_say, POS_RESTING, 0, LOG_NORMAL, 1}, {"'", do_say, POS_RESTING, 0, LOG_NORMAL, 0}, ## add: {"translate", do_translate, POS_RESTING, 0, LOG_NORMAL, 1}, {"-", do_translate, POS_RESTING, 0, LOG_NORMAL, 0}, ********************************************************************* ## down near the bottom, by the code for one_argument, add this: /* [count_args() by Forridean] */ int count_args (char *argument) { char arg[MAX_STRING_LENGTH]; int count; count = 0; while (*argument != '\0') { argument = one_argument(argument, arg); if (arg != '\0') count++; } return count; } /* [END OF CODE] */ ********************************************************************** ************* INTEP.H ********************************************* ********************************************************************** ## add this in the correct place (alphabetic order) DECLARE_DO_FUN( do_translate ); ********************************************************************** ************* CONST.C ********************************************* ********************************************************************** ## Find the code for the wand skill, and add the following code below it, first making SURE that it follows the same structure as you other skills. If it doesn't, then you will have to make your own skill entries to reflect this information: { "Common", {1, 1, 1, 1}, {1, 1, 1, 1}, spell_null, TAR_IGNORE, POS_STANDING, &gsn_common, SLOT (0), 0, 12, "", "!common!", ""}, { "Elfish", {1, 1, 1, 1}, {1, 1, 1, 1}, spell_null, TAR_IGNORE, POS_STANDING, &gsn_elfish, SLOT (0), 0, 12, "", "!elfish!", ""}, { "Dwarvish", {1, 1, 1, 1}, {1, 1, 1, 1}, spell_null, TAR_IGNORE, POS_STANDING, &gsn_dwarvish, SLOT (0), 0, 12, "", "!dwarvish!", ""}, ********************************************************************** ************* NANNY.C ******************************************* ********************************************************************** ## find the code: ch->race = race; ## and add this below: /* [ Language Code by Forridean ] */ if (ch->race == race_lookup("dwarf")) { ch->pcdata->learned[gsn_dwarvish] = 100; ch->pcdata->language = str_dup ("dwarvish"); } if (ch->race == race_lookup("elf")) { ch->pcdata->learned[gsn_elfish] = 100; ch->pcdata->language = str_dup ("elfish"); } if (ch->race == race_lookup("Human") || ch->race == race_lookup("giant")) { ch->pcdata->learned[gsn_common] = 100; ch->pcdata->language = str_dup ("common"); } /* [END OF CODE] */