Self-Destruct Primitive

From Second Life Wiki
Jump to navigation Jump to search

Introduction

This is a very simple script to self-destruct a primitive at a certain date and time which also survives simulator resets. All date and time references are set in UTC time because we do not want to overload the script too much.

Setup

In order to set a self-destruct time:

  • Create a new primitive and drop this script inside it. As soon as you do, you will see some overhead text appear, saying that the self-destruct is not armed.
  • Set the primitive's description to the date and time at which the primitive will self-destruct. The format is given by:
YYYY-MM-DD hh:mm

where the letters stand for:

Y - year, as four digits
M - month, as two digits
D - day, as two digits
h - hour, as two digits in 24hour time
m - minutes

An example could be:

2012-08-20 13:00

which would make the primitive self-destruct at 1PM on the 20th of August 2012.

Code

<lsl> ////////////////////////////////////////////////////////// // [K] Kira Komarov - 2011, License: GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html // // for legal details, rights of fair usage and // // the disclaimer and warranty conditions. // //////////////////////////////////////////////////////////

string zTimeDate;

default {

   state_entry() {
       llSensorRepeat("", NULL_KEY, AGENT, 0.1, 0.1, 1);
   }
   
   no_sensor() {
       llSensorRemove();
       zTimeDate = llGetObjectDesc();
       list cTimeDate = llParseString2List(zTimeDate, [" "], []);
       // Arm check
       list nTimeDate = llParseString2List(llGetTimestamp(),["-",":"],["T"]);
       list nDate = llParseString2List(llList2String(cTimeDate, 0), ["-"], []);
       list nTime = llParseString2List(llList2String(cTimeDate, 1), [":"], []);
       if(llGetListLength(nDate) + llGetListLength(nTime) != 5) {
           llSetText("Time now: " + llList2String(nTimeDate, 0) + "-" + llList2String(nTimeDate, 1) + "-" + llList2String(nTimeDate, 2) + " " + llList2String(nTimeDate, 4) + ":" + llList2String(nTimeDate, 5) + " UTC\nSelf-destruct is not armed.\n", <1,1,1>, 1.0);
           llSensorRepeat("", NULL_KEY, AGENT, 0.1, 0.1, 1);
           return;
       }
       llSetText("Time now: " + llList2String(nTimeDate, 0) + "-" + llList2String(nTimeDate, 1) + "-" + llList2String(nTimeDate, 2) + " " + llList2String(nTimeDate, 4) + ":" + llList2String(nTimeDate, 5) + " UTC\n" + "Self-Destruct: " + zTimeDate + " UTC", <1,1,1>, 1.0);
       llSetTimerEvent(1);
   }
   
   on_rez(integer pin) {
       llResetScript();
   }
   timer() {
       
       if(llGetObjectDesc() != zTimeDate) llResetScript();
       list nTimeDate = llParseString2List(llGetTimestamp(),["-",":"],["T"]);
       list nDate = llParseString2List(zTimeDate, ["-"], []);
       list nTime = llParseString2List(zTimeDate, [":"], []);
       if(llGetListLength(nDate) + llGetListLength(nTime) != 5) {
           llSetText("Time now: " + llList2String(nTimeDate, 0) + "-" + llList2String(nTimeDate, 1) + "-" + llList2String(nTimeDate, 2) + " " + llList2String(nTimeDate, 4) + ":" + llList2String(nTimeDate, 5) + " UTC\nSelf-destruct is not armed.\n", <1,1,1>, 1.0);
           llSensorRepeat("", NULL_KEY, AGENT, 0.1, 0.1, 1);
           return;
       }
       
       list cTimeDate = llParseString2List(zTimeDate, [" "], []);
       llSetText("Time now: " + llList2String(nTimeDate, 0) + "-" + llList2String(nTimeDate, 1) + "-" + llList2String(nTimeDate, 2) + " " + llList2String(nTimeDate, 4) + ":" + llList2String(nTimeDate, 5) + " UTC\n" + "Self-Destruct: " + llGetObjectDesc() + " UTC", <1,1,1>, 1.0);
       list zDate = llParseString2List(llList2String(cTimeDate, 0), ["-"], []);    
       if(llList2Integer(zDate, 0) < llList2Integer(nTimeDate, 0)) return;
       if(llList2Integer(zDate, 1) < llList2Integer(nTimeDate, 1)) return;
       if(llList2Integer(zDate, 2) < llList2Integer(nTimeDate, 2)) return;
       
       list zTime = llParseString2List(llList2String(cTimeDate, 1), [":"], []);
       if(llList2Integer(zTime, 0) < llList2Integer(nTimeDate, 4)) return;
       if(llList2Integer(zTime, 1) < llList2Integer(nTimeDate, 5)) return;
       
       llDie();
   }

} </lsl>