I'm trying to get the current language spoken by the character to show up in say. I cannot, for the life of me, figure it out. I can get a language to show up but it's not the language currently being spoken. I know that I'm just overlooking something that I should know...if anyone could help me get on the right track I'd appreciate it.
Showing Current Language in Say
Posted by Twystedpair on Thu 03 Jul 2003 07:17 AM — 5 posts, 16,690 views.
Can you post a snippet showing what you did - that will help see if you are on the right track.
Here is the line, I just can't figure out what to define the string as:
ch_printf(ch, "&CYou say (&W%s&C): &W%s\n\r", ??, drunk_speech( argument, ch ));
I've tried everything I can think of and find in the code at the moment. I'm not that wonderful at C but I'm just learning to do minor alterations right now. I tried lang_names[ch->speaking] but got the wrong language...so I set it as an integer and just showed ch->speaking in say and it shows 2, 4, 8, 16, 32, etc. as I go through speaking the different languages, when I need it to show 0, 1, 2, 3, etc. or atleast that's what I think considering the language names are in a const right there in the same file.
ch_printf(ch, "&CYou say (&W%s&C): &W%s\n\r", ??, drunk_speech( argument, ch ));
I've tried everything I can think of and find in the code at the moment. I'm not that wonderful at C but I'm just learning to do minor alterations right now. I tried lang_names[ch->speaking] but got the wrong language...so I set it as an integer and just showed ch->speaking in say and it shows 2, 4, 8, 16, 32, etc. as I go through speaking the different languages, when I need it to show 0, 1, 2, 3, etc. or atleast that's what I think considering the language names are in a const right there in the same file.
Actually, ch->speaking uses the power of 2 numbers (1, 2, 4, 8, 16, etc.) because it's a set of flags. For example, if 2 is set, then ch is speaking language 2 is being spoken. If 6 is set, then ch is speaking languages 2 AND 3 (represented by 2 + 4).
So you have two problems:
1- mobs who speak multiple languages probably should either not have a language indicator, or should only display the first language. However, the problem is that mobs who speak multiple languages are probably "special mobs" such as the supermob, who must be understood at all times. Or, immortals can use "speak all" to speak all languages at once. I would recommend leaving the language tag off for people speaking more than one.
2- you need to make a routine to translate from powers of 2, and display the right text. Here is the code that was in my MUD. I didn't write it, and since it works (and I've never needed to) I haven't looked into the exact details, but it's fairly straightforward. You will probably have to modify it, because this isn't stock SMAUG anymore... but maybe it's similar enough to require minimal modification.
This is the code that the game calls when looping through the room's people to display to everyone what ch said.
Where language is a bool, set to false if ch->speaking == 0 (which I believe means speaking all) and true otherwise; lang_names is the strings corresponding to language numbers; can_understand is a boolean set to true if victim (or vch) can understand ch's language; understand is a simple char string. I think that's it.
Let me know if this helps you. :)
So you have two problems:
1- mobs who speak multiple languages probably should either not have a language indicator, or should only display the first language. However, the problem is that mobs who speak multiple languages are probably "special mobs" such as the supermob, who must be understood at all times. Or, immortals can use "speak all" to speak all languages at once. I would recommend leaving the language tag off for people speaking more than one.
2- you need to make a routine to translate from powers of 2, and display the right text. Here is the code that was in my MUD. I didn't write it, and since it works (and I've never needed to) I haven't looked into the exact details, but it's fairly straightforward. You will probably have to modify it, because this isn't stock SMAUG anymore... but maybe it's similar enough to require minimal modification.
for ( vch = ch->in_room->first_person; vch; vch = vch->next_in_room )
{
char buffer[MAX_STRING_LENGTH];
char understand[MAX_STRING_LENGTH];
char *sbuf = argument;
bool language;
bool can_understand;
if ( vch == ch )
continue;
can_understand = TRUE;
if ( !knows_language(vch, ch->speaking, ch) &&
(!IS_NPC(ch) || ch->speaking != 0) )
{
sbuf = scramble(argument, ch->speaking);
can_understand = FALSE;
}
if ( ch->speaking != 0 )
{
language = TRUE;
}
sbuf = drunk_speech( sbuf, ch );
MOBtrigger = FALSE;
if (language)
{
int i, count, lang;
count = lang = 0;
for (i = LANG_COMMON; lang_array[i] != LANG_UNKNOWN; i++)
{
if (ch->speaking & lang_array[i])
{
count++;
lang = i;
}
}
if (count == 1)
{
if (can_understand)
sprintf(understand, "in %s", lang_names[lang]);
else
sprintf(understand, "in some language");
sprintf(buffer, "$n says, %s, '$t'", understand);
}
else
{
sprintf(buffer, "$n says '$t'");
}
}
else
sprintf(buffer, "$n says '$t'");
act( AT_SAY, buffer, ch, sbuf, vch, TO_VICT );
}
This is the code that the game calls when looping through the room's people to display to everyone what ch said.
Where language is a bool, set to false if ch->speaking == 0 (which I believe means speaking all) and true otherwise; lang_names is the strings corresponding to language numbers; can_understand is a boolean set to true if victim (or vch) can understand ch's language; understand is a simple char string. I think that's it.
Let me know if this helps you. :)
Took a little bit of obvious modification but plopped right in without a hitch. That's exactly what I was thinking with the ch-> speaking, after I set it to show me what it actually was. Now that I look at the working code, it makes sense. Thanks much!