Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Saya 2018
- * AO Applier Script - Sends a seperate script in this prim's inventory begining "ao.SCRIPT_NAME" to the tail
- *
- * Negotiation with the tail is as follows
- * 1. Send a "BEGIN_PAIRING" command, and await a response from the tail (if one is attached to user, otherwise timeout)
- * 2. The tail will respond with a "READY," followed by pin code needed to send the script across
- * 3. We use the given PIN code to send the script across
- */
- integer pairing_channel = -91010;
- // Function to send script who's name begins "ao."
- // integer pin: The PIN security code required by the tail to accept the script
- // key target: The object that should recieve the script
- send_script(integer pin, key target)
- {
- // 1. Find the script w/ name begining "ao."
- integer num_scripts = llGetInventoryNumber(INVENTORY_SCRIPT);
- integer i = 0;
- string ao_script = "";
- for (i = 0; i < num_scripts; i++)
- {
- string script_name = llGetInventoryName(INVENTORY_SCRIPT, i);
- string script_begins = llList2String(llParseString2List(script_name, ["."], []), 0); // split the string on any dots(.) to find the first string
- if (script_begins == "ao")
- {
- // found our ao script
- ao_script = script_name;
- }
- }
- // Check that we actually found a script in that loop
- if (ao_script == "")
- {
- llOwnerSay("This applier is missing an ao script. Please add one w/ name format 'ao.YOUR_AO_NAME' and attach me again");
- detach();
- return;
- }
- // if we got this far, everything is ready. Send the script across
- llRemoteLoadScriptPin(target, ao_script, pin, TRUE, 0);
- llOwnerSay("Installation Complete");
- detach();
- }
- detach()
- {
- llRequestPermissions(llGetOwner(), PERMISSION_ATTACH); // this permission is auto-granted in an attachment
- }
- default
- {
- attach(key id)
- {
- if (id)
- {
- // 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
- llListen(pairing_channel, "", NULL_KEY, "");
- llSay(pairing_channel,"BEGIN_PAIRING"); // Send a message to the tail to begin pairing
- llSetText("- Finding Tail -", <1,1,1>, 0.5); // keeping the user updated on what's happening
- llSetTimerEvent(10); // If no message is recieved after 10 seconds, the users' tail is not currently attached so we can't install the animation
- }
- else
- {
- // Not attached anymore
- llSetTimerEvent(FALSE);
- llSetText("- Inactive -", <1,1,1>, 0.5); // keeping the user updated on what's happening
- }
- }
- listen(integer channel, string name, key id, string message)
- {
- 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
- 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
- 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)
- // If we got this far, we have a valid ready message, the pairing process is complete, now we send the script
- llSetText("- Installing AO -", <1,1,1>, 0.5); // keeping the user updated on what's happening
- integer pin = (integer)llList2String(cmd, 1);
- send_script(pin,id);
- }
- run_time_permissions(integer perm)
- {
- if (perm & PERMISSION_ATTACH)
- {
- llDetachFromAvatar();
- }
- }
- timer()
- {
- // Didn't find a tail
- llOwnerSay("Tail not found - Please attach your tail first");
- llSetTimerEvent(FALSE);
- detach();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement