Chat Commands

View previous topic View next topic Go down

Do you use the chat command system?

33% 33% 
[ 1 ]
0% 0% 
[ 0 ]
67% 67% 
[ 2 ]
0% 0% 
[ 0 ]
 
Total Votes : 3

Chat Commands

Post  Felix on Mon Apr 09, 2012 2:28 pm

It seems to me that people may not know of this system we have in place. You can do really fun stuff with this system like command your summons/companions to attack a door indefinitely or talk as your summon ect ect. Just type "/help" without quotes in the chat box for a book with some quick references in it. Here is the original post from J regarding the system he made.

J. Persinne wrote:With this next update, we'll be adding a robust chat commands system to the module. For those who aren't aware, a chat command is an action that's executed from the chat event when a player types text into the chat bar. Examples of some typical chat commands:

/sit -- the character sits down
/laugh -- the character laughs
/d20 -- the character rolls a d20

Adding a Chat Command

A number of chat commands have already been included, but adding new ones is extremely easy. Here's what you need to do:

1) Add a new script to the module. Prefix the script name with "cc_". Whatever comes after the prefix will then be used as the chat command name in game (i.e., if you call the script "cc_sit", it will be executed when players type /sit). You don't have to alter the chat command script in order to hook it in after the fact. At this point, you're done with that part; the chat command will automatically be executed.
2) In your custom chat command script, include the file "_inc_chat".
3) In the first line of your chat command script, call FlagChatCommandExecuted(). This passes a variable back to the chat command handler to inform it that the chat command was executed properly. If the chat command wasn't executed properly, it will assume the chat command does not exist and inform the player that the command was invalid.

Special Notes

At this point, you're pretty much done. But there are a couple things to note:

1) Chat commands are executed from the player object. Meaning that in order to refer to the player, you need simply reference OBJECT_SELF. When performing an action, no reference is required.
2) _inc_chat includes a constant float called CHAT_COMMAND_EMOTE_DURATION. All looping chat command emotes should use this value as a default.

Chat Command Parameter Functions

There are also several handy functions included in _inc_chat to make your life easier:

1) CreateChatCommandParametersArray(int nParametersCount, int nExcessParametersAppend = FALSE, object oPC = OBJECT_SELF)

This script will parse whatever text the player typed after the chat command into an array of parameters to be used by the chat command script. For example, if the player had typed "/sit 300 south", it will parse "300 south" into a parameters array.

It will parse out as many parameters as you ask it to in the nParametersCount variable. If nExcessParametersAppend is set to FALSE, it will ignore excess parameters; if set to TRUE, it will concatenate excess parameters into the last parameter.

Note that the delimiter between parameters is "|". Ergo, if you request two parameters and the player types "/sit 300 south", you'll only get one (i.e. "300 south"), because it only sees one possible parameter. On the other hand, if they type "/sit 300|south", you will get two (i.e. "300" and "south").

2) GetChatCommandParameterAsString(int nParameter, object oPC = OBJECT_SELF)

Returns the specified parameter in the form of a string. Note that the first parameter begins from index 0. If you attempt to request more parameters than the number that exist, the function will always return "" (an empty string). This also means that you will always have to call CreateChatCommandParametersArray() first, or you will never receive any useful values.

3) GetChatCommandParameterAsInt(int nParameter, object oPC = OBJECT_SELF)

The same as the above, except it casts the parameter to an int. Returns 0 on error.

4) GetChatCommandParameterAsFloat(int nParameter, object oPC = OBJECT_SELF)

The same as the above, except it casts the parameter to a float. Returns 0.0 on error.

And that's it. Here's a sample chat command script:

File Name: cc_sit
Code:
#include "_inc_chat"

void main()
{
    FlagChatCommandExecuted();

    float fDuration;
    float fParameter1;

    CreateChatCommandParametersArray(1);
    fParameter1 = GetChatCommandParameterAsFloat(0);
    fDuration = fParameter1 >= 0.1 ? fParameter1 : CHAT_COMMAND_EMOTE_DURATION;
    ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS, 1.0, fDuration);
}
avatar
Felix
Admin

Posts : 1253
Join date : 2011-02-28

View user profile

Back to top Go down

Re: Chat Commands

Post  Felix on Fri Apr 13, 2012 4:42 pm

J. Persinne wrote:
Chat Commands

    -Finished incorporation of chat command scripts; the following chat commands are supported (accepted parameters are listed in braces):

    Emotes
    /beg {seconds}
    /bow
    /cast {seconds}
    /cast1 {seconds}
    /cast2 {seconds}
    /cheer
    /cheer1
    /cheer2
    /cheer3
    /conjure1 {seconds}
    /conjure2 {seconds}
    /dodge
    /drink
    /drunk {seconds}
    /duck
    /fall {seconds}
    /fallback {seconds}
    /greet
    /kneel
    /laugh
    /look {seconds}
    /low {seconds}
    /meditate {seconds}
    /mid {seconds}
    /middle {seconds}
    /plead {seconds}
    /pray {seconds}
    /read
    /salute
    /scratch
    /sit {seconds}
    /spasm {seconds}
    /taunt
    /threaten {seconds}
    /wave
    /worship {seconds}
    /yawn

    Associates
    /ai {"activate", "enable", "on", "deactivate", "disable", "off", "auto", "manual"} -- Manipulates associate AI modes
    /detect {"activate", "enable", "on", "deactivate", "disable", "off"} -- Manipulates associate detect modes
    /namecomp {text} -- Renames animal companion
    /namefam {text} -- Renames familiar
    namesum {which|text} -- Renames summon
    /stealth {"activate", "enable", "on", "deactivate", "disable", "off"} -- Manipulates assosciate stealth modes
    /tkcomp {text} -- Commands animal companion to speak
    /tkdom {which|text} -- Commands dominated creature to speak
    /tkfam {text} -- Commands familiar to speak
    /tkhench {which|text} -- Commands henchman to speak
    /tksum {which|text} -- Commands summon to speak

    Description
    /appenddesc {text} -- Appends your description
    /newlinedesc {number of lines} -- Adds blank lines to your description
    /setdesc {text} -- Sets your description

    Items
    /itappenddesc {text} -- Appends an item's description
    /itname {name} -- Renames an item
    /itnewlinedesc {number of lines} -- Adds blank lines to an item's description
    /itesetdesc {text} -- Sets an item's description

    Horn Signals
    /allclear -- Signal area all clear
    /enemies -- Signal enemies sighted in the area
    /expedition -- Call for an expedition group
    /reinforcements -- Call for reinforcements

    Miscellaneous
    /automine -- Toggles ATS automining
    /damage {amount} -- Damages self
    /die - Induces death
    /flavor {fruit} -- Makes you flavorful
    /help - Creates or destroys Chat Command Help Book
    /msgcolors -- Toggles PC message color scheme
    /relevel -- Allows you to retake your last level
    /removexp {amount} -- Removes experience points
    /sendings -- Toggles whether you will hear global sendings
    /subdual -- Sets subdual mode {"full", "deactivate", "disable", "off", "subdual", "activate", "enable", "on", "sparring"}

avatar
Felix
Admin

Posts : 1253
Join date : 2011-02-28

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum