Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Textures TextureAllByDescription  

TextureAllByDescription

Texture all prims from an inventory by menu

Category: Textures
By : Ferd Frederix
Created: 2014-01-01 Edited: 2014-01-01
Worlds: Second Life

the Zip file

Download all files for TextureAllByDescription
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Texture_all_by_Description_Script.lsl

This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 integer debug = TRUE;
2
3 DEBUG(string msg)
4 {
5 if(debug) llSay(0,msg);
6 }
7
8 list textures; // a list of texture names, in Head,Middle,Bottom Strided order
9 key user; // you
10 integer listen_id; // a listener that we can cancel to control lag
11 integer menuChannel;
12 list menus; // a list of Names of textures read from inventory
13 // from the menu system http://wiki.secondlife.com/wiki/SimpleDialogMenuSystem
14 integer N_DIALOG_CHOICES;
15 integer MAX_DIALOG_CHOICES_PER_PG = 8; // if not offering back button, increase this to 9
16 string PREV_PG_DIALOG_PREFIX = "< Page ";
17 string NEXT_PG_DIALOG_PREFIX = "> Page ";
18 string DIALOG_DONE_BTN = "Done";
19 string DIALOG_BACK_BTN = "<< Back";
20
21 integer pageNum;
22 list DIALOG_CHOICES;
23
24 giveDialog( integer pageNum) {
25
26 list buttons;
27 integer firstChoice;
28 integer lastChoice;
29 integer prevPage;
30 integer nextPage;
31 string OnePage;
32
33 CancelListen();
34
35 menuChannel = llCeil(llFrand(1000000) + 11000000);
36 listen_id = llListen(menuChannel,"","","");
38
39 N_DIALOG_CHOICES = llGetListLength(DIALOG_CHOICES);
40
41
42 if(N_DIALOG_CHOICES <= 10) {
43 buttons = DIALOG_CHOICES;
44 OnePage = "Yes";
45 }
46 else {
47 integer nPages = (N_DIALOG_CHOICES+MAX_DIALOG_CHOICES_PER_PG-1)/MAX_DIALOG_CHOICES_PER_PG;
48
49 if(pageNum < 1 || pageNum > nPages) {
50 pageNum = 1;
51 }
52 firstChoice = (pageNum-1)*MAX_DIALOG_CHOICES_PER_PG;
53
54 lastChoice = firstChoice+MAX_DIALOG_CHOICES_PER_PG-1;
55
56 if(lastChoice >= N_DIALOG_CHOICES) {
57 lastChoice = N_DIALOG_CHOICES;
58 }
59 if(pageNum <= 1) {
60 prevPage = nPages;
61 nextPage = 2;
62 }
63 else if(pageNum >= nPages) {
64 prevPage = nPages-1;
65 nextPage = 1;
66 }
67 else {
68 prevPage = pageNum-1;
69 nextPage = pageNum+1;
70 }
71 buttons = llList2List(DIALOG_CHOICES, firstChoice, lastChoice);
72 }
73
74
75 // FYI, this puts the navigation button row first, so it is always at the bottom of the dialog
76 list buttons01 = llList2List(buttons, 0, 2);
77 list buttons02 = llList2List(buttons, 3, 5);
78 list buttons03 = llList2List(buttons, 6, 8);
79 list buttons04;
80 if(OnePage == "Yes") {
81 buttons04 = llList2List(buttons, 9, 11);
82 }
83 buttons = buttons04 + buttons03 + buttons02 + buttons01;
84
85 if(OnePage == "Yes") {
86 buttons = [ DIALOG_DONE_BTN, DIALOG_BACK_BTN ]+ buttons;
87 //omit DIALOG_BACK_BTN in line above if not offering
88
89 }
90 else {
91 buttons = [
92 PREV_PG_DIALOG_PREFIX + (string)prevPage,
93 DIALOG_BACK_BTN, NEXT_PG_DIALOG_PREFIX+(string)nextPage, DIALOG_DONE_BTN
94 ]+buttons;
95 //omit DIALOG_BACK_BTN in line above if not offering
96 }
97 llDialog(user, "Page "+(string)pageNum+"\nChoose one:", buttons, menuChannel);
98 }
99
100
101 CancelListen() {
102 llListenRemove(listen_id);
104 }
105
106
107 // change texture of any prims name Head, Body, Legs
108 TextureIt(integer texNum) {
109
110 DEBUG("using texture # " + (string) texNum);
111
112 DEBUG(llDumpList2String(textures,","));
113
114 DEBUG(llList2String(textures,0));
115 DEBUG(llList2String(textures,1));
116 DEBUG(llList2String(textures,2));
117 DEBUG( llList2String(textures,3));
118 DEBUG(llList2String(textures,4));
119 DEBUG(llList2String(textures,5));
120
121
122
123 // Head, Middle, Bottom pops out of this
124 // texNum *= 3; // cast this to the size of the actual texture list, which is 3
125
126
127
128
129 integer found = 0;
130 integer nPrims = llGetNumberOfPrims();
131 integer i;
132 for (i = 0; i <= nPrims; i++) {
133 list param = llGetLinkPrimitiveParams(i,[PRIM_DESC]); // DESCRIPTION holds the texture number
134 string primName = llList2String(param,0);
135
136 if(primName == "Body") {
137 string text = llList2String(textures,texNum);
138 llSetLinkTexture(i,text,ALL_SIDES); // add this line which sets the texture with no offset or repeat or rotation changes
139 found++;
140 }
141 else if(primName == "Head") {
142 string text = llList2String(textures,texNum+1);
143 llSetLinkTexture(i,text,ALL_SIDES); // add this line which sets the texture with no offset or repeat or rotation changes
144 found++;
145 }
146 else if(primName == "Leg") {
147 string text = llList2String(textures,texNum+2);
148 llSetLinkTexture(i,text,ALL_SIDES); // add this line which sets the texture with no offset or repeat or rotation changes
149 found++;
150 }
151 }
152
153 if(found < 3)
154 {
155 llOwnerSay("Something is wrong. There must be at least 3 prims with a description of Head, Body, and Leg");
156 }
157
158 }
159
160 GetTextures()
161 {
163 integer i;
164 textures = [];
165 DIALOG_CHOICES = [];
166 menus = [];
167 for ( i = 0; i < nItems; i++) {
168
169 // this section makes a list with all three texture names in alphabetical order
171 textures += name;
172
173 // This break it down into the Name-Head, name-Body and name-Leg parts and saves the name for a menu
174 list parts = llParseString2List(name,["-"],[""]);
175 string firstpart = llList2String(parts,0);
176 menus += firstpart;
177 }
178 // we want a menu with just the names, bit the -Head, etc.
179 DIALOG_CHOICES = ListUnique(menus);
180
181 // and all this depends upon them being in alpha order.
182 DIALOG_CHOICES = llListSort(DIALOG_CHOICES,1,1);
183 menus = llListSort(menus,3,1);
184 }
185
186 list ListUnique( list lAll ) {
187 integer i;
188 list lFiltered = llList2List(lAll, 0, 0);
189 integer iAll = llGetListLength( lAll );
190 for (i = 1; i < iAll; ++i) {
191 if( llListFindList(lFiltered, llList2List(lAll, i, i) ) == -1 ) {
192 lFiltered += llList2List(lAll, i, i);
193 }
194 }
195 return lFiltered;
196 }
197
198 default
199 {
200 state_entry() {
201 GetTextures();
202 }
203
204 touch_start(integer total_number) {
205 GetTextures();
206 user = llDetectedKey(0);
207 giveDialog(pageNum);
208 }
209
210 listen(integer channel, string name, key id, string message){
211 CancelListen();
212
213 user = id; // two people may be using it at the same time, so we save the ID here
214
215 if( message == DIALOG_DONE_BTN){
216 CancelListen();
217 return;
218 }
219 else if(message == DIALOG_BACK_BTN){
220 pageNum = 1;
221 giveDialog(pageNum);
222 }
223 else if(llSubStringIndex(message, PREV_PG_DIALOG_PREFIX) == 0){
224 pageNum = (integer)llGetSubString(message, llStringLength(PREV_PG_DIALOG_PREFIX), -1);
225 giveDialog( pageNum);
226 }
227 else if(llSubStringIndex(message, NEXT_PG_DIALOG_PREFIX) == 0){
228 pageNum = (integer)llGetSubString(message, llStringLength(NEXT_PG_DIALOG_PREFIX), -1);
229 giveDialog(pageNum);
230
231 } else { //this is the section where we do stuff other than menus
232
233 integer where = llListFindList(menus, [message]); // find the string he clicked in the master list
234 if(where >= -1) { // -1 is not found
235 TextureIt(where); // 0th is Body, 1 = Head, 2 = Legs
236 }
237 }
238 }
239
240
241 timer() {
242 CancelListen();
243 llOwnerSay("Sorry. The menu timed out, click me again. ");
244 }
245
246 }

Back to the Best Free Tools in Second Life and OpenSim.