How this works is, you load up a prm with textures and the script. The prim will automatically display the first texture (as expected) and each mouse click will rotate to the next one.
Where this is different is, if you hold down the mouse key for two seconds, you get a dialog asking if you want to take the texture. This can be handy if you are on a building project and want to keep a hot list of textures handy in your "Recent Items" tab without having a lot of unwanted textures in inventory (which can slow you down by contributing to inventory lag and also by having to constantly search for the exact texture...). With a little more code jiggery, someone could also add a pay method allowing buyers to purchase individual textures instead of having to buy (or choose not to buy) complete sets.
CODE
// set these to whatever values you wish
integer myChannel = 123;
float trigger_time = 2.0;
float idle_time = 10.0;
list menu = ["Get Texture"];
// used for controlling command entry
float elapsed = 0.0;
integer listenHandle;
// used for texture cycling
integer count;
integer i;
string texture_name;
// used to retrieve texture
key agent_key;
display(integer n)
{
llSetTexture(texture_name, ALL_SIDES);
llSetText(llGetObjectName() + "\n" + (string)(n+1) + " of " + (string)count + " - " + texture_name, <1.0,1.0,1.0>, 1.0);
}
get_texture()
{
llGiveInventory(agent_key, texture_name);
}
B()
{
llSay(0, "B Pressed");
}
touch_hold()
{
elapsed = llGetAndResetTime();
llListenControl(listenHandle, TRUE); // ...enable
llSetTimerEvent(idle_time);
llDialog(llDetectedKey(0), texture_name, menu, myChannel);
}
default
{
state_entry()
{
listenHandle = llListen(myChannel,"","","");
elapsed = 0.0;
count = llGetInventoryNumber(INVENTORY_TEXTURE);
i = 0;
texture_name = llGetInventoryName(INVENTORY_TEXTURE, 0);
display(i);
}
on_rez(integer startup_param)
{
llResetScript();
}
touch_start(integer num_detected)
{
if (llDetectedKey(0) == llGetOwner()) {
elapsed = llGetAndResetTime();
}
}
touch(integer num_detected)
{
if (llDetectedKey(0) == llGetOwner()) {
elapsed = llGetTime();
if (elapsed >= trigger_time) {
agent_key = llDetectedKey(0);
touch_hold();
}
}
}
touch_end(integer num_detected)
{
if (elapsed < trigger_time) {
i += 1;
if (i >= count) i = 0;
texture_name = llGetInventoryName(INVENTORY_TEXTURE, i);
display(i);
}
}
timer()
{
llSetTimerEvent(0.0);
llListenControl(listenHandle, FALSE); // ...disable
}
listen(integer chan, string name, key id, string cmd)
{
if (llListFindList(menu, [cmd]) != -1) {
if (llToUpper(cmd) == "GET TEXTURE") {
get_texture();
}
}
}
}