Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Saya 2018
- *
- * Generic AO script for a tail
- *
- */
- // All of the animation names go in their appropriate lists
- list standing = ["AvatarAction_StandingSet1","AvatarAction_StandingSet2","AvatarAction_StandingSet3"];
- list walking = ["AvatarAction_Walk1"];
- list sitting = ["AvatarAction_Crouch1","AvatarAction_Turn1","AvatarAction_Turn2"];
- list sitting_on_ground = ["AvatarAction_Crouch1","AvatarAction_Turn1","AvatarAction_Turn2"];
- list crouching = ["AvatarAction_Crouch1","AvatarAction_Turn1","AvatarAction_Turn2"];
- list crouch_walking = ["AvatarAction_Crouch1"];
- list landing = ["AvatarAction_Landing1"];
- list standing_up = ["AvatarAction_Landing1"];
- list falling = ["AvatarAction_Falling1"];
- list flying_down = ["AvatarAction_Falling1"];
- list flying_up = ["AvatarAction_FlyingUp1"];
- list flying = ["AvatarAction_StandingSet1"];
- list flying_slow = ["AvatarAction_StandingSet2"];
- list hovering = ["AvatarAction_WaterFloating1"];
- list jumping = ["AvatarAction_Landing1"];
- list pre_jumping = ["AvatarAction_Landing1"];
- list running =["AvatarAction_Running1"];
- list turning_right = ["AvatarAction_Turning1"];
- list turning_left = ["AvatarAction_Turning2"];
- list floating = ["AvatarAction_WaterFloating1"];
- list swimming_forward = ["AvatarAction_SwimingFoward1"];
- list swimming_up = ["AvatarAction_FlyingUp1"];
- list swimming_down = ["AvatarAction_Falling1"];
- list typing = [];
- // returns TRUE if agent in water, else FALSE
- integer agent_in_water()
- {
- vector agent_pos = llList2Vector(llGetObjectDetails(llGetOwner(), [OBJECT_POS]), 0);
- float water_height = llWater(ZERO_VECTOR);
- return (agent_pos.z < water_height); // returns TRUE if agent's position is below water level
- }
- string now_playing = ""; // currently playing animation, if any
- // Start a random animation from a list of given animations
- // Must check permission to animate agent before calling!
- start_random_animation(list animations)
- {
- string animation = llList2String(llListRandomize(animations, 1), 0); // choose a random animation from list of animations
- llStartAnimation(animation); // star the animation
- llSleep(0.1);
- llStopAnimation(now_playing); // stop the old animation shortly afterwards (this is on purpose to prevent 'whitespace')
- now_playing = animation;
- }
- update_animations()
- {
- integer permissions = llGetPermissions();
- if (permissions & PERMISSION_TRIGGER_ANIMATION)
- {
- // have permission to animate
- integer agent_info = llGetAgentInfo(llGetOwner());
- if (agent_info & AGENT_CROUCHING)
- {
- // crouching, could be moving
- float velocity = llVecMag(llList2Vector(llGetObjectDetails(llGetOwner(), [OBJECT_VELOCITY]),0));
- if (velocity < 1)
- {
- // not moving
- start_random_animation(crouching);
- }
- else
- {
- start_random_animation(crouch_walking);
- }
- }
- if (agent_info & AGENT_WALKING)
- {
- // walking or running
- float velocity = llVecMag(llList2Vector(llGetObjectDetails(llGetOwner(), [OBJECT_VELOCITY]),0));
- if (velocity < 4)
- {
- // walking
- start_random_animation(walking);
- return;
- }
- else
- {
- // running
- start_random_animation(running);
- return;
- }
- }
- if (agent_info & AGENT_SITTING)
- {
- if (agent_info & AGENT_ON_OBJECT)
- {
- start_random_animation(sitting);
- return;
- }
- else
- {
- // sitting on ground
- start_random_animation(sitting_on_ground);
- return;
- }
- }
- if (agent_info & AGENT_IN_AIR)
- {
- // in the air or water
- vector velocity = llList2Vector(llGetObjectDetails(llGetOwner(), [OBJECT_VELOCITY]),0);
- float speed = llVecMag(velocity);
- if (agent_info & AGENT_FLYING)
- {
- if (speed < 0.25)
- {
- // hovering or floating
- if (!agent_in_water())
- {
- start_random_animation(hovering);
- return;
- } else
- {
- start_random_animation(floating);
- return;
- }
- }
- else
- {
- // moving in some form
- if (llFabs(velocity.z) < 1)
- {
- // more or less flying/swimming at the same height
- if (agent_in_water())
- {
- start_random_animation(swimming_forward);
- return;
- }
- else
- {
- start_random_animation(flying);
- return;
- }
- }
- else
- {
- if (velocity.z < 5)
- {
- // probably falling
- start_random_animation(falling);
- return;
- }
- // either going upwards or downwards
- if (velocity.z > 0)
- {
- // upwards
- if (agent_in_water())
- {
- start_random_animation(swimming_up);
- return;
- }
- else
- {
- start_random_animation(flying_up);
- return;
- }
- }
- else
- {
- // downwards
- if (agent_in_water())
- {
- start_random_animation(swimming_down);
- return;
- }
- else
- {
- start_random_animation(flying_down);
- return;
- }
- }
- }
- }
- }
- else
- {
- // agent jumping
- start_random_animation(jumping);
- }
- }
- // if we got this far, we're probably just standing
- start_random_animation(standing);
- }
- else
- {
- // no permission to animate, request it, if we're attached
- if (llGetAttached()) llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS| PERMISSION_TRIGGER_ANIMATION | PERMISSION_OVERRIDE_ANIMATIONS);
- }
- }
- default
- {
- state_entry()
- {
- llSetTimerEvent(10); // Every 10 seconds, update the AO. Every 2 seconds, check if the agent moved into or out of water
- if (llGetAttached()) llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS| PERMISSION_TRIGGER_ANIMATION | PERMISSION_OVERRIDE_ANIMATIONS);
- }
- attach(key id)
- {
- if (id) llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS| PERMISSION_TRIGGER_ANIMATION | PERMISSION_OVERRIDE_ANIMATIONS);
- }
- // // fires every 10seconds and updates the animation override for the agent
- // timer()
- // {
- // if (!llGetAttached()) return; // don't do anything when not attached
- // /*
- // *
- // * The following logic is disused because we're aiming for firestorm ao compatibility
- // * It could be reintroduced when, Firestorm supports multi-AO's
- // */
- // // if (llGetPermissions() & PERMISSION_OVERRIDE_ANIMATIONS)
- // // {
- // // // every couple of seconds, check if the avatar has moved into or out of water
- // // if (agent_in_water() != in_water)
- // // {
- // // // agent moved into, or out of water, update AO's immediately (we 'trick' the logic into thinking 10 seconds has passed)
- // // in_water = agent_in_water();
- // // ticks = 10;
- // // }
- // // ticks = ticks + 2;
- // // if (ticks < 10) return; // don't do the following if 10 seconds hasn't passed
- // // ticks = 0;
- // // // if we got this far, 10 seconds has passed OR the agent just moved into or out of water
- // // llSetAnimationOverride("Crouching", random_animation(crouching));
- // // llSetAnimationOverride("CrouchWalking", random_animation(crouch_walking));
- // // llSetAnimationOverride("Falling Down", random_animation(falling));
- // // llSetAnimationOverride("Jumping", random_animation(jumping));
- // // llSetAnimationOverride("Landing", random_animation(landing));
- // // llSetAnimationOverride("PreJumping", random_animation(pre_jumping));
- // // llSetAnimationOverride("Running", random_animation(running));
- // // llSetAnimationOverride("Sitting", random_animation(sitting));
- // // llSetAnimationOverride("Sitting on Ground", random_animation(sitting_on_ground));
- // // llSetAnimationOverride("Standing", random_animation(standing));
- // // llSetAnimationOverride("Standing Up", random_animation(standing_up));
- // // llSetAnimationOverride("Striding", random_animation(standing));
- // // llSetAnimationOverride("Soft Landing", random_animation(landing));
- // // llSetAnimationOverride("Taking Off", random_animation(flying_up));
- // // llSetAnimationOverride("Turning Left", random_animation(turning_left));
- // // llSetAnimationOverride("Turning Right", random_animation(turning_right));
- // // llSetAnimationOverride("Walking" , random_animation(walking));
- // // if (!agent_in_water())
- // // {
- // // // above water level
- // // llSetAnimationOverride("Hovering", random_animation(hovering));
- // // llSetAnimationOverride("Hovering Down", random_animation(flying_down));
- // // llSetAnimationOverride("Hovering Up", random_animation(flying_up));
- // // llSetAnimationOverride("Flying", random_animation(flying));
- // // llSetAnimationOverride("FlyingSlow", random_animation(flying_slow));
- // // }
- // // else
- // // {
- // // // below water level
- // // llSetAnimationOverride("Hovering", random_animation(floating));
- // // llSetAnimationOverride("Hovering Down", random_animation(swimming_down));
- // // llSetAnimationOverride("Hovering Up", random_animation(swimming_up));
- // // llSetAnimationOverride("Flying", random_animation(swimming_forward));
- // // llSetAnimationOverride("FlyingSlow", random_animation(swimming_forward));
- // // }
- // // }
- // // else
- // // {
- // // // no permission to override animations, request it
- // // llSetTimerEvent(FALSE);
- // // llRequestPermissions(llGetOwner(), PERMISSION_OVERRIDE_ANIMATIONS);
- // // }
- // }
- run_time_permissions(integer perm)
- {
- if (perm & PERMISSION_TAKE_CONTROLS)
- {
- llTakeControls(
- CONTROL_FWD |
- CONTROL_BACK |
- CONTROL_LEFT |
- CONTROL_RIGHT |
- CONTROL_ROT_LEFT |
- CONTROL_ROT_RIGHT |
- CONTROL_UP |
- CONTROL_DOWN |
- CONTROL_LBUTTON |
- CONTROL_ML_LBUTTON |
- 0, TRUE, TRUE); // all control events are generated, but the control is not intercepted
- // We react ONLY to the user starting or stopping pressing something, to provide snappy animation reactions
- // we don't react to holding the control to avoid animation start spam
- }
- if (perm & PERMISSION_OVERRIDE_ANIMATIONS)
- {
- llSetAnimationOverride("Turning Left", llList2String(turning_left, 0));
- llSetAnimationOverride("Turning Right", llList2String(turning_right, 0));
- }
- }
- control(key id, integer level, integer edge)
- {
- if (edge == 0) return; // don't do anything if this event is not related to the moment a control is pressed or released
- llSetTimerEvent(0.1); // slight delay to ensure correct response
- update_animations(); // quickly respond to input
- }
- timer()
- {
- // every 10s, update animations
- update_animations();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement