Chats

From LSWiki

(Redirected from Chat variables)
Jump to: navigation, search

Chats are important to giving your autonomoi personality and flavor, to setting them up to be interactive, and sometimes even to setting their combat behavior.

The basic commands is straightforward: in the configure of your autonomon, use the functions set_chat(int, (string array)), set_combat_chat(int, (string_array)), and set_responses(mapping). The int in the former two cases represents the frequency of the chat (I think it's determined by whether or not a random(100) every heartbeat is lower than it). The first element of the mapping for responses is the communication key that triggers the response of the second element. Both of these can be string arrays. In the first case this will mean that they have the same response for more than one thing, and in the second that their response involves more than one action.

If this is confusing, just go look at some examples. There are a great many examples, everywhere on the mud; if you need a place to start, start with Aildrek.

The mechanism for chats is fairly simple, so simple in fact that sometimes they just don't seem flexible enough to do what you want to do. The two main ways of alleviating this are by using some built-in escape characters in your chats (easier) or by writing custom functions/closures (harder).

Chat Variables

Here are some escape characters you can use in chats and combat chats.

  • %e, enemy
  • %f, friend
  • %s, source (on chat responses)
  • %p, person, prefers players but will choose an NPC if one isn't around
  • %s, source, i.e. the thing that initiates a response for responses
  • %b, bystander, like someone not involved in combat
  • %h, someone hiding, i.e. someone attacking you other than the person you're attacking

These each have "conversational" variants that look like %Cp, %Ce, and so forth. These address the individual in question by a name suitable for use in conversation, as opposed to a name suitable for command targeting.

For example:

    set_chat(2, ({
        "say Hello, %Cp.",
        "say Greetings. to %p",
        "hug <%f>",
    });
    set_combat_chat(50, ({
        "say Help me, %Cb!"
        "spit <%e>"
        "throw dagger at %h",
    });
    set_responses(([
        ({ "what is your name", "who are you", "what are you called" }) :
            "say What gives you the right to ask, %Cs?",
    ]));

The non-combat chats will say hello to a player (or an NPC if none is around/visible), and hug someone befriended, respectively. The combat chats will ask a bystander (someone not in combat) for help, spit on an attacker, and throw a dagger at someone who is attacking but is being succored. The snide response will include the asker's name in it.

Note that you can also put a closure in a chat, i.e.

    set_chat(5, ({
        #'fish_command,
    }));

Custom Commands and Closures in Chats

There are any number of reasons to use closures in chats. The simplest case is that you want a correct message of the autonomon in question interacting with an object. For example, the fishermen in Hanoma perform various actions directed at their fishing rods. So I map this fish_command function to an add_action and have them call it in their chat cycle:

status fish_command() {
    if(query_attacker() || query_incapacitated())
        return True;
    object rod = locate_name("fishing rod");
    unless(rod)
        return True;
    if(environment(this_object())->query_realm("Hanoma_Dock")) {
        message(({ 0, "expertly", ({ "cast", 0 }), "a line from", ({ 'r', 0, rod }), "off the dock and into the bay" }));
        return True;
    }
    int i = random(4);
    switch(i) {
        case 0  : message(({ 0, ({ "check", 0 }), "the line on", ({ 'r', 0, rod }) })); break;
        case 1  : message(({ 0, "carefully", ({ "examine", 0 }), ({ 'r', 0, rod }) })); break;
        case 2  : message(({ 0, ({ "adjust", 0 }), "the taughtness of the line on", ({ 'r', 0, rod }) })); break;
        case 3  : message(({ 0, ({ "tighten", 0 }), "the knot holding the hook on", ({ 'r', 0, rod }) })); break;
        default : 0; break;
    };
    return True;
}

You can also see that you can something like the above to handle more complex cases, in this case where they are. If they are on a dock in Hanoma, they will attempt to fish, otherwise they will maintain their rod in one of four ways.

Using init for Initial Responses

Personal tools