Advertisement
left2chance

Untitled

Jul 23rd, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* !rezFromData */
  2.  
  3. /* ------- user settable script parameters -------- */
  4. integer p_ch = -6011948; // CHANNEL - channel to talk to other prims
  5. integer DEBUG = FALSE; // DEBUG - chat debug data
  6. float range = 30.0; // RANGE - range to scan
  7. integer HIDER = FALSE; // HIDE - hide the rezzer after rezzing objects
  8.  
  9.  
  10. /* ------- user dialog routines ------------- */
  11.  
  12. get_menu_selection( key user, string title, list opt, integer ch)
  13. { opt = subL(opt,-3,-1)+subL(opt,-6,-4)+subL(opt,-9,-7)+subL(opt,-12,-10);
  14. llListenRemove(wait);
  15. wait = llListen(ch,"",user,"");
  16. llDialog(user, title, opt, ch);
  17. llSetTimerEvent(idleTime*60);
  18. }
  19. key user_id; // user to present menu to
  20. integer m_ch; // menu channel
  21. integer wait=0; // wait handle
  22. float idleTime=10.0; // minutes to wait
  23. string opt1; string opt2; string opt3; string opt4; string opt5; string opt12;
  24.  
  25. list options(){ return [opt1,opt2,opt3,opt4=l2s(["SHOW","HIDE"],!HIDE),opt5,opt12]; }
  26. string title() { return dl2s(
  27. [ "\nPosition objects from the rezzer's contents\n"
  28. , "in-world relative to the rezzer. SCAN them and\n"
  29. , "copy chatted data to the rezzer's '#DATA' notecard.\n"
  30. , "REZ the collection, and use MOVE to reposition\n"
  31. , "or KILL to de-rez objects with the '!kill' script in them.\n\n"
  32. , opt1, ":   Scan ", (integer)range, " meters.\n"
  33. , opt2, ":\t Rez from notecard data.\n"
  34. , opt3, ":  Relay position changes on ch:", p_ch, ".\n"
  35. , opt4, ":\tShow/Hide the rezzer.\n"
  36. , opt5, ":\t De-rez things with '!kill' script.\n"
  37. , opt12, ":\tEnd menu until a restart."], ""); }
  38.  
  39.  
  40. /* ___________ menu command routines _____________ */
  41.  
  42. find_object()
  43. { if(obj_ix < obj_count)
  44. { string obj_name = llGetInventoryName(INVENTORY_OBJECT, obj_ix++);
  45. llSensor(obj_name, (key)"", 4|2, range, PI);
  46. }
  47. else
  48. { report(["found",found = llGetListLength(objects)," objects."]
  49. ,l2s(["",".. Copy the following to a '#DATA' card >>"],found!=0));
  50. integer ix; string myName = llGetObjectName();
  51. llSetObjectName("");
  52. do report([],l2s(objects,ix)); while(++ix < found);
  53. llSetObjectName(myName);
  54. }
  55. }
  56. integer obj_ix;
  57. integer obj_count;
  58. list objects;
  59. integer found;
  60.  
  61. read_card(integer nc_ix)
  62. { Name = llGetInventoryName(INVENTORY_NOTECARD,nc_ix);
  63. if(found_in(Name, "#DATA"))
  64. { report(["Reading", Name, "card."],"");
  65. query = llGetNotecardLine(Name, Line_no = 0);
  66. }
  67. }
  68. key query;
  69. string Name;
  70. integer Line_no;
  71. integer cards;
  72. integer Card_no;
  73.  
  74. rez_objects()
  75. { bp = llGetPos(); br = llGetRot();
  76. integer ix; integer rez_max=llGetListLength(objects);
  77. string name; vector p_off; rotation r_off; list pl;
  78. do
  79. { pl=parse(l2s(objects,ix),[":"],[]);
  80. name = l2s(pl,0);
  81. if(llGetInventoryType(name)==INVENTORY_OBJECT)
  82. { p_off = (vector)l2s(pl,1);
  83. r_off = (rotation)l2s(pl,2);
  84. llRezAtRoot(name, bp+(p_off*br), ZERO_VECTOR, r_off*br, p_ch);
  85. dump([name, bp+(p_off*br), r_off*br]);
  86. }
  87. } while(++ix < rez_max);
  88. if(rez_max && HIDER) llSetLinkAlpha(LINK_SET, (float)(!(HIDE=HIDER)), ALL_SIDES);
  89. }
  90. vector bp; rotation br;
  91.  
  92. rez_all_objects()
  93. { dump([92]);
  94. integer ix; integer rez_max= llGetInventoryNumber(INVENTORY_OBJECT);
  95. bp = llGetPos(); br = llGetRot(); string n;
  96. do
  97. { llRezObject(llGetInventoryName(INVENTORY_OBJECT,ix), bp+<1*ix,0,0>, ZERO_VECTOR, br, p_ch);
  98. } while(++ix < rez_max);
  99. }
  100.  
  101.  
  102. /* -------------- common routines ---------------------- */
  103.  
  104. dump ( list l)
  105. { if(DEBUG) llOwnerSay(llDumpList2String(l, "•")); }
  106. report ( list l, string s)
  107. { llOwnerSay(llDumpList2String(l, " ") + s); }
  108. string l2s ( list l, integer ix)
  109. { return llList2String(l,ix); }
  110. string dl2s ( list l, string sep )
  111. { return llDumpList2String(l, sep); }
  112. list subL ( list l, integer b, integer e)
  113. { return llList2List(l, b, e); }
  114. list parse ( string s, list sep, list spc)
  115. { return llParseString2List(s, sep, spc); }
  116. integer found_in( string s, string target) // set TRUE if target found, FALSE if not
  117. { return llSubStringIndex(s,target)+1; }
  118. integer find_ix ( list l, list t)
  119. { return llListFindList(l, t); }
  120. integer s2bin ( string s) // interpret strings as binary settings
  121. { s=llToUpper(s); // make independent of case
  122. if(~find_ix(["1","YES","Y","ON","TRUE"],[s])) return 1;
  123. if(~find_ix(["0","NO","N","OFF","FALSE"],[s])) return 0;
  124. dump([98, "s2bin failed"]); return -1; }
  125. integer HIDE;
  126. integer LOADING;
  127.  
  128.  
  129.  
  130. /* -------------- script states ---------------------- */
  131.  
  132. default
  133. { state_entry()
  134. { llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);
  135. bp = llGetPos(); br = llGetRot();
  136. opt1="SCAN"; opt2="REZ"; opt3="MOVE"; opt4=l2s(["SHOW","HIDE"],!HIDE); opt5="KILL"; opt12="QUIT";
  137.  
  138. // set parameters from object description: eg., "#SET:DEBUG=Y"
  139. string s; list p; integer ix; list seps = ["=", ":"];
  140. if (found_in(s = llGetObjectDesc(),"#SET"))
  141. { if(ix=find_ix(p=parse(s,seps,[]),["DEBUG"])+1) DEBUG = s2bin(l2s(p,ix));
  142. if(ix=find_ix(p=parse(s,seps,[]),["HIDE"])+1) HIDER = s2bin(l2s(p,ix));
  143. if(ix=find_ix(p=parse(s,seps,[]),["RANGE"])+1) range = (float)l2s(p,ix);
  144. if(ix=find_ix(p=parse(s,seps,[]),["CHANNEL"])+1) p_ch = (integer)l2s(p,ix);
  145. }
  146. }
  147.  
  148. touch_start(integer total_number)
  149. { user_id=llDetectedKey(0);
  150. get_menu_selection(user_id, title(), options(), m_ch=(integer)llFrand(-20000000.0));
  151. }
  152.  
  153. listen(integer ch, string nm, key id, string SEL)
  154. { if (SEL==opt1) // SCAN
  155. { bp = llGetPos(); br = llGetRot();
  156. obj_count = llGetInventoryNumber(INVENTORY_OBJECT);
  157. objects = []; obj_ix=0;
  158. find_object();
  159. }
  160. else if (SEL==opt2) // REZ
  161. { cards=llGetInventoryNumber(INVENTORY_NOTECARD);
  162. if(cards)
  163. { objects=[]; Card_no = 0;
  164. while(Card_no < cards) read_card(Card_no++);
  165. }
  166. else if(objects!=[]) rez_objects(); else rez_all_objects();
  167. }
  168. else if (SEL==opt3) // MOVE
  169. llRegionSay(p_ch, dl2s(["MOVE", bp, br, bp=llGetPos(), br=llGetRot()],":") );
  170. else if (SEL==opt4) HIDE=!HIDE;
  171. else if (SEL==opt5) { llRegionSay(p_ch, "DIE"); HIDE=FALSE;}
  172. else if (SEL==opt12) llSetScriptState(llGetScriptName(), 0);
  173.  
  174. llSetLinkAlpha(LINK_SET, (float)(!HIDE), ALL_SIDES);
  175. if(SEL!=opt5)
  176. get_menu_selection(user_id, title(), options(), m_ch = (integer)llFrand(-20000000.0) );
  177. }
  178.  
  179. sensor( integer d )
  180. { while(d--)
  181. { string n = llDetectedName(d);
  182. vector p = llDetectedPos(d);
  183. rotation r = llDetectedRot(d);
  184. vector p_off = (p-bp)/br;
  185. rotation r_off = r/br;
  186. objects += dl2s([n, p_off, r_off ],":");
  187. }
  188. find_object();
  189. }
  190.  
  191. no_sensor(){ find_object(); }
  192.  
  193. dataserver(key q_id, string data)
  194. { if (q_id != query) return;
  195. if (data == EOF)
  196. { report(["Read",Line_no,"lines from",Name],"");
  197. if(objects!=[]) rez_objects();
  198. }
  199. else
  200. { objects += data;
  201. query = llGetNotecardLine(Name, ++Line_no);
  202. }
  203. }
  204.  
  205. changed(integer chg){ if(chg|CHANGED_INVENTORY && !LOADING){ ++LOADING; llSetTimerEvent(3.0); } }
  206.  
  207. timer()
  208. { llSetTimerEvent(0.0);
  209. if(LOADING) state end_wait; else
  210. if(wait) report(["Timed out, reset to restart"],""); state end_wait;
  211. }
  212. }
  213.  
  214. state end_wait { state_entry() { wait=LOADING=0; state default; } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement