Jump to content

Making a simple posing attachment that you can turn on and off


Sion Pearl
 Share

You are about to reply to a thread that has been inactive for 4656 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Here is a script for a thing that animates you when you wear it. It's pretty standard. I took it from another object I had. But what if I wanted to turn the pose on and off? Say by clicking the object? Put object on - pose working, click, it's off, click again, it's on. Any ideas?

string anim = "chinup"; // Name of head holding still pose thingy

integer hidden = FALSE;
key wearer;  // Wearer key

//MESSAGE MAP
integer COMMAND_NOAUTH = 0;
integer COMMAND_OWNER = 500;
integer COMMAND_SECOWNER = 501;
integer COMMAND_GROUP = 502;
integer COMMAND_WEARER = 503;
integer COMMAND_EVERYONE = 504;
integer CHAT = 505;

default
{
    state_entry()
    {
        wearer = llGetOwner();
        llRequestPermissions(wearer,PERMISSION_TRIGGER_ANIMATION);
    }

    run_time_permissions(integer perm)
    {
        if(PERMISSION_TRIGGER_ANIMATION & perm)
        {
            llStartAnimation(anim);
            llSetTimerEvent(1.0);
        }
    }
    
    timer()
    {
        llStopAnimation(anim);
        llStartAnimation(anim);
    }
    
    attach(key id)
    {
        if(id)
        {
            if(!hidden)
            {
                llStartAnimation(anim);
                llSetTimerEvent(1.0);
            }
        }
        else
        {
            llStopAnimation(anim);
            llSetTimerEvent(0.0);
        }
    }

    
    link_message(integer sender,integer auth,string str,key id)
    {
        if (auth >= COMMAND_OWNER && auth <= COMMAND_WEARER)
        {
            if (str == "hide")
            {
                hidden = TRUE;
                llStopAnimation(anim);
                llSetTimerEvent(0.0);                   
            }
            else if (str == "show")
            {
                hidden = FALSE;
                llStartAnimation(anim);
                llSetTimerEvent(1.0);                    
            }
        }
    }
    
    changed(integer change)
    {
        if(change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
}

 

Link to comment
Share on other sites

Call it anything you  like.  gON is just a variable name I use when I need a global variable to use as a toggle switch.  Whatever name you choose will work.  Just be sure that it's declared among any other global variables at the very top of your script (before state default) in the format

integer gON;

Link to comment
Share on other sites

OK, so I tried it, and while the script throws up no errors as such, and you can touch it (you get the little hand if you mouse hover), touching it does nothing. I am at a loss. 

Now it should be apparent I know little about scripting, but there was a lot of nonsense in that script. I tried something simpler. It still does not work. 

I am eager to learn. Please tell me why?

 

integer gpose = 1;string anim = "chinup"; // Name of head holding still pose thingy   default   {      state_entry()      {         llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);      }      run_time_permissions(integer parm)      {         if(parm == PERMISSION_TRIGGER_ANIMATION)         {            llStartAnimation("chinup");         }      }      on_rez(integer st)      {         llResetScript();      }    touch_start(integer num){    llSetTimerEvent(1.0 * (gpose = !gpose));  }      attach(key id)      {         llStopAnimation("chinup");      }   }   //-------------------------------------------------------------

 

Link to comment
Share on other sites

Did you touch it at least twice - if I read the script correct, this is what happens:

  • object is rezzed -> script get restarted
  • gpose is set to 1 and permission is asked - animation starts; stimer starts
  • object gets attached and anim as well as timer stop

that means, at this point gpose is at 1 but the anim isn't played. When you click it, gpose gets set to 0 - which means, timer won't ruun and anim won't play. If you click it once more, gpose should turn to 1 and the anim should run

Link to comment
Share on other sites

I hope that does the trick

integer gpose;string anim = "chinup"; // Name of head holding still pose thingydefault{    run_time_permissions(integer parm)    {    	if(parm == PERMISSION_TRIGGER_ANIMATION)       	{		llStartAnimation(anim);		llSetTimerEvent(1.0 * (gpose = !gpose));		gpose = 1;        }    }	touch_start(integer num)	{		if (llGetPermissions(PERMISSION_TRIGGER_ANIMATION)) {			llSetTimerEvent(1.0 * (gpose = !gpose));		} else {			llOwnerSay("No permission to start or stop animations.");		}	}    attach(key id)	{		gpose = 0;		if (id != NULL_KEY) {			llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);		}    }}

 

Link to comment
Share on other sites

Or ...

integer gPose;integer gON;default{	attach(key id)	{		if(id)  // If the device is attached, initialize and request perms		{			gON = FALSE;			gPose = FALSE;			llSetTimerEvent(0.0);			llRequestPermissions(id,PERMISSION_TRIGGER_ANIMATION);		}	}	run_time_permissions(integer perm)	{		if (perm == PERMISSION_TRIGGER_ANIMATION)		{			gPose = TRUE;			llSetTimerEvent(1.0);		}	}	timer()	{		if(llGetAttached())  // If the device is worn		{			if(gON)			{				llStopAnimation("chinup");			}			else			{				llStartAnimation("chinup");			}			gON = !gON; // Start/Stop anim in alternate timer cycles		}		else  // If the device is dropped		{			llSetTimerEvent(0.0);		}	}	touch_start(integer total_number)	{		integer perm = llGetPermissions();		if (perm == PERMISSION_TRIGGER_ANIMATION)		{			llSetTimerEvent(1.0 * (gPose = !gPose)); // Toggle timer on/off with touch		}	}}

 I assume that the reason you wanted to have llSetTimerEvent  there is so that the animation triggers on and off on a one-second cycle, right?  If so, you actually need a timer event and you need a toggle in there too.  That's what my gON is.

Link to comment
Share on other sites

Here's the same script with no timer event ...

integer gPose;default{	attach(key id)	{		if(id)  // If the device is attached, initialize and request perms		{			gPose = FALSE;			llRequestPermissions(id,PERMISSION_TRIGGER_ANIMATION);		}	}	run_time_permissions(integer perm)	{		if (perm == PERMISSION_TRIGGER_ANIMATION)		{			gPose = TRUE;			llStartAnimation("chinup");		}	}	touch_start(integer total_number)	{		integer perm = llGetPermissions();		if (perm == PERMISSION_TRIGGER_ANIMATION)		{			if(gPose)			{				llStopAnimation("chinup");			}			else			{				llStartAnimation("chinup");			}			gPose = !gPose;		}	}}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4656 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...