EmotiveAvi

EmotiveAvi is a simple method to make an avatar that responds to chat to play speaking animations, change states, or play actions.

Downloads

 * EmotiveAvi.as - The source file
 * smile.fla - An example avatar that uses EmotiveAvi, if the below instructions confuse you, grab this file and see how EmotiveAvi was used in the main scene code.

Using EmotiveAvi
Download EmotiveAvi.as and either place it in the same directory as your avatar, or you can place the file in the uravatar/src directory so it will be available to all your avatars.

In your main scene, after _ctrl = new AvatarControl(this), add this new line:

var emo:EmotiveAvi = new EmotiveAvi(_ctrl);

Now we just need to tell the avatar what to do when it hears different chat. We can do this by registering mood states, actions, and speak actions. You don't have to do all of these, just the ones you want the avatar to do. So if you just want an avatar that plays animations when the user chats, you only need to use the registerSpeakAction function.

registerMoodState(state name, list of chat triggers)
Example: emo.registerMoodState("Morose", [ "I'm so sad" ]); The avatar will change to the Morose state when the user says "I'm so sad"

Example: emo.registerMoodState("Happy", [ ":)", ":-)","=)",":D","=D",":-D" ]); The avatar will change to the Happy state when the user says any of the above smilies

registerMoodAction(action name, list of chat triggers)
Example: emo.registerMoodAction("Surprise", ["OMG","!!!","ZOMG"]); The avatar will play the action named Surprise when the user says either OMG, !!! or ZOMG

registerSpeakAction(state name,speak action)
If you havn't registered a speak action for a state, the script will attempt to use the speak for state Default. Speak animations only play if a mood action wasn't triggered.

Example: emo.registerSpeakAction("Default","Speak"); If the user is in the Default state, the avatar will play the action named Speak

Example: emo.registerSpeakAction("On fire", "Immolated Speak"); If the user is in the state named On fire, then Immolated Speak will be triggered on chat

Complete Usage Example
Everything else about the avatar is the same as usual. Just make sure you actually have actions and states created that match the names you used, and this will work automatically. This should also be compatible with any of the different Body scripts out there.

Combining all these steps, here is what an example avatar looks like in the main scenes code:

import flash.display.MovieClip; import flash.display.Sprite;

import flash.events.Event;

import com.whirled.AvatarControl; import com.whirled.ControlEvent;

if (_ctrl == null) { _ctrl = new AvatarControl(this); _ctrl.setHotSpot(150,300,175); _body = new Body(_ctrl, this, 300, 150);

var emo:EmotiveAvi = new EmotiveAvi(_ctrl); // registerMoodState takes the name of a state, // followed by the chat triggers that will force avi into that mood emo.registerMoodState("Happy", [ ":)", ":-)","=)", "happy" ]);	emo.registerMoodState("Frowning", [ ":(", ":-(", "=(", "sad" ]); emo.registerMoodState("Default", [ ":|", "=|", ":-|", "meh" ]); emo.registerMoodState("Crying", [ "im cryin in rl" ]);

// registerMoodAction takes the name of an action, // follow by the chat triggers that will cause the avatar to use

// those actions emo.registerMoodAction("Surprise", ["OMG","!!!","ZOMG"]);

// registerSpeakAction takes the name of a state,

// followed by the action to use // if EmotiveAvi can't find a speak action for a state, // it will try and use "Default" emo.registerSpeakAction("Default","Speak"); emo.registerSpeakAction("Crying", "Crying Speak");

addEventListener(Event.UNLOAD, handleUnload); }

function handleUnload (... ignored) :void {  _body.shutdown; }

var _ctrl :AvatarControl; var _body :Body;

Attribution
If you use this script in an avatar and find it useful, please attribute Cosmic Cheese. To attribute, favorite these listings:
 * EmotiveAvi Base [bars] - http://www.whirled.com/#shop-l_5_38263
 * EmotiveAvi Base [coins] - http://www.whirled.com/#shop-l_5_38262

and then when listing your item, select the listing you favorited in the Based On dropdown.