Jump to content

llSetPos Script Assistance (Blade Sheath)


Killer Dryke
 Share

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

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

Recommended Posts

Within Second Life, I am creating a retractable forearm blade, using a llSetPos script in order to deploy and retract the blade, and a llSetScale script in order to allow the blade to fit in the sheath, and grow as it comes out. The script works in sync with no issues, however, I would like to know if it is possible to have the llSetPos script check the position of the blade, in order to prevent retracting while it's already retracted, or from deploying while it's already deployed, causing the blade to come off it's "track." (even though it's easily fixable)

Here is my script so far (I'm a novice scripter, and made this script as a derivation from another one, it works fine, but some parts may be unnecessary)

 

init() {          key owner = llGetOwner();                    llListen(73, "",llGetOwner(), ""); }                        default     {                   state_entry()                 {               init();           }                      on_rez(integer start_param)           {               init();           }                            listen( integer channel, string name, key id, string message )                    {                         if( message == "knife_retract" )                    {                                llMessageLinked(LINK_SET, 0, "shrink", id);                                        llSetPos(llGetLocalPos() - <0,.0148,.3134>);                   }                                                 if( message == "knife_deploy" )                                {                                    llMessageLinked(LINK_SET, 0, "grow", id);                                     llSetPos(llGetLocalPos() + <0,.0148,.3143>);                       }                                 }}

Link to comment
Share on other sites

I would suggest combining you grow() and shrink() functions with your llSetPos() functions into one single script as one single function.

 

Establish an original size (Osize) with blade in sheath...

 

SC(){    if(Osize.z/20<0.1)    {        scale = 0.1;    }    else    {        scale = Osize.z/20;    }}

 

and then call the resize function when needed...

 

resize(float scal){    llSetScale(scal*llGetScale());    Nsize = llGetScale();    if(Osize.z>Nsize.z)    {        new.z = (Osize.z - Nsize.z)/2;        llSetPos(llGetPos() - <0,0,new.z>*llGetRot());    }    else    {        new.z = (Nsize.z - Osize.z)/2;        llSetPos(llGetPos() + <0,0,new.z>*llGetRot());    }            Osize = Nsize;}

 

You can adjust the resize(scal) as a percentage change to meet your needs where 1.0 = 100%, 0.9 = 90%, 1.1 = 110%, etc...

 

vector Osize;vector Nsize;float scale;vector pos;vector new;init(){    key owner = llGetOwner();    llListen(73, "",llGetOwner(), "");    Osize = llGetScale();    SC();}SC(){    if(Osize.z/20<0.1)    {        scale = 0.1;    }    else    {        scale = Osize.z/20;    }}resize(float scal){    llSetScale(scal*llGetScale());    Nsize = llGetScale();    if(Osize.z>Nsize.z)    {        new.z = (Osize.z - Nsize.z)/2;        llSetPos(llGetPos() - <0,0,new.z>*llGetRot());    }    else    {        new.z = (Nsize.z - Osize.z)/2;        llSetPos(llGetPos() + <0,0,new.z>*llGetRot());    }            Osize = Nsize;}default{    state_entry()    {        init();    }        on_rez(integer start_param)    {        init();    }        listen( integer channel, string name, key id, string message )    {        if( message == "knife_retract" )        {            resize(.1); // Shrink to Original Size       }                if( message == "knife_deploy" )        {            resize(1.1); //Grow to Desired Length        }    }}

 

Link to comment
Share on other sites

The most  simple way is to store in a global variable the state of the blade. So the script will only initiate the shrinking if the blade is not already shrunk... and vice-versa.


(Note: Use the icon of a clipboard with a "C" to insert a script.)

 

integer isSHRUNK = TRUE; // Assuming the blade is shrunk						// when the script is compiled.vector Offset = <0.0, 0.0148, 0.3134>;init(){    llListen(73, "", llGetOwner(), "");}default{                  	state_entry() { init(); }               		on_rez(integer param) { init(); }	 	listen(integer channel, string name, key id, string msg)	{		if (msg == "knife_retract")		{			if (! isSHRUNK)			{				llMessageLinked(LINK_SET, 0, "shrink", id);                                     				llSetPos(llGetLocalPos() - Offset);				isSHRUNK = TRUE;			}		}              		else if (msg == "knife_deploy")		{			if (isSHRUNK)			{				llMessageLinked(LINK_SET, 0, "grow", id);				llSetPos(llGetLocalPos() + Offset);				isSHRUNK = FALSE;			}		}	}}

Personal advice: Do not use strings to send link messages if you are not directly interested in the content of these strings. Use the integer parameter. It's faster, uses less memory and there's no lower/upper case issues.

Besides, my radar seems to detect a script in every prim. If I'm right, check llSetLinkPrimitiveParamsFast() in the wiki. (It's better to take good habits since the beginning...)

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4537 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...