From the NannyMUD documentation

LAST CHANGE

2001-08-08

NAME

        state_monster - A state monster.

INHERITS

        /std/monster (do 'man monster' for further details)

FUNCTIONS

SETUP FUNCTIONS

        add_response
        add_timeout
        set_state
        reset_timeout
        clear_timeout
        set_chat_chance
        add_chat

QUERY FUNCTIONS

        query_state
        query_states
        query_timeout
        query_timeouts

OTHER FUNCTIONS

        remove_response
        remove_timeout
        remove_chat

PROPERTIES

INTERNAL PROPERTIES


PROPERTY NAME

        listen_to_npc - Makes the state_monster listen to chats by NPCs.

DESCRIPTION

        Usually monsters respond only to messages coming from the
        players. Adding this property will make the monster respond to
        messages coming from NPCs as well. You can make NPCs interact
        with eachother this way.

PROPERTY NAME

        speed_chat - Make the monster say the entire chat in one go.

DESCRIPTION

        Chats are queued, and in each heart beat, only one line of text is
        displayed. To get the whole queue emptied at once, add this property.

PROPERTY NAME

        debug_level - Set the level of debug information.

DESCRIPTION

        Set this to a integer to see debug information
        that can be vital when debugging a monster.


FUNCTION


NAME

        add_response - Add responses to the monster.

SYNTAX

        void add_response(string state, string pattern,
                          string response, string new_state)

SYNTAX

        void add_response(string state, string pattern,
                          string response, string new_state,
                          string flag, int random, int shots)

SYNTAX

        void add_response(string state, string pattern,
                          string response, string new_state,
                          int random, int shots)

DESCRIPTION

        With this function you add a response. If the  matches, the
         is executed. Please note that only one (1)  is
        executed at any time.  However if a  has failed the monster
        tries to match a new . Therefore, if you have random, the
        order of the responses affect the chance that they will be carried out.

        Below is a detailed description of the different arguments:

           A state is any string you wish, example: "angry". There is
                however one string that is reserved, "ALL", "ALL" means that
                this pattern will be matched in "ALL" states.

           See monster.
          See monster.
         A string containing the new_state the monster should end up
                    in. The monster changes state BEFORE the  is
                    evaluated (This allows a response function to alter the
                    state to something else, if needed).
                    A '0' (zero) as state means do not change state.

              See monster.
            See monster.
             See monster.

EXAMPLE

        add_response("ALL","%1 smiles happily.","!smile %L1");
        This will cause the monster to smile if someone smiles in the
        same room as the monster is in. Notice that the %1 is always the
        exact match of the string. In this case it would be the players
        name capitalized. So to be able to smile towards the monster we
        need to first convert it to lower_case thus the %L1 in the response.

EXAMPLE

        add_response("ALL","%1 massacres Theo.",
        "$/std/msg->msg(\bPRON cast\b$ a fireball on \b2PRON.\n,%P0,%P1)");
        This makes "Theo casts a fireball on you." be typed to the player
        doing the masacre on Theo.

FUNCTION


NAME

        add_timeout - Add a timeout to the state we just entered.

SYNTAX

        void add_timeout(string state, int time, string action,
                         string next_state)

DESCRIPTION

        Whenever the monster changes state it starts a timeout IF there is
        one defined for this state. When the timeout expires, the monster
        changes state to .

        Below is a detailed description of the different arguments:

        
          A string with the state the timeout is for.

        

SEE ALSO

        add_response in std/monster/monster
        add_response in std/monster/state_monster

FUNCTION


NAME

        set_state - Set the current state in the monster.

SYNTAX

void set_state(string state)

DESCRIPTION

        Set the current state in the monster to . When this is done
        a timeout is started if there is one defined for this state.

FUNCTION


NAME

        reset_timeout - Reset the current timeout if any.

SYNTAX

void reset_timeout(int new_duration)

DESCRIPTION

        If you call this function you reset the current timeout if there was
        any. This means it is started all over again, with a new duration of
        . If  is 0, the original duration will be
        used.

FUNCTION


NAME

        clear_timeout - Clear the current timeout if any.

SYNTAX

void clear_timeout()

DESCRIPTION

        If there is a timeout running it is stopped. Note that since you can
        only be in one state at a time, there can only be one timeout running
        at one time: the one for the current state.

FUNCTION


NAME

        add_chat - Add chat strings.

SYNTAX

void add_chat(string state,string chat)

SYNTAX

void add_chat(string state, string *chats)

DESCRIPTION

        This function adds one or more 'chats' to the monster. Chats are
        strings that the monster will echo when there are players present.
        You can either give it one chat string at a time, or send it an
        array of chats. The chats are only performed if the monster is in
        that state, if state "ALL" was given the chat can be given in all
        states.

FUNCTION


NAME

        remove_chat - Remove chats.

SYNTAX

void remove_chat(string state,string chat)

SYNTAX

void remove_chat(string state,string *chat)

DESCRIPTION

        Remove the chats for the state .

FUNCTION


NAME

        set_chat_chance - Set the chance to be obnoxious.

SYNTAX

void set_chat_chance(int chance)

DESCRIPTION

        This sets the chance (in percent) for the monster to echo one of
        the chat strings every heart beat. ie. A chance of 1 will in average
        do a chat every 200 seconds, a chance of 2 will do one every 100
        seconds, etc etc.

FUNCTION


NAME

        remove_response - Remove a response.

SYNTAX

void remove_response(string state, string pattern)

DESCRIPTION

        If there was a response in  with a match pattern identical to
        , it is removed.

FUNCTION


NAME

        remove_timeout - Remove a timeout from a state.

SYNTAX

void remove_timeout(string state)

DESCRIPTION

        If there was a timeout for , it is removed. Note that it
        doesn't matter if the timeout is actually running or not, it
        is removed either way.

FUNCTION


NAME

        query_state - Ask the monster what state it is in.

SYNTAX

string query_state()

DESCRIPTION

        Ask the monster what state it is in. The monster returns a string
        with the current state.

FUNCTION


NAME

        query_states - Ask the monster what states it has.

SYNTAX

mapping query_states()

DESCRIPTION

        This function is mainly used for debugging purposes. It returns a
        mapping with the entire state structure.

FUNCTION


NAME

        query_timeout - Ask the monster how long time it is left to the timeout.

SYNTAX

int query_timeout()

DESCRIPTION

        Returns the number of seconds to the timeout if any. If there is no
        timeout running for this state, it returns -1.

FUNCTION


NAME

        query_timeouts - Ask the monster what timeouts it has.

SYNTAX

mapping query_timeouts()

DESCRIPTION

        This function is mainly used for debugging purposes. It returns a
        mapping with the entire timeout structure.