OSSL Script Library/OSSL Poseball: Difference between revisions
From OpenSimulator
Jump to navigationJump to search
imported>Fritigern Created page with "A poseball script, using OSSL functions The code contains a lot of comments, explaining what does what, and why it is there. <source lang="lsl"> // OSSL Poseball // By Fritiger..." |
No edit summary |
||
| (One intermediate revision by one other user not shown) | |||
| Line 42: | Line 42: | ||
user = llAvatarOnSitTarget(); | user = llAvatarOnSitTarget(); | ||
if(user == NULL_KEY) used = FALSE; // Make sure that there's really someone sitting on the poseball | if(user == NULL_KEY) used = FALSE; // Make sure that there's really someone sitting on the poseball | ||
llSetAlpha(0.0,ALL_SIDES); // Hide the poseball when sat upon | |||
osAvatarStopAnimation(user, "sit"); // Stop the default sit animation (IMPORTANT!) | osAvatarStopAnimation(user, "sit"); // Stop the default sit animation (IMPORTANT!) | ||
osAvatarPlayAnimation(user, anim); // And start the animation that we want started. | osAvatarPlayAnimation(user, anim); // And start the animation that we want started. | ||
} else { | } else { | ||
used = FALSE; | used = FALSE; | ||
llSetAlpha(1.0,ALL_SIDES); // Make the poseball visible again when user stands up | |||
osAvatarStopAnimation(user, anim); //Stop the animation when the user stands up. | osAvatarStopAnimation(user, anim); //Stop the animation when the user stands up. | ||
user = NULL_KEY; // Probably redundant, but we want to make sure that the value for ''user'' is empty. | user = NULL_KEY; // Probably redundant, but we want to make sure that the value for ''user'' is empty. | ||
| Line 70: | Line 72: | ||
{ | { | ||
llOwnerSay("Change detected. Initializing"); | llOwnerSay("Change detected. Initializing"); | ||
llResetScript(); | |||
} | |||
} | |||
} | |||
</source> | |||
OSSL Multi Gender Poseball | |||
<source lang="lsl"> | |||
vector target = <0.0, 0.0, 1.0>; // Change these values to adjust your avatar's position. | |||
list male_animations; // List for male animations | |||
list female_animations; // List for female animations | |||
list unknown_animations; // List for third gender animations | |||
integer used; // Used as a flag to determine what the script should do. | |||
key user; // Stores the key of the user using the pose ball | |||
string chosen_anim; // Stores the chosen animation | |||
default | |||
{ | |||
state_entry() | |||
{ | |||
llSitTarget(target, ZERO_ROTATION); | |||
// Collect animations in inventory | |||
integer num_anims = llGetInventoryNumber(INVENTORY_ANIMATION); | |||
integer i; | |||
for (i = 0; i < num_anims; ++i) { | |||
string anim_name = llGetInventoryName(INVENTORY_ANIMATION, i); | |||
if (llSubStringIndex(anim_name, "male_") == 0) { | |||
male_animations += anim_name; | |||
} else if (llSubStringIndex(anim_name, "female_") == 0) { | |||
female_animations += anim_name; | |||
} else if (llSubStringIndex(anim_name, "unknown_") == 0) { | |||
unknown_animations += anim_name; | |||
} | |||
} | |||
if (male_animations == [] && female_animations == [] && unknown_animations == []) { | |||
state error; // Go and wait until inventory changes. | |||
} else { // Otherwise... | |||
llOwnerSay("Found animations: Male: " + (string)llGetListLength(male_animations) + ", Female: " + (string)llGetListLength(female_animations) + ", Unknown: " + (string)llGetListLength(unknown_animations)); // Confirm that there are animations in inventory | |||
} | |||
} | |||
changed(integer change) | |||
{ | |||
if (change & CHANGED_LINK) // Triggered when someone sits on the pose ball. When you sit down, you actually link with the ball. | |||
{ | |||
if(!used) | |||
{ | |||
used = TRUE; | |||
user = llAvatarOnSitTarget(); | |||
if(user == NULL_KEY) used = FALSE; // Make sure someone is actually sitting on the pose ball | |||
llSetAlpha(0.0,ALL_SIDES); // Hide the pose ball when someone sits on it | |||
osAvatarStopAnimation(user, "sit"); // Stop the default sitting animation (IMPORTANT!) | |||
// Get user's gender | |||
string gender = osGetGender(user); | |||
// Select and play a random animation | |||
if (gender == "male") { | |||
chosen_anim = llList2String(male_animations, llFloor(llFrand(llGetListLength(male_animations)))); | |||
} else if (gender == "female") { | |||
chosen_anim = llList2String(female_animations, llFloor(llFrand(llGetListLength(female_animations)))); | |||
} else { | |||
chosen_anim = llList2String(unknown_animations, llFloor(llFrand(llGetListLength(unknown_animations)))); | |||
} | |||
osAvatarPlayAnimation(user, chosen_anim); // And start the chosen animation. | |||
state running; // Switch to the "running" state to monitor the animation playback | |||
} else { | |||
used = FALSE; | |||
llSetAlpha(1.0,ALL_SIDES); // Make the pose ball visible again when the user stands up | |||
osAvatarStopAnimation(user, chosen_anim); // Stop the animation when the user stands up. | |||
user = NULL_KEY; // Probably redundant, but we want to ensure the value for ''user'' is empty. | |||
} | |||
} | |||
if(change & CHANGED_INVENTORY) | |||
{ | |||
llResetScript(); // Reset the script if inventory changes. | |||
} | |||
} | |||
} | |||
state running | |||
{ | |||
state_entry() | |||
{ | |||
// Additional actions can be performed here when the animation is playing | |||
} | |||
on_rez(integer start_param) | |||
{ | |||
llResetScript(); | |||
} | |||
changed(integer change) | |||
{ | |||
if(change & CHANGED_LINK) | |||
{ | |||
used = FALSE; | |||
llSetAlpha(1.0,ALL_SIDES); // Make the pose ball visible again when the user stands up | |||
osAvatarStopAnimation(user, chosen_anim); // Stop the animation when the user stands up. | |||
user = NULL_KEY; // Probably redundant, but we want to ensure the value for ''user'' is empty. | |||
llSleep(0.1); | |||
state default; | |||
} | |||
} | |||
} | |||
state error | |||
{ | |||
state_entry() | |||
{ | |||
llOwnerSay("This pose ball contains no animations. Please add one."); | |||
} | |||
changed(integer change) | |||
{ | |||
if(change & CHANGED_INVENTORY) | |||
{ | |||
llOwnerSay("Change detected. Initializing."); | |||
llResetScript(); | llResetScript(); | ||
} | } | ||
Latest revision as of 18:05, 8 March 2024
A poseball script, using OSSL functions
The code contains a lot of comments, explaining what does what, and why it is there.
// OSSL Poseball
// By Fritigern Gothly
// Written on March 18th, 2012
// Additional contributors:
// <add your name here if you made any improvements to this script>
vector target = <0.0, 0.0, 1.0>; // Change these values to position your avatar.
// =============================
// DO NOT CHANGE BELOW THIS LINE
// =============================
string anim; // Will be used for the animation name.
integer used; // Used as a flag to determine what the script should do.
key user; // This will hold the key of the user that uses the poseball
default
{
state_entry()
{
llSitTarget(target, ZERO_ROTATION);
anim = llGetInventoryName(INVENTORY_ANIMATION,0); // Get the first animation in the prim's inventory.
if(anim == "") // If no animation was found...
{
state error; // Go and wait until the inventory has changed.
} else { // Otherwise....
llOwnerSay("Found animation ''"+anim+"''"); // Confirm that there is an animation in the inventory
}
}
changed(integer change)
{
if (change & CHANGED_LINK) // Triggered when someone sits on the4 poseball. When you sit, you really link to the ball.
{
if(!used)
{
used = TRUE;
user = llAvatarOnSitTarget();
if(user == NULL_KEY) used = FALSE; // Make sure that there's really someone sitting on the poseball
llSetAlpha(0.0,ALL_SIDES); // Hide the poseball when sat upon
osAvatarStopAnimation(user, "sit"); // Stop the default sit animation (IMPORTANT!)
osAvatarPlayAnimation(user, anim); // And start the animation that we want started.
} else {
used = FALSE;
llSetAlpha(1.0,ALL_SIDES); // Make the poseball visible again when user stands up
osAvatarStopAnimation(user, anim); //Stop the animation when the user stands up.
user = NULL_KEY; // Probably redundant, but we want to make sure that the value for ''user'' is empty.
}
}
if(change & CHANGED_INVENTORY)
{
llResetScript(); // Reset the script if the inventopry has changed.
}
}
}
state error
{
state_entry()
{
llOwnerSay("This poseball contains no animations. Please add one.");
}
changed(integer change)
{
if(change & CHANGED_INVENTORY)
{
llOwnerSay("Change detected. Initializing");
llResetScript();
}
}
}
OSSL Multi Gender Poseball
vector target = <0.0, 0.0, 1.0>; // Change these values to adjust your avatar's position.
list male_animations; // List for male animations
list female_animations; // List for female animations
list unknown_animations; // List for third gender animations
integer used; // Used as a flag to determine what the script should do.
key user; // Stores the key of the user using the pose ball
string chosen_anim; // Stores the chosen animation
default
{
state_entry()
{
llSitTarget(target, ZERO_ROTATION);
// Collect animations in inventory
integer num_anims = llGetInventoryNumber(INVENTORY_ANIMATION);
integer i;
for (i = 0; i < num_anims; ++i) {
string anim_name = llGetInventoryName(INVENTORY_ANIMATION, i);
if (llSubStringIndex(anim_name, "male_") == 0) {
male_animations += anim_name;
} else if (llSubStringIndex(anim_name, "female_") == 0) {
female_animations += anim_name;
} else if (llSubStringIndex(anim_name, "unknown_") == 0) {
unknown_animations += anim_name;
}
}
if (male_animations == [] && female_animations == [] && unknown_animations == []) {
state error; // Go and wait until inventory changes.
} else { // Otherwise...
llOwnerSay("Found animations: Male: " + (string)llGetListLength(male_animations) + ", Female: " + (string)llGetListLength(female_animations) + ", Unknown: " + (string)llGetListLength(unknown_animations)); // Confirm that there are animations in inventory
}
}
changed(integer change)
{
if (change & CHANGED_LINK) // Triggered when someone sits on the pose ball. When you sit down, you actually link with the ball.
{
if(!used)
{
used = TRUE;
user = llAvatarOnSitTarget();
if(user == NULL_KEY) used = FALSE; // Make sure someone is actually sitting on the pose ball
llSetAlpha(0.0,ALL_SIDES); // Hide the pose ball when someone sits on it
osAvatarStopAnimation(user, "sit"); // Stop the default sitting animation (IMPORTANT!)
// Get user's gender
string gender = osGetGender(user);
// Select and play a random animation
if (gender == "male") {
chosen_anim = llList2String(male_animations, llFloor(llFrand(llGetListLength(male_animations))));
} else if (gender == "female") {
chosen_anim = llList2String(female_animations, llFloor(llFrand(llGetListLength(female_animations))));
} else {
chosen_anim = llList2String(unknown_animations, llFloor(llFrand(llGetListLength(unknown_animations))));
}
osAvatarPlayAnimation(user, chosen_anim); // And start the chosen animation.
state running; // Switch to the "running" state to monitor the animation playback
} else {
used = FALSE;
llSetAlpha(1.0,ALL_SIDES); // Make the pose ball visible again when the user stands up
osAvatarStopAnimation(user, chosen_anim); // Stop the animation when the user stands up.
user = NULL_KEY; // Probably redundant, but we want to ensure the value for ''user'' is empty.
}
}
if(change & CHANGED_INVENTORY)
{
llResetScript(); // Reset the script if inventory changes.
}
}
}
state running
{
state_entry()
{
// Additional actions can be performed here when the animation is playing
}
on_rez(integer start_param)
{
llResetScript();
}
changed(integer change)
{
if(change & CHANGED_LINK)
{
used = FALSE;
llSetAlpha(1.0,ALL_SIDES); // Make the pose ball visible again when the user stands up
osAvatarStopAnimation(user, chosen_anim); // Stop the animation when the user stands up.
user = NULL_KEY; // Probably redundant, but we want to ensure the value for ''user'' is empty.
llSleep(0.1);
state default;
}
}
}
state error
{
state_entry()
{
llOwnerSay("This pose ball contains no animations. Please add one.");
}
changed(integer change)
{
if(change & CHANGED_INVENTORY)
{
llOwnerSay("Change detected. Initializing.");
llResetScript();
}
}
}