Chats

From LSWiki

Revision as of 10:26, 20 January 2007; Msb (Talk | contribs)
(diff) ←Older revision | Current revision | Newer revision→ (diff)
Jump to: navigation, search

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

For example:

    set_chat(2, ({
        "!say Hello, %p."
        "!hug %f",
    });
    set_combat_chat(50, ({
        "!say Help me, %b!"
        "!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, %s?",
    ]));

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.

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.

Personal tools