Jump to content

"Remote" Texture Change Menu Script


Fleischgeiger
 Share

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

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

Recommended Posts

Hi guys ;)

 

First of all...my english is pretty bad...sorry for it =)

Second of all...im a totally noob in scripting :(

 

I really need a script for texturechanging.

My idea is to click "prim 1" ( that i will attach to "hud" ) to change "prim 2" that i will attach to my Body. Mesheyes to be exactly.

 

That is the "Texturechange Menu" script i have. Works perfectly as far as i know. But now i want it to be a "remote" so it changes the texture on another Prim ( the mesh eyes ).

//______Change Texture Menu___Alicia Stella______
//__________last modifed__May 2009___________
//_____more scripts: www.aliciastella.com_____

//Drop this script into an object with up to 22 textures inside.

//When anyone Touches they will get a menu with all the textures available. Button names in menu will be first 10 characters from that item's name. 

//NOTE: Texture Names may not exceed 24 characters or script error and menu fails.


integer side = ALL_SIDES; //ALL_SIDES or any face number 0 through 5

list texture_list;
list texture_list2;
key user = NULL_KEY;

composelist()
{
    integer currenttexture = 0;
    integer totaltextures = llGetInventoryNumber(INVENTORY_TEXTURE);
    
    if(totaltextures > 0 & totaltextures <= 12)
    {
        texture_list = [];
        do
        {
            texture_list = texture_list + llGetInventoryName(INVENTORY_TEXTURE, currenttexture);
            currenttexture++;
        }
        while (currenttexture > 0 & currenttexture < totaltextures);
    }
    
    if(totaltextures > 12 & totaltextures <= 22)
    {
        texture_list = ["Next Page"];
        do
        {
            texture_list = texture_list + llGetInventoryName(INVENTORY_TEXTURE, currenttexture);
            currenttexture++;
        }
        while (currenttexture > 0 & currenttexture < 11);
        
        texture_list2 = ["Last Page"];
        do
        {
            texture_list2 = texture_list2 + llGetInventoryName(INVENTORY_TEXTURE, currenttexture);
            currenttexture++;
        }
        while (currenttexture >= 11 & currenttexture < totaltextures);
    }
    
    if(totaltextures > 22)
    {
        llWhisper(0, "You may only have a maximimum of 22 Textures. Please remove any extra ones.");
    }
    if(totaltextures == 0)
    {
        llWhisper(0, "Please add up to 22 Textures inside this object.");
    }
}


//The Menu
integer menu_handler;
integer menu_channel;
menu(key user,string title,list texture_list)
{
    menu_channel = (integer)(llFrand(99999.0) * -1); //random channel
    menu_handler = llListen(menu_channel,"","","");
    llDialog(user,title,texture_list,menu_channel);
    llSetTimerEvent(30.0); //menu channel open for 30 seconds
}

default
{
    state_entry()
    {
        composelist(); //make list from inventory textures
    }

    touch_start(integer total_number)
    {
        user = llDetectedKey(0);
        menu(user,"\n\nPlease select one below.",texture_list);
    }
    
    listen(integer channel,string name,key id,string message)
    {
        if (channel == menu_channel)
        {
            llSetTimerEvent(0.0);
            llListenRemove(menu_handler);
            if(message == "Next Page")
            {
                menu(user,"\n\nPlease select one below.",texture_list2);
            }
            else if(message == "Last Page")
            {
                menu(user,"\n\nPlease select one below.",texture_list);
            }
            else
            {
                llSetTexture(message, side);
            }
        }
    }
    
    timer() //Close the Menu Listen or we'll get laggy
    {
        llSetTimerEvent(0.0); 
        llListenRemove(menu_handler);
    }
    
    changed(integer change) 
    {
        if (change & CHANGED_INVENTORY) //inventory has changed
        {
            llSleep(0.5);
            composelist(); //rebuild the list
        }
    }
}

i really hope you guys can understand my problem and maybe help me out a little bit =)

 

Thank you very much ^^

Link to comment
Share on other sites

send a RegionSayTo  ... to the eyes, and have a script in the eyes that listens?

http://wiki.secondlife.com/wiki/LlRegionSayTo

something like this ...

key id = " *uuid of eye prim* ";

integer chan = -12321;

// replace your llSettexure with a region say

 llRegionSayTo(id, chan, message + " " + side);

 

 

and in the eye prim,

 listen(integer channel, string name, key id, string message)
 { list myList = llParseString2List(message,[" "],[];
   string texture = llList2String(myList,0);
   integer side = llList2String(myList,1);
   llSetTexture(texture, side);

}

etc, etc

  • Like 1
Link to comment
Share on other sites

You say you're a beginner at scripting, so I'll try to take this in easy stages and we'll end up with something that works though probably won't be as optimised as something I would make for a customer.

But it should give you the idea.

To apply a texture to a prim (or mesh) by script, you normally need to know the texture's uuid.   If you don't know the uuid, then the texture and the script have to be in the same prim that you want to re-retexture, and then you can use the texture's name.

The script by Alicia Stella you reproduce is written to use the texture's name, so it's probably not an ideal model, but we can use it for this exercise.

I don't know if you know how to read a script (probably not, since you are a beginner), but most of this script is about creating a menu for the user to select a texture.   The texture, once selected, is applied by one single line at the end of the listen event, 

 

  llSetTexture(message, side);

 We need to communicate the name of the texture (held by the variable message) to the script in the eye mesh.

To do this, I would use the function llRegionSayTo(uuid, channel, message).  Normally you need to know the UUID of the object to which you want to send the message, which can be a problem because objects change their UUID each time you rez them.

However, if you use llRegionSayTo to send a message to an avatar's uuid, that message can be heard by all objects the avatar is wearing (or sitting on) that are listening to that channel.   This is very useful here.

So, I would change the line llSetTexture(message, side) to something like 

llRegionSayTo(llGetOwner(),99,message);

That sends a message on 99 (use any integer) to the owner of the object, and to any items the owner is wearing that are listening on channel 99.

Now, in the eyes, I would place copies of all the textures I had put in the HUD prim.

I would also place a script something like this:

default{	state_entry()	{		llListen(99,"","","");		//listen on channel 99 to messages from any source		//this has to be the same channel the HUD uses to send messages	}	listen(integer channel, string name, key id, string message)	{		//a message on channel 99!		if(llGetOwnerKey(id)==llGetOwner()){			//if the message is from an object belonging to my owner			if(llGetInventoryType(message)==INVENTORY_TEXTURE){				//and if the message is the name of a texture in my inventory				llSetTexture(message,0);				//apply the texture to side 0 of the mesh -- change the side number if necessary			}		}	}}

As I said, this is not the best way to do it.   If I intended to sell the objects, I would certainly use the textures' uuids and not their names.    However, that is more complex.   But when you become more experienced with scripting, you should be able to see how to modify your script and my example to use the textures' uuids.

Link to comment
Share on other sites

It is not really easy for a beginner to do this operation. You will need to break up the script you have in two scripts. The menu with the texture choices on touch will go into the HUD prim (the SENDER). And the listener who "hears" the menu choice will have to go into the attachment (the RECEIVER).

Then additionally to breaking it up succesfully, you will have to add/change some code as Xija pointed out. These are not operations that a beginner will succefully do without investing a lot of time and patience. 

There are some existing threads that might help (a bit) further:

https://community.secondlife.com/t5/LSL-Scripting/Texture-changer-via-HUD-for-worn-object/td-p/1752027

https://community.secondlife.com/t5/Mesh/mesh-color-texture-changer-script-hud/td-p/2007871

With a simple Google search I have seen that a prefabricated script is available on the marketplace:

https://kimmscripts.wordpress.com/2011/11/09/hud-texture-changer/

Or have a look at this tutorial that presents a pretty simple solution, but you should add some security to the scripts presented there or advanced scripters can easily make the textures of your customers change (I could). That is not what you want, is it? (I will watching out for eyes from Fleischgeiger... no just joking).

http://oddy.nl/?p=824

Good luck!

  • Like 1
Link to comment
Share on other sites

  • 4 years later...
On 7/29/2015 at 9:03 AM, Xiija said:

send a RegionSayTo  ... to the eyes, and have a script in the eyes that listens?

http://wiki.secondlife.com/wiki/LlRegionSayTo

something like this ...

key id = " *uuid of eye prim* ";

integer chan = -12321;

// replace your llSettexure with a region say

 llRegionSayTo(id, chan, message + " " + side);

 

 

and in the eye prim,

 listen(integer channel, string name, key id, string message)
 { list myList = llParseString2List(message,[" "],[];
   string texture = llList2String(myList,0);
   integer side = llList2String(myList,1);
   llSetTexture(texture, side);

}

etc, etc

I'm working in something like your sample, but want to change the action to run the script, (to apply texture) with sit on the object instead touch the object, but I continue have errors.

  • Like 1
Link to comment
Share on other sites

You basically can use the script above, but instead of the llSetTexture(message, side); you can use llRegionSayTo like @Innula Zenovka suggested, but instead of the name, you can use llGetInventoryKey to send the texture UUID directly to the eye prim. This way, you can keep the textures in the HUD and not move them to the eye prim.

It would look something like this:

llRegionSayTo(llGetOwner(), -12345, (string)llGetInventoryKey(message));

Where -12345 is the channel you use to communicate with the eyes and message the name of the texture as per your original script. This is presuming you don't need to add the side that needs to change or that it's hard-coded in the eye prim script.

 

The eye prim can then use a listener like Innula's (with the same channel as the sender) to recast the UUID back to a key and use llSetTexture to set it.

 

Link to comment
Share on other sites

  • 10 months later...

receptor texture UUID + normal map + specular

 

default
{
    
     state_entry()
    {
        llListen(-1,"",NULL_KEY,"");
    }
    

   listen(integer channel, string name, key id, string msg)
    {
         if (llGetOwner() == llGetOwnerKey(id))
         if (msg == "text1" )
         {
        llSetTexture("a3e061d1-c9b1-ce89-2de9-addc39506563", 1 );
        llSetTexture("77873a5d-ab44-ff8f-6a9a-d6087b5adb00", 2 );
        llSetTexture("77873a5d-ab44-ff8f-6a9a-d6087b5adb00", 0 );
        llSetPrimitiveParams([ PRIM_SPECULAR, ALL_SIDES, "3a97e824-fd26-1d9f-ffe7-00d0264e6631", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0, <0.275, 0.624, 0.832>, 51, 0]);
llSetPrimitiveParams([ PRIM_NORMAL, ALL_SIDES, "1ece3148-6cea-f9eb-2152-9902944dbc3d", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0 ]);
          }
           if (llGetOwner() == llGetOwnerKey(id))
         if (msg == "text2" )
         {
        llSetTexture("4c1f2066-861a-bce8-4d50-efa0a521a543", 1 );
        llSetTexture("80fce838-825b-a490-e17b-48f7dd51a6e8", 0 );
        llSetTexture("77873a5d-ab44-ff8f-6a9a-d6087b5adb00", 2 );
 llSetPrimitiveParams([ PRIM_SPECULAR, ALL_SIDES, "4dcc7f31-c8a7-6575-09ed-5fd8059534a7", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0,<1.000, 1.000, 1.000>, 51, 0]);
llSetPrimitiveParams([ PRIM_NORMAL, ALL_SIDES, "4c1751ad-b848-b230-1cc7-134c066df4c2", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0 ]);

          }
    }
}

HUD CLICK CHANGE TEXTURE MENU

 

integer i = 0;
integer currentPos = 0;

integer listener;
integer MENU_CHANNEL ;

// opens menu channel and displays dialog
Dialog(key id)
{
    list MENU1 = [];

    // count the textures in the prim to see if we need pages
    integer c = llGetInventoryNumber(INVENTORY_TEXTURE);
    if (c <= 12)
    {
        for (i = 0; i < c; i++ ) {
            MENU1 += llGetInventoryName(INVENTORY_TEXTURE, i);
        }
    }
    else
    {
        for (i = 10 * currentPos; i < (10 + (10 * currentPos)) ; i++) {

            // check to make sure name <= 24, or else the menu will not work.
            string aname = llGetInventoryName(INVENTORY_TEXTURE, i);
            if ( llStringLength(aname) >24)
            {
                llOwnerSay("The texture  named " + aname + " has too long of a name to be used, please give it a shorter name <= 24 characters ");
            }
            else
            {
                if (i < c ) {
                    MENU1 += aname;
                }
            }
        }
        MENU1 += ">>";
        if (currentPos != 0)
            MENU1 += "<<";
        else
            MENU1 += "-";
    }


    MENU_CHANNEL = (integer) (llFrand(10000) + 10000);
    listener = llListen(-1, "", NULL_KEY, "");

    llDialog(id, "Select one object below: ", MENU1, -1);
}

default
{
    on_rez(integer num)
    {
        // reset scripts on rez
        llResetScript();
    }

    touch_start(integer total_number)
    {
        // display the dialog
        Dialog(llDetectedKey(0));
    }

    listen(integer channel, string name, key id, string message)
    {
        if (channel == -1)
        {
            llListenRemove(listener);
            if (message == ">>")
            {
                currentPos ++;
                Dialog(id);
            }
            else if (message == "<<")
            {
                currentPos--;
                if (currentPos < 0)
                    currentPos = 0;
                Dialog(id);
            }
            else
            {
                // display the texture from menu selection
                llSetTexture(message, ALL_SIDES);

            }
        }
    }
}

 

Screenshot_2.png

Edited by System32jos
Link to comment
Share on other sites

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