Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* !rezFromData */
- /* ------- user settable script parameters -------- */
- integer p_ch = -6011948; // CHANNEL - channel to talk to other prims
- integer DEBUG = FALSE; // DEBUG - chat debug data
- float range = 30.0; // RANGE - range to scan
- integer HIDER = FALSE; // HIDE - hide the rezzer after rezzing objects
- /* ------- user dialog routines ------------- */
- get_menu_selection( key user, string title, list opt, integer ch)
- { opt = subL(opt,-3,-1)+subL(opt,-6,-4)+subL(opt,-9,-7)+subL(opt,-12,-10);
- llListenRemove(wait);
- wait = llListen(ch,"",user,"");
- llDialog(user, title, opt, ch);
- llSetTimerEvent(idleTime*60);
- }
- key user_id; // user to present menu to
- integer m_ch; // menu channel
- integer wait=0; // wait handle
- float idleTime=10.0; // minutes to wait
- string opt1; string opt2; string opt3; string opt4; string opt5; string opt12;
- list options(){ return [opt1,opt2,opt3,opt4=l2s(["SHOW","HIDE"],!HIDE),opt5,opt12]; }
- string title() { return dl2s(
- [ "\nPosition objects from the rezzer's contents\n"
- , "in-world relative to the rezzer. SCAN them and\n"
- , "copy chatted data to the rezzer's '#DATA' notecard.\n"
- , "REZ the collection, and use MOVE to reposition\n"
- , "or KILL to de-rez objects with the '!kill' script in them.\n\n"
- , opt1, ": Scan ", (integer)range, " meters.\n"
- , opt2, ":\t Rez from notecard data.\n"
- , opt3, ": Relay position changes on ch:", p_ch, ".\n"
- , opt4, ":\tShow/Hide the rezzer.\n"
- , opt5, ":\t De-rez things with '!kill' script.\n"
- , opt12, ":\tEnd menu until a restart."], ""); }
- /* ___________ menu command routines _____________ */
- find_object()
- { if(obj_ix < obj_count)
- { string obj_name = llGetInventoryName(INVENTORY_OBJECT, obj_ix++);
- llSensor(obj_name, (key)"", 4|2, range, PI);
- }
- else
- { report(["found",found = llGetListLength(objects)," objects."]
- ,l2s(["",".. Copy the following to a '#DATA' card >>"],found!=0));
- integer ix; string myName = llGetObjectName();
- llSetObjectName("");
- do report([],l2s(objects,ix)); while(++ix < found);
- llSetObjectName(myName);
- }
- }
- integer obj_ix;
- integer obj_count;
- list objects;
- integer found;
- read_card(integer nc_ix)
- { Name = llGetInventoryName(INVENTORY_NOTECARD,nc_ix);
- if(found_in(Name, "#DATA"))
- { report(["Reading", Name, "card."],"");
- query = llGetNotecardLine(Name, Line_no = 0);
- }
- }
- key query;
- string Name;
- integer Line_no;
- integer cards;
- integer Card_no;
- rez_objects()
- { bp = llGetPos(); br = llGetRot();
- integer ix; integer rez_max=llGetListLength(objects);
- string name; vector p_off; rotation r_off; list pl;
- do
- { pl=parse(l2s(objects,ix),[":"],[]);
- name = l2s(pl,0);
- if(llGetInventoryType(name)==INVENTORY_OBJECT)
- { p_off = (vector)l2s(pl,1);
- r_off = (rotation)l2s(pl,2);
- llRezAtRoot(name, bp+(p_off*br), ZERO_VECTOR, r_off*br, p_ch);
- dump([name, bp+(p_off*br), r_off*br]);
- }
- } while(++ix < rez_max);
- if(rez_max && HIDER) llSetLinkAlpha(LINK_SET, (float)(!(HIDE=HIDER)), ALL_SIDES);
- }
- vector bp; rotation br;
- rez_all_objects()
- { dump([92]);
- integer ix; integer rez_max= llGetInventoryNumber(INVENTORY_OBJECT);
- bp = llGetPos(); br = llGetRot(); string n;
- do
- { llRezObject(llGetInventoryName(INVENTORY_OBJECT,ix), bp+<1*ix,0,0>, ZERO_VECTOR, br, p_ch);
- } while(++ix < rez_max);
- }
- /* -------------- common routines ---------------------- */
- dump ( list l)
- { if(DEBUG) llOwnerSay(llDumpList2String(l, "•")); }
- report ( list l, string s)
- { llOwnerSay(llDumpList2String(l, " ") + s); }
- string l2s ( list l, integer ix)
- { return llList2String(l,ix); }
- string dl2s ( list l, string sep )
- { return llDumpList2String(l, sep); }
- list subL ( list l, integer b, integer e)
- { return llList2List(l, b, e); }
- list parse ( string s, list sep, list spc)
- { return llParseString2List(s, sep, spc); }
- integer found_in( string s, string target) // set TRUE if target found, FALSE if not
- { return llSubStringIndex(s,target)+1; }
- integer find_ix ( list l, list t)
- { return llListFindList(l, t); }
- integer s2bin ( string s) // interpret strings as binary settings
- { s=llToUpper(s); // make independent of case
- if(~find_ix(["1","YES","Y","ON","TRUE"],[s])) return 1;
- if(~find_ix(["0","NO","N","OFF","FALSE"],[s])) return 0;
- dump([98, "s2bin failed"]); return -1; }
- integer HIDE;
- integer LOADING;
- /* -------------- script states ---------------------- */
- default
- { state_entry()
- { llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);
- bp = llGetPos(); br = llGetRot();
- opt1="SCAN"; opt2="REZ"; opt3="MOVE"; opt4=l2s(["SHOW","HIDE"],!HIDE); opt5="KILL"; opt12="QUIT";
- // set parameters from object description: eg., "#SET:DEBUG=Y"
- string s; list p; integer ix; list seps = ["=", ":"];
- if (found_in(s = llGetObjectDesc(),"#SET"))
- { if(ix=find_ix(p=parse(s,seps,[]),["DEBUG"])+1) DEBUG = s2bin(l2s(p,ix));
- if(ix=find_ix(p=parse(s,seps,[]),["HIDE"])+1) HIDER = s2bin(l2s(p,ix));
- if(ix=find_ix(p=parse(s,seps,[]),["RANGE"])+1) range = (float)l2s(p,ix);
- if(ix=find_ix(p=parse(s,seps,[]),["CHANNEL"])+1) p_ch = (integer)l2s(p,ix);
- }
- }
- touch_start(integer total_number)
- { user_id=llDetectedKey(0);
- get_menu_selection(user_id, title(), options(), m_ch=(integer)llFrand(-20000000.0));
- }
- listen(integer ch, string nm, key id, string SEL)
- { if (SEL==opt1) // SCAN
- { bp = llGetPos(); br = llGetRot();
- obj_count = llGetInventoryNumber(INVENTORY_OBJECT);
- objects = []; obj_ix=0;
- find_object();
- }
- else if (SEL==opt2) // REZ
- { cards=llGetInventoryNumber(INVENTORY_NOTECARD);
- if(cards)
- { objects=[]; Card_no = 0;
- while(Card_no < cards) read_card(Card_no++);
- }
- else if(objects!=[]) rez_objects(); else rez_all_objects();
- }
- else if (SEL==opt3) // MOVE
- llRegionSay(p_ch, dl2s(["MOVE", bp, br, bp=llGetPos(), br=llGetRot()],":") );
- else if (SEL==opt4) HIDE=!HIDE;
- else if (SEL==opt5) { llRegionSay(p_ch, "DIE"); HIDE=FALSE;}
- else if (SEL==opt12) llSetScriptState(llGetScriptName(), 0);
- llSetLinkAlpha(LINK_SET, (float)(!HIDE), ALL_SIDES);
- if(SEL!=opt5)
- get_menu_selection(user_id, title(), options(), m_ch = (integer)llFrand(-20000000.0) );
- }
- sensor( integer d )
- { while(d--)
- { string n = llDetectedName(d);
- vector p = llDetectedPos(d);
- rotation r = llDetectedRot(d);
- vector p_off = (p-bp)/br;
- rotation r_off = r/br;
- objects += dl2s([n, p_off, r_off ],":");
- }
- find_object();
- }
- no_sensor(){ find_object(); }
- dataserver(key q_id, string data)
- { if (q_id != query) return;
- if (data == EOF)
- { report(["Read",Line_no,"lines from",Name],"");
- if(objects!=[]) rez_objects();
- }
- else
- { objects += data;
- query = llGetNotecardLine(Name, ++Line_no);
- }
- }
- changed(integer chg){ if(chg|CHANGED_INVENTORY && !LOADING){ ++LOADING; llSetTimerEvent(3.0); } }
- timer()
- { llSetTimerEvent(0.0);
- if(LOADING) state end_wait; else
- if(wait) report(["Timed out, reset to restart"],""); state end_wait;
- }
- }
- state end_wait { state_entry() { wait=LOADING=0; state default; } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement