Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * Saya 2018
  3. * AO Applier Script - Sends a seperate script in this prim's inventory begining "ao.SCRIPT_NAME" to the tail
  4. *
  5. * Negotiation with the tail is as follows
  6. * 1. Send a "BEGIN_PAIRING" command, and await a response from the tail (if one is attached to user, otherwise timeout)
  7. * 2. The tail will respond with a "READY," followed by pin code needed to send the script across
  8. * 3. We use the given PIN code to send the script across
  9. */
  10.  
  11.  
  12. integer pairing_channel = -91010;
  13.  
  14. // Function to send script who's name begins "ao."
  15. // integer pin: The PIN security code required by the tail to accept the script
  16. // key target:  The object that should recieve the script
  17. send_script(integer pin, key target)
  18. {
  19.     // 1. Find the script w/ name begining "ao."
  20.     integer num_scripts = llGetInventoryNumber(INVENTORY_SCRIPT);
  21.     integer i = 0;
  22.     string ao_script = "";
  23.     for (i = 0; i < num_scripts; i++)
  24.     {
  25.         string script_name = llGetInventoryName(INVENTORY_SCRIPT, i);
  26.         string script_begins = llList2String(llParseString2List(script_name, ["."], []), 0); // split the string on any dots(.) to find the first string
  27.         if (script_begins == "ao")
  28.         {
  29.             // found our ao script
  30.             ao_script = script_name;
  31.         }
  32.     }
  33.  
  34.     // Check that we actually found a script in that loop
  35.     if (ao_script == "")
  36.     {
  37.         llOwnerSay("This applier is missing an ao script. Please add one w/ name format 'ao.YOUR_AO_NAME' and attach me again");
  38.         detach();
  39.         return;
  40.     }
  41.     // if we got this far, everything is ready. Send the script across
  42.     llRemoteLoadScriptPin(target, ao_script, pin, TRUE, 0);
  43.     llOwnerSay("Installation Complete");
  44.     detach();
  45. }
  46.  
  47. detach()
  48. {
  49.     llRequestPermissions(llGetOwner(), PERMISSION_ATTACH); // this permission is auto-granted in an attachment
  50. }
  51.  
  52. default
  53. {
  54.     attach(key id)
  55.     {
  56.         if (id)
  57.         {
  58.             // On attach, we want to instantly install the new AO onto the users tail, so begin the pairing process now by asking the tail to pair
  59.             llListen(pairing_channel, "", NULL_KEY, "");
  60.             llSay(pairing_channel,"BEGIN_PAIRING"); // Send a message to the tail to begin pairing
  61.             llSetText("- Finding Tail -", <1,1,1>, 0.5); // keeping the user updated on what's happening
  62.             llSetTimerEvent(10); // If no message is recieved after 10 seconds, the users' tail is not currently attached so we can't install the animation
  63.         }
  64.         else
  65.         {
  66.             // Not attached anymore
  67.             llSetTimerEvent(FALSE);  
  68.             llSetText("- Inactive -", <1,1,1>, 0.5); // keeping the user updated on what's happening
  69.         }
  70.     }
  71.  
  72.     listen(integer channel, string name, key id, string message)
  73.     {
  74.         list cmd = llCSV2List(message); // the message is formatted as CSV comma seperated value ("READY,125") where 125 is the randomized pin code number needed to load the script
  75.         if (llList2String(cmd, 0) != "READY") return; // don't execute further if the first value is not "READY" as this message is just interference on the channel
  76.         if (llGetOwnerKey(id) != llGetOwner()) return; // don't execute further if the owner of the tail is not the same as the person who attached the applier (unlikely event)
  77.  
  78.         // If we got this far, we have a valid ready message, the pairing process is complete, now we send the script
  79.         llSetText("- Installing AO -", <1,1,1>, 0.5); // keeping the user updated on what's happening
  80.         integer pin = (integer)llList2String(cmd, 1);
  81.         send_script(pin,id);
  82.     }
  83.  
  84.     run_time_permissions(integer perm)
  85.     {
  86.         if (perm & PERMISSION_ATTACH)
  87.         {
  88.             llDetachFromAvatar();
  89.         }
  90.     }
  91.  
  92.     timer()
  93.     {
  94.         // Didn't find a tail
  95.         llOwnerSay("Tail not found - Please attach your tail first");
  96.         llSetTimerEvent(FALSE);
  97.         detach();
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement