Jump to content

show/hide script from touch to chat command


Reivan
 Share

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

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

Recommended Posts

Hello i have a script to show/hide unlinked object but its work on touching and i need make it work on chat command, im not a scripter, tried do it by myself but my every attempt failed.

Maybe someone will help me with that :)

First script:

integer CHANNEL = -6573;
string SOUND = "sound";
string ANIM = "anim";

//-------------------------------

integer an = 0;
default
{
    state_entry()
    {
        llListen(CHANNEL, "", NULL_KEY, "");
    }

    touch_start(integer total_number)
    {
       if (llDetectedKey(0) == llGetOwner()) { 
           llSetLinkAlpha(LINK_SET, 0, ALL_SIDES);
           an=0; 
           llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);  
           llStopSound();
           llWhisper(CHANNEL, (string)llGetOwner()+"_change");
       }
    }
    
    listen(integer channel, string name, key id, string message)
    {
        list mlist = llParseString2List(message,["_"],["_"]);  
        if (llList2String(mlist, 0) == (string)llGetOwner()) {
            llSetLinkAlpha(LINK_SET, 1, ALL_SIDES);
            llPlaySound(SOUND,1.0); 
            an=1;
            llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
            
        }  
    }
    
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            if (an)
                llStartAnimation(ANIM);
            else
                llStopAnimation(ANIM);
        }
    }
    
    on_rez(integer rr) {
        llResetScript();   
    }
}

and second one:

integer CHANNEL = -6573;
string SOUND = "sound";
string ANIM = "anim";

//-------------------------------

integer an = 0;
default
{
    state_entry()
    {
        llListen(CHANNEL, "", NULL_KEY, "");
        an=1;
        llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);        
    }

    touch_start(integer total_number)
    {
       if (llDetectedKey(0) == llGetOwner()) { 
           llSetLinkAlpha(LINK_SET, 0, ALL_SIDES);
           an=0; 
           llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);  
           llStopSound();
           llWhisper(CHANNEL, (string)llGetOwner()+"_change");
       }
    }
    
    listen(integer channel, string name, key id, string message)
    {
        list mlist = llParseString2List(message,["_"],["_"]);  
        if (llList2String(mlist, 0) == (string)llGetOwner()) {
            llSetLinkAlpha(LINK_SET, 1, ALL_SIDES);
            llPlaySound(SOUND,1.0); 
            an=1;
            llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
            
        }  
    }
    
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            if (an)
                llStartAnimation(ANIM);
            else
                llStopAnimation(ANIM);
        }
    }
    
    on_rez(integer rr) {
        llResetScript();   
    }
}

 

Link to comment
Share on other sites

You was nearly there, take a look at your touch_start, you check if touch is by owner, use the same principle in the listen event.

    listen(integer channel, string name, key id, string message)
    {
        if (( llGetOwnerKey(id) == llGetOwner() ) && ( channel==CHANNEL) )
        {
            llSetLinkAlpha(LINK_SET, 1, ALL_SIDES);
            llPlaySound(SOUND,1.0);
            an=1;
            llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
        }
    }

And we can simply it even more by filtering the listening, listen only to channel 1 and only for the owner. Now you can omit checking owner only and just have as below. See also Wiiki on llListen

listenHandle = llListen(1, "", llGetOwner(), "");

    listen(integer channel, string name, key id, string message)
    {
            llSetLinkAlpha(LINK_SET, 1, ALL_SIDES);
            llPlaySound(SOUND,1.0);
            an=1;
            llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
    }

Happy coding 👍

Edited by Rachel1206
Spelling
Link to comment
Share on other sites

Thank you for help :), but i think i didnt described correctly my problem and what those scripts shoud be used, my bad sorry.

Scripts are used as alpha switcher, i need it to switch an alpha betwen two unlinked weared obiects (weared on different body spots), and now it works on touching but those obiects will be in fast move so i must change it to chat command, and i need rework those scripts. Like i said im not an scripter so its hard for me.

Link to comment
Share on other sites

2 hours ago, Reivan said:

Thank you for help :), but i think i didnt described correctly my problem and what those scripts shoud be used, my bad sorry.

Scripts are used as alpha switcher, i need it to switch an alpha betwen two unlinked weared obiects (weared on different body spots), and now it works on touching but those obiects will be in fast move so i must change it to chat command, and i need rework those scripts. Like i said im not an scripter so its hard for me.

The most easy way for you, place a copy of the script (with my changes) in each object, you wear.

    listen(integer channel, string name, key id, string message)
    {
            if (message=="hide")
                llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES);
            if (message=="show")
                llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);

            llPlaySound(SOUND,1.0);
            an=1;
            llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
    }

Now, when you (owner) say in chat "/1 hide", the objects you wear will be hidden. Say"/1 show" and they will be shown.

Link to comment
Share on other sites

9 hours ago, Rachel1206 said:

The most easy way for you, place a copy of the script (with my changes) in each object, you wear.

    listen(integer channel, string name, key id, string message)
    {
            if (message=="hide")
                llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES);
            if (message=="show")
                llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);

            llPlaySound(SOUND,1.0);
            an=1;
            llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
    }

Now, when you (owner) say in chat "/1 hide", the objects you wear will be hidden. Say"/1 show" and they will be shown.

It should look like this?

integer CHANNEL = -6573;
string SOUND = "sound";
string ANIM = "anim";

//-------------------------------

integer an = 0;
default
{
    state_entry()
    {
        llListen(CHANNEL, "", NULL_KEY, "");
    }

    touch_start(integer total_number)
    {
       if (llDetectedKey(0) == llGetOwner()) { 
           llSetLinkAlpha(LINK_SET, 0, ALL_SIDES);
           an=0; 
           llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);  
           llStopSound();
           llWhisper(CHANNEL, (string)llGetOwner()+"_change");
       }
    }
    
      listen(integer channel, string name, key id, string message)
    {
            if (message=="hide")
                llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES);
            if (message=="show")
                llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);

            llPlaySound(SOUND,1.0);
            an=1;
            llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
    }
    
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            if (an)
                llStartAnimation(ANIM);
            else
                llStopAnimation(ANIM);
        }
    }
    
    on_rez(integer rr) {
        llResetScript();   
    }
}

This one does not work, also like i write above, it must be alpha switcher, one obiect must go alpha on command, another must show, and after use same or another chat command they switch back.

Link to comment
Share on other sites

What you are sending to the listen event is a string consisting of the owner name plus "_change", but in the listen event you have to if test for such a string. Add the test, and when that string is received, toggle the alpha on or off from it's last state.

if( message == (string) llGetOwner() + "_change")
{
	if( an)
    {
        lSetLinkAlpha ( //to what it is when an goes from 1 to 0)
        an = 0;
    }
	else
    {    
        llSetLinkAlpha ( // to what it is when an goes from 0 to 1)
        an = 1;
    }
//

Also, in your touch event, remove the line setting an to 0, you have already done that in the initialisation, and so each time you touch it, an animation will play or be stopped, and the listen event will toggle the link alpha and then also change the value of an so that the next touch event does the opposite to what it did last time.

 

There is a more elegant way of toggling the value of an but it is less clear than the two operations in the example above. Once you are comfortable with scripting, have a look at an = !an

Edited by Profaitchikenz Haiku
Link to comment
Share on other sites

36 minutes ago, Reivan said:

This one does not work, also like i write above, it must be alpha switcher, one obiect must go alpha on command, another must show, and after use same or another chat command they switch back.

need to identify each of the linked prims and toggle between them. Code snippet example:

// global A and B prim link numbers. Change these to the actual link numbers
integer A = 1;  
integer B = 2;


touch_start ...
  if (llDetectedKey(0) == llGetOwner())
  {
     an = !an; // toggle an: 0 or 1
     llSetLinkAlpha(A, (float)an, ALL_SIDES);
     llSetLinkAlpha(B, (float)!an, ALL_SIDES);
    

listen ...
  if (message == "toggle")
  {
     an = !an;
     llSetLinkAlpha(A, (float)an, ALL_SIDES);
     llSetLinkAlpha(B, (float)!an, ALL_SIDES);

when an == 0 then !an = 1.  when an == 1 then !an = 0

 

edit: what Prof said

Edited by Mollymews
Link to comment
Share on other sites

1 minute ago, Mollymews said:

edit: what Prof said

Prof was having to edit what Prof said because he had missed something rather important :)

 

The script could be simplified greatly by just checking the toucher key and listen checking that the id was the same, but I think one step at a time here.

  • Like 1
Link to comment
Share on other sites

1 minute ago, Profaitchikenz Haiku said:

The script could be simplified greatly by just checking the toucher key and listen checking that the id was the same, but I think one step at a time here.

yes one step at a time I agree. Get the basic understandings sorted out then look at optimisations

Link to comment
Share on other sites

Thanks, i try to figure it out, like i said im not a scripter, i can add sound or do other simple things but this one is black magic for me :) those scripts was writen by friend, he leaved SL long ago and i dont know any scripter to ask for help.

If someone can write for me a basic working script to switch separate objects alphas with description what every line do then will be easier for me to understand how it works and modify my scripts, now i dont even understand what an = !an; is.

 

It should look like that?

integer CHANNEL = -6573;
string SOUND = "sound";
string ANIM = "anim";

//-------------------------------

integer an = 0;
integer A = 1;  
integer B = 2;
default
{
    state_entry()
    {
        llListen(CHANNEL, "", NULL_KEY, "");
    }

    touch_start(integer total_number)
    {
       if (llDetectedKey(0) == llGetOwner()) { 
     llSetLinkAlpha(A, (float)an, ALL_SIDES);
     llSetLinkAlpha(B, (float)!an, ALL_SIDES);
           an = !an; 
           llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);  
           llStopSound();
           llWhisper(CHANNEL, (string)llGetOwner()+"_change");
       }
    }
    
    listen(integer channel, string name, key id, string message)
    {
        list mlist = llParseString2List(message,["_"],["_"]);  
        if (message == "toggle" llList2String(mlist, 0) == (string)llGetOwner()) {
     an = !an;
     llSetLinkAlpha(A, (float)an, ALL_SIDES);
     llSetLinkAlpha(B, (float)!an, ALL_SIDES);
            llPlaySound(SOUND,1.0); 
            llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
            
        }  
    }
    
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            if (an)
                llStartAnimation(ANIM);
            else
                llStopAnimation(ANIM);
        }
    }
    
    on_rez(integer rr) {
        llResetScript();   
    }
}

 

Edited by Reivan
Link to comment
Share on other sites

Reivan, might be best to post in the Wanted sub-forum on here

post that you would like somebody to help you write the script

if you are happy to drop some little L$ on the person then post in Inworld Employment

once you get a script that is working as you want it, then will be a step forward on your journey

 

edit add: I am suggesting this as the scripts you are trying to mod are not a good basis to do what you want. It needs a different design to be efficient

Edited by Mollymews
  • Like 1
Link to comment
Share on other sites

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