Change font size
It is currently Thu Nov 22, 2018 5:49 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 2 posts ]
Author Message
 Post subject: New Playing Animation Changed Event (AO Stuff)
PostPosted: Thu Jul 23, 2009 8:07 pm 
OSG Elite
User avatar

Joined: Wed Mar 11, 2009 3:57 pm
Posts: 444
Here is a Code Snippet to help anyone trying to fix up an AO. It uses a Changed Event instead of a timer and therefore considerably faster and no Timer() overhead. This is slightly related to another code snippet here in the forums. I used the Particle Emitter from that as an example of a function that could occur when the avatar (in this case) walk, the avatar emits a Particle Effect.

Reference information is included in the code snippet for your perusal.

{L_CODE}:
// ALTERNATE Anim Detection WITHOUT using a Timer Event
// Added the sub-code detection for the different animations as reported by the viewer
// as this can now be used to act on any animation being played and do something with them.
// Ideally suited for an AO and quicker in response without the overhead
// uses the change event:
// ** REFERENCE     http://docs.opensimulator.org/classOpenSim_1_1Region_1_1ScriptEngine_1_1Shared_1_1ScriptBase_1_1ScriptBaseClass.html#5f605bfb618f30f46315a97fe9ab6550
// ** REFERENCE     const int OpenSim::Region::ScriptEngine::Shared::ScriptBase::ScriptBaseClass::AGENT_TYPING = 512 
//
// Additional chaged events that can be captured directly:
// *  AGENT_FLYING = 1
// *  AGENT_ATTACHMENTS = 2
// *  AGENT_SCRIPTED = 4
// *  AGENT_MOUSELOOK = 8
// *  AGENT_SITTING = 16
// *  AGENT_ON_OBJECT = 32
// *  AGENT_AWAY = 64
// *  AGENT_WALKING = 128
// *  AGENT_IN_AIR = 256
// *  AGENT_TYPING = 512
// *  AGENT_CROUCHING = 1024
// *  AGENT_BUSY = 2048
// *  AGENT_ALWAYS_RUN = 4096
// ========================================================
// LlGetAgentInfo
// REREFENCE: http://wiki.secondlife.com/wiki/LlGetAgentInfo
// for more info on viewer based default anims
//

list anims = [];
key OWNER;
string PreviousAnim;
//
StartSteam()
{
    llParticleSystem([  PSYS_PART_MAX_AGE,6.0,
                    PSYS_PART_FLAGS, PSYS_PART_EMISSIVE_MASK | PSYS_PART_INTERP_COLOR_MASK | PSYS_PART_INTERP_SCALE_MASK | PSYS_PART_FOLLOW_VELOCITY_MASK ,
                    PSYS_PART_START_COLOR, <1,1,1>,
                    PSYS_PART_END_COLOR, <1,1,1>,
                    PSYS_PART_START_SCALE,<1,1,1>,
                    PSYS_PART_END_SCALE,<1,1,1>,
                    PSYS_SRC_PATTERN,  PSYS_SRC_PATTERN_EXPLODE,
                    PSYS_SRC_BURST_RATE,0.3,
                    PSYS_SRC_ACCEL, <0,0,0>,
                    PSYS_SRC_BURST_PART_COUNT,1,
                    PSYS_SRC_BURST_RADIUS,0.0,
                    PSYS_SRC_BURST_SPEED_MIN,1.5,
                    PSYS_SRC_BURST_SPEED_MAX,1.55,
                   // PSYS_SRC_TARGET_KEY,target,
                    //PSYS_SRC_INNERANGLE, 0.01,
                    //PSYS_SRC_OUTERANGLE, 1.0,
                    PSYS_SRC_ANGLE_BEGIN, 0.01,
                    PSYS_SRC_ANGLE_END, 1.0,
                    PSYS_SRC_OMEGA, <0,0,1>,
                    PSYS_SRC_MAX_AGE, 0.0,
                    PSYS_SRC_TEXTURE, "ddf57dfe-de15-4ec0-80ca-25e2ad257e39",
                    PSYS_PART_START_ALPHA, 1.0,
                    PSYS_PART_END_ALPHA, 1.0
                    ]);
}
// no emissions if not typing !
StopStream()
{
    llParticleSystem([]);
}
//
// This could be used for an AO (hint hint) and to execute multiple results based on the animplaying.
// this stub is here to make it easier to Change to different animations based on the captured animplaying.
ANIM_chg(string animplaying)
{
    if(animplaying == "")
    {
        llStopAnimation(PreviousAnim);
        PreviousAnim = animplaying;
        return;
    }
    else if(animplaying == "Walking") StartSteam();
    else
    {
        llStopAnimation(PreviousAnim);
        PreviousAnim = animplaying;
        llStartAnimation(animplaying);
    }
}
//
default
{
    state_entry()
    {
        StopStream();
        OWNER = llGetOwner();
        llAttachToAvatar(ATTACH_BELLY);         // USE ONLY IF used as a Worn Object
        llSetText("",<1,0,0>,1.0);
        llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES); // USE ONLY IF used as a Worn Object
    }
    changed( integer change )
    {
        if (change & CHANGED_ANIMATION) // CHANGED_ANIMATION is new !
        {
            // to capture normal anims as presented by the Viewer
            string anim = llGetAnimation(OWNER);
            //
            llOwnerSay(anim); // displays that anims that are currently captured, so you can see for yourself.
            //
            StopStream(); // stops the Particle Stream on every change.  We don't want to blow up viewers !  LOL
            //
            // these are the typical / normal anims reported by the viewer
            // usually the ones used to address anims for an active AO so I am listing them here.
            // commented out as not needed in this sample script. 
            //
            //if (anim == "Crouching") ANIM_chg(anim);
            //if (anim == "CrouchWalking") ANIM_chg(anim);
            //if (anim == "Falling Down")ANIM_chg(anim);
            //if (anim == "Flying") ANIM_chg(anim);
            //if (anim == "FlyingSlow")ANIM_chg(anim);
            //if (anim == "Hovering")ANIM_chg(anim);
            //if (anim == "Hovering Down")ANIM_chg(anim);
            //if (anim == "Hovering Up")ANIM_chg(anim);
            //if (anim == "Jumping")ANIM_chg(anim);
            //if (anim == "Landing")ANIM_chg(anim);
            //if (anim == "PreJumping")ANIM_chg(anim);
            //if (anim == "Running")ANIM_chg(anim);
            //if (anim == "Sitting")ANIM_chg(anim);
            //if (anim == "Sitting on Ground")ANIM_chg(anim);
            //if (anim == "Standing")ANIM_chg(anim);
            //if (anim == "Standing Up")ANIM_chg(anim);
            //if (anim == "Striding")ANIM_chg(anim);
            //if (anim == "Soft Landing")ANIM_chg(anim);
            //if (anim == "Taking Off")ANIM_chg(anim);
            //if (anim == "Turning Left")ANIM_chg(anim);
            //if (anim == "Turning Right")ANIM_chg(anim);
            if (anim == "Walking") ANIM_chg(anim);
        }
    }   
}

_________________
No further support of any kind, for any of my materials. Use as/is whereis.
PLEASE UNSTICKY Any Stickied Posting by myself.


Top
 Profile  
 
 Post subject: Re: New Playing Animation Changed Event (AO Stuff)
PostPosted: Tue May 29, 2012 5:44 pm 
Furious Typer
User avatar

Joined: Mon Aug 10, 2009 11:53 pm
Posts: 258
Long time no type all,

Well this is a bit of a resurrection of a thread here, but thought I would post the end result since this was exactly what I'd been looking for. Now that I'm back to a 'normalish' life and can enjoy my NPC projects again. :) Nice low-lag AO! Thanks to WhiteStar for doing all the work, and here is the finished product. If anyone would like a simple AO with some basic animations already inside it, just stop by Ispbeland in world and grab you one. Click the glowing orb by the tree. It will take you to the few goodies. More coming soon.

Without further ado:

{L_CODE}:
// -------------------------------------------------------------------------------
// Original ALTERNATE method of detecting ANIMATION changes without using a timer
// By WhiteStar Magic - 3-11-2009
// Altered as implied by Haplo Voss for very simple AO - 5-28-12
// -------------------------------------------------------------------------------

// NOTE: All animations need to be renamed to match the naming conventions
// In the script as they are detected. This is a very simple AO and no lists
// are being generated to do name handling. See the changed Animation block
// for correct naming convention.
// -------------------------------------------------------------------------------

list anims = [];
key OWNER;
string PreviousAnim;
integer debug = FALSE;

ANIM_chg(string animplaying)
{
    if(animplaying == "")
    {
        llStopAnimation(PreviousAnim);
        PreviousAnim = animplaying;
        return;
    }
    else
    {
        llStopAnimation(PreviousAnim);
        PreviousAnim = animplaying;
        llStartAnimation(animplaying);
    }
}
//
default
{
    state_entry()
    {
        OWNER = llGetOwner();
        llRequestPermissions(OWNER, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
        llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES); // USE ONLY IF used as a Worn Object
    }
    changed( integer change )
    {
        if (change & CHANGED_ANIMATION) // CHANGED_ANIMATION is new !
        {
            // to capture normal anims as presented by the Viewer
            string anim = llGetAnimation(OWNER);
            //
            if (debug) llOwnerSay(anim); // Set debug = TRUE to see anims displayed as they occurr.
            //
            //if (anim == "Crouching") ANIM_chg(anim);
            //if (anim == "CrouchWalking") ANIM_chg(anim);
            //if (anim == "Falling Down")ANIM_chg(anim);
            if (anim == "Flying") ANIM_chg(anim);
            //if (anim == "FlyingSlow")ANIM_chg(anim);
            if (anim == "Hovering")ANIM_chg(anim);
            //if (anim == "Hovering Down")ANIM_chg(anim);
            //if (anim == "Hovering Up")ANIM_chg(anim);
            if (anim == "Jumping")ANIM_chg(anim);
            if (anim == "Landing")ANIM_chg(anim);
            //if (anim == "PreJumping")ANIM_chg(anim);
            if (anim == "Running")ANIM_chg(anim);
            if (anim == "Sitting")ANIM_chg(anim);
            if (anim == "Sitting on Ground")ANIM_chg(anim);
            if (anim == "Standing")ANIM_chg(anim);
            //if (anim == "Standing Up")ANIM_chg(anim);
            //if (anim == "Striding")ANIM_chg(anim);
            //if (anim == "Soft Landing")ANIM_chg(anim);
            //if (anim == "Taking Off")ANIM_chg(anim);
            //if (anim == "Turning Left")ANIM_chg(anim);
            //if (anim == "Turning Right")ANIM_chg(anim);
            if (anim == "Walking") ANIM_chg(anim);
        }
    }   
}

Take care all,
- Hap

_________________
Sorry, I was just thinking upon the immortal words of Socrates who said ... "I drank what?? ... "
- Real Genius


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 2 posts ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net