RentalBoxv1

From Second Life Wiki
Revision as of 21:59, 1 October 2009 by Sendao Goodman (talk | contribs) (Created page with '<lsl> // Configure here: float linden_per_day=4800.0; float warning_1_daysleft = 1.000; float warning_2_daysleft = 3.000; string warning_1 = "Warning, rent is up in 1 day"; strin...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<lsl> // Configure here: float linden_per_day=4800.0; float warning_1_daysleft = 1.000; float warning_2_daysleft = 3.000; string warning_1 = "Warning, rent is up in 1 day"; string warning_2 = "Warning, rent is up in 3 days";

// warn_owner=0; // only sends messages when rent is overdue integer warn_owner=1; // sends all warnings to admin as well as renter


// Below this is the script integer mystat=0; string timetil; list times; float days_left=0.0; integer last_time; key renter; string renter_name;

string hexc="0123456789ABCDEF";//faster string float2str(float input) {// Copyright Strife Onizuka, 2006, LGPL, http://www.gnu.org/copyleft/lesser.html

   if((integer)input != input)//LL screwed up hex integers support in rotation & vector string typecasting
   {//this also keeps zero from hanging the zero stripper.
       float unsigned = llFabs(input);//logs don't work on negatives.
       integer exponent = llFloor(llLog(unsigned) / 0.69314718055994530941723212145818);//floor(log2(b))
       if(exponent > 127) exponent = 127;//catch fatal rounding error in exponent.
       integer mantissa = (integer)((unsigned / (float)("0x1p"+(string)exponent)) * 0x1000000);//shift up into integer range
       while(!(mantissa & 0x1))
       {//strip extra zeros off before converting or they break "p"
           mantissa = mantissa >> 1;
           exponent = -~exponent;//++c;
       }
       string str = "p" + (string)(exponent - 24);
       do
           str = llGetSubString(hexc,15&mantissa,15&mantissa) + str;
       while(mantissa = mantissa >> 4);
       if(input < 0)
           return "-0x" + str;
       return "0x" + str;
   }//integers pack well so anything that qualifies as an integer we dump as such, supports netative zero
   return llDeleteSubString((string)input,-7,-1);//trim off the float portion, return an integer

}

default {

   state_entry()
   {
       mystat=1;
       llSetText("Rental Script v1", <0,1,0>, 1.0 );
       if( llGetStatus( STATUS_PHYSICS ) == TRUE ) {
           mystat=0;
           days_left = 0.0;
           last_time = llGetUnixTime();
       } else {
           list lStatus = llParseString2List( llGetObjectDesc(), ["~"], [] );
           days_left = llList2Float(lStatus,0);
           last_time = llList2Integer(lStatus,1);
           renter = llList2Key(lStatus,2);
           if( days_left <= 0.0 || last_time <= 0 ) {
               mystat=0;
               days_left = 0.0;
               last_time = llGetUnixTime();
           }
       }
       llSetTimerEvent(0.5);
   }
   timer()
   {
       if( mystat == 0 ) return;
       days_left -= ((float)(last_time=llGetUnixTime())-(float)last_time)/3600.0;
       llSetObjectDesc( float2str(days_left) + "~" + (string)last_time + "~" + (string)renter );
       if( days_left <= 0.0 ) {
           llInstantMessage( llGetOwner(), "Rent is overdue" );
           days_left = 0.0;
           llSetText("Expired", <1,0,0>, 1.0);
           mystat=0;
           return;
       } else if( mystat<3 && days_left <= warning_1_daysleft ) {
           if( warn_owner ) {
               llInstantMessage( llGetOwner(), warning_1 );
           }
           llInstantMessage( renter, warning_1 );
           mystat=3;
       } else if( mystat<2 && days_left <= warning_2_daysleft ) {
           if( warn_owner ) {
               llInstantMessage( llGetOwner(), warning_2 );
           }
           llInstantMessage( renter, warning_2 );
           mystat=2;
       }
       integer daysleft = (integer) llFloor(days_left);
       float hoursleft = 24.0*(days_left-(float)daysleft);
       llSetText(renter_name + ": " + (string)daysleft + " days, " + (string)hoursleft + " hours", <1,1,1>, 0.5);
   }
   money(key giver, integer amt)
   {
       if( mystat == 0 ) {
           renter=giver;
           list lDet = llGetObjectDetails( renter, [ OBJECT_NAME ] );
           renter_name = llList2String(lDet,0);
           llSay(0, "renter is " + renter_name);
           mystat=1;
       }
       llSay(0, "Pushed clock back " + (string)((float)amt/linden_per_day) + " days");
       days_left += (float)amt/linden_per_day;
   }

} </lsl>