Advertisement
Trafalgar

second life sector spy drone script

Aug 12th, 2019
1,419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. integer attachmentPoint;
  2. key attachedTo;
  3. integer listenHandle = 0;
  4. integer listenHandle2 = 0;
  5. vector origScale = ZERO_VECTOR;
  6. integer pin = 980572850;
  7. string lastMessage = "";
  8. float version = 0.4;
  9. list lastMessages = [];
  10. float messagePurgeCountdown;
  11.  
  12. //http://secondlife.com/badgeo/wakka.php?wakka=LibraryWarpPos&show_comments=1#comments
  13. warpPos(vector destpos)
  14. {   //R&D by Keknehv Psaltery, 05/25/2006
  15.     //with a little pokeing by Strife, and a bit more
  16.     //some more munging by Talarus Luan
  17.     //Final cleanup by Keknehv Psaltery
  18.     // Compute the number of jumps necessary
  19.     integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1;
  20.     // Try and avoid stack/heap collisions
  21.     if (jumps > 100 )
  22.         jumps = 100;    //  1km should be plenty
  23.     list rules = [ PRIM_POSITION, destpos ];  //The start for the rules list
  24.     integer count = 1;
  25.     while ( ( count = count << 1 ) < jumps)
  26.         rules = (rules=[]) + rules + rules;   //should tighten memory use.
  27.     llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
  28. }
  29.  
  30. default {
  31.     state_entry() {
  32.         attachmentPoint = llGetAttached();
  33.         listenHandle = llListen(150, "", NULL_KEY, "");  //Listen only to our owner.
  34.         if (attachmentPoint==0) {
  35.             listenHandle2 = llListen(0, "", NULL_KEY, "");
  36.         } else {
  37.             listenHandle2 = 0;
  38.         }
  39.         lastMessage="";
  40.         llSetRemoteScriptAccessPin(pin);
  41.         lastMessages = [];
  42.         llSetTimerEvent(0.0);
  43.         messagePurgeCountdown=0.0;
  44.     }
  45.    
  46.     on_rez(integer start_param) {
  47.         attachmentPoint = llGetAttached();
  48.         llListenRemove(listenHandle);
  49.         listenHandle = llListen(150, "", NULL_KEY, "");  //Listen only to our owner.
  50.         llListenRemove(listenHandle2);
  51.         if (attachmentPoint==0) {
  52.             listenHandle2 = llListen(0, "", NULL_KEY, "");
  53.         } else {
  54.             listenHandle2 = 0;
  55.         }
  56.         lastMessage="";
  57.         lastMessages = [];
  58.         llSetTimerEvent(0.0);
  59.         messagePurgeCountdown=0.0;
  60.         if (start_param>0) {
  61.             integer index = start_param - 1;
  62.             float x = (index%3)*64 + 64.0;
  63.             float y = (index/3)*64 + 64.0;
  64.             float z = llGround(<x, y, 0.0>-llGetPos()) - 1.0;
  65.             vector dest = <x, y, z>;
  66.             llOwnerSay("Moving to "+(string)dest);
  67.             warpPos(dest);
  68.             //llDie();
  69.         }
  70.     }
  71.    
  72.     attach(key id) {
  73.         if (id==NULL_KEY) {
  74.             attachmentPoint=0;
  75.         } else {
  76.             attachmentPoint = llGetAttached();
  77.         }
  78.         llListenRemove(listenHandle);
  79.         listenHandle = llListen(150, "", NULL_KEY, "");  //Listen only to our owner.
  80.         llListenRemove(listenHandle2);
  81.         if (attachmentPoint==0) {
  82.             listenHandle2 = llListen(0, "", NULL_KEY, "");
  83.         } else {
  84.             listenHandle2 = 0;
  85.         }
  86.     }
  87.    
  88.     listen(integer channel, string name, key id, string message) {
  89.         if (id==llGetOwner()) {    //If the owner is speaking
  90.             if (attachmentPoint!=0 && channel==150) {    //If we're attached and the owner spoke on channel 150.
  91.                 if (message=="suicide") {    //Kill all our drones.
  92.                     llOwnerSay("Commanding drones to suicide.");
  93.                     llShout(150, "suicide");
  94.                 } else if (message=="update") {
  95.                     llOwnerSay("Sending update information (our version: "+(string)version+").");
  96.                     llShout(150, "update|"+(string)version);
  97.                 } else if (message=="test") {
  98.                     llOwnerSay("Querying drones.");
  99.                     llShout(150, "test");
  100.                 } else if (message=="rez") {
  101.                     llOwnerSay("Creating network.");
  102.                     integer i=1;
  103.                     for (i=1; i<=9; i++) {
  104.                         llRezObject("Comm Drone", llGetPos(), ZERO_VECTOR, ZERO_ROTATION, i);
  105.                     }
  106.                 } else if (message!=lastMessage) {    //Have the drones say something.
  107.                     llOwnerSay("Commanding drones to say \""+message+"\"");
  108.                     llShout(150, "say|"+name+"|"+message);
  109.                 }
  110.             }
  111.         } else if (llGetOwnerKey(id)==llGetOwner()) {
  112.             if (attachmentPoint==0) {
  113.                 if (channel==150) {
  114.                     list packet = llParseString2List(message, ["|"], []);
  115.                     if (llListFindList(lastMessages, [message])==-1) {
  116.                         if (messagePurgeCountdown==0.0) {
  117.                             llSetTimerEvent(0.1);
  118.                             messagePurgeCountdown=5.0;
  119.                         }
  120.                         lastMessages += message;
  121.                         string command = llList2String(packet, 0);
  122.                         if (command=="suicide") {    //Die on command
  123.                             llOwnerSay("Suiciding.");
  124.                             llShout(150, "suicide");
  125.                             llDie();
  126.                         } else if (command=="update") {
  127.                             float availableVersion = (float) llList2String(packet, 1);
  128.                             if (availableVersion>version) {
  129.                                 llOwnerSay("Requesting update (our version is "+(string)version+", proposed version is "+(string)availableVersion+".");
  130.                                 string send = "updateme|"+(string)llGetKey();
  131.                                 lastMessages += send;
  132.                                 llShout(150, send);
  133.                             } else {
  134.                                 llOwnerSay("Ignoring update (our version is "+(string)version+", proposed version is "+(string)availableVersion+".");
  135.                             }
  136.                         } else if (command=="test") {
  137.                             llOwnerSay("Comm Drone at "+(string)llGetPos()+" reporting in.");
  138.                             llShout(150, "test");                            
  139.                         } else if (command=="say") {
  140.                             string speakerName = llList2String(packet, 1);
  141.                             string speakerMessage = llList2String(packet, 2);
  142.                             llOwnerSay("Saying <"+speakerName+"> "+speakerMessage);
  143.                             string myName = llGetObjectName();
  144.                             llSetObjectName(speakerName);
  145.                             llSay(0, speakerMessage);
  146.                             llSetObjectName(myName);
  147.                         } else if (command=="updateme") {
  148.                             llOwnerSay("Forwarding update request "+message);
  149.                             //llRemoteLoadScriptPin(llGetLinkKey(num), llGetScriptName(), pin, TRUE, 1);
  150.                             llShout(150, message);
  151.                         }
  152.                     }
  153.                 } else {
  154.                     //Ignore anything said by other drones on channel 0.
  155.                 }
  156.             } else {
  157.                 list packet = llParseString2List(message, ["|"], []);
  158.                 if (llListFindList(lastMessages, [message])==-1) {
  159.                     if (messagePurgeCountdown==0.0) {
  160.                         llSetTimerEvent(0.1);
  161.                         messagePurgeCountdown=5.0;
  162.                     }
  163.                     lastMessages += message;
  164.                     string command = llList2String(packet, 0);
  165.                     if (command=="updateme") {
  166.                         llOwnerSay("Updating "+llKey2Name(id));
  167.                            
  168.                         key id = (key) llList2String(packet, 1);
  169.                         llRemoteLoadScriptPin(id, llGetScriptName(), pin, TRUE, 1);
  170.                     }
  171.                 }
  172.             }
  173.         } else if (channel==0) {
  174.             //said by someone or something not belonging to our owner
  175.             llOwnerSay("<"+name+"> "+message);
  176.         }
  177.     }
  178.    
  179.     timer() {
  180.         if (messagePurgeCountdown<=0.1) {
  181.             if (llGetListLength(lastMessages)>0) {
  182.                 llListReplaceList(lastMessages, [], 0, 0);
  183.                 messagePurgeCountdown=5.0;
  184.             } else {
  185.                 messagePurgeCountdown=0.0;
  186.                 llSetTimerEvent(0.0);
  187.             }
  188.         } else {
  189.             messagePurgeCountdown-=0.1;
  190.         }
  191.     }
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement