auto-lease add-on scripts
From Apez
The auto-lease v2.x and v3.x support custom add-on scripts so that you can customize behaviour or integrate the auto-lease with other devices or services.
Each unit sends link messages and chat messages to add-on scripts either in each unit or in external devices (in which case they'll receive updates from all auto-lease units within the same sim (3.x) or within 100m (2.x))
The auto-lease v3.x package contains the add-on kit and some example scripts to get you started. Below are some scripts that you may find useful. If you develop one that you think other may benefit from, please add it below!
To add the script:
- Create a new script in the Content tab of an auto-lease unit. It'll be called "New Script" by default.
- Edit the name appropriately (select it and press F2)
- Double-click to open/edit it. Copy the script code below and paste it into the script window in SL, click 'save' and you're done.
If you want to place such a script in multiple units, it is simplest to either put it into one unit and them copy the units as you deploy them, or if you've got unit rezzed already, copy the script into your inventory (drag it) and then drag it into each unit.
Hover-text customization for v3.x
The auto-lease v3.0-3.4 have an option for hover-text. The setting allow enabling/disabling the text and changing its colour, but not complete customization. This add-on script over-rides the unit hover-text to prefix the unit/object name at the beginning. You can modify it to suit your needs.
It works by simply setting the hovertext after a 10sec delay of receiving updates from the unit. This ensures that if the unit sets the hovertext itself, that this script will set it afterward (hence there will be a 10sec delay before it sets the text and it will only set it after lease or time changes - so it will not update instantly when you first add the script to the unit - you'll need to force an update online or reset it). It is best to disable hover-text when using the script (either using the "text off" chat command or the online option).
Script: .HoverTextOverride 1.0
vector colour = <1,1,1>;
setHoverText()
{
integer hovertext_enabled = (leaseOptions & 2048) > 0;
if (autoLeaseKey==NULL_KEY) { // no data yet
if (!hovertext_enabled) llSetText("",<1,1,1>,1); // clear it
return;
}
string text = llGetObjectName()+": "; // prefix text with object name
integer locked = (leaseOptions & 4) > 0;
// some other option variable that might be useful (not currently used below)
integer reserved = (leaseOptions & 32) > 0;
if (leaseHolderKey == NULL_KEY) {
text += "For lease L$"+(string)leaseTimeUnitRate+"/"+sintervalName(leaseTimeUnit);
// if you want to display the remaining time, add +formatTime(leaseExpiryUnixtime-llGetUnixTime(),leaseTimeUnit)
}
else {
integer secsRemaining = leaseExpiryUnixtime - llGetUnixTime();
if (secsRemaining>0)
text += "Occupied by "+leaseHolderName;
else // -ve remaining secs => overdue
text += "Occupied by "+leaseHolderName+" (Overdue)";
}
if (locked) text += " [LOCKED]";
llSetText(text, colour, 1);
}
//
// The code below is taken from the standard add-on kit script example
//
integer AutoLeaseRequest = 432;
integer AutoLeaseStateChangeNum = 433;
integer AutoLeaseOutput = 434;
integer AL_NotifyType_Init = 0;
integer AL_NotifyType_Update = 1;
integer AL_NotifyType_LeaseChange = 2;
integer AL_NotifyType_TouchHold = 3; // v2.x only
integer AL_NotifyType_DaysChanged = 4;
integer AL_NotifyType_LinkChange = 5;
// stuff passed innotify events that we store here for printing out
key autoLeaseKey = NULL_KEY; // key of the Auto-Lease object
string model; // Auto-Lease model string
string usercookie; // cookie set by user (with 'setcookie' command)
string name; // its name
string locationName; // its location name
key leaseHolderKey=NULL_KEY; // key of lease holder avatar, if new lease, NULL_KEY otherwise
string leaseHolderName; // name of avatar or "unknown:<key>" if leased, or "VACANT" of not
integer leaseDaysRemaining; // number of days remaining on lease
integer leaseTimeUnitRate; // the rate in $L per time-unit (e.g. hour,day,week or month) [v2.x always week]
integer leasePrimLimit; // the prim limit
integer leaseExpiryUnixtime; // v3.x only - unixtime of lease expiry (in past if overdue)
string leaseTimeUnit; // v3.x only - "h"(hour), "d"(day), "w"(week) or "m"(month) [v2.x assume "w"]
integer leaseOptions; // v3.x only - options bitfield (undocumented)
string sintervalName(string interval)
{
if (interval=="w") return "week";
else if (interval=="m") return "month";
else if (interval=="d") return "day";
return "hour";
}
saveParameters(list alStateParams)
{
autoLeaseKey = (key)llList2String(alStateParams,1);
model = llList2String(alStateParams,2);
usercookie = llList2String(alStateParams,3);
name = llList2String(alStateParams,4);
locationName = llList2String(alStateParams,5);
leaseHolderKey = (key)llList2String(alStateParams,6);
leaseHolderName = (key)llList2String(alStateParams,7);
leaseDaysRemaining = llList2Integer(alStateParams,8);
leaseTimeUnitRate = llList2Integer(alStateParams,9);
leasePrimLimit = llList2Integer(alStateParams,10);
if (llGetListLength(alStateParams)>11) {
leaseExpiryUnixtime = llList2Integer(alStateParams,11);
leaseTimeUnit = llList2String(alStateParams,12);
leaseOptions = llList2Integer(alStateParams,13);
}
else { // v2.x
leaseExpiryUnixtime = llGetUnixTime() + 24*60*60*leaseDaysRemaining; // estimate
leaseTimeUnit = "w";
leaseOptions = 0;
}
}
string formatTime(integer timeRemaining, string leaseTimeUnit) // seconds
{
if (timeRemaining<0) timeRemaining = -timeRemaining;
integer minsRemaining = timeRemaining / 60;
integer hoursRemaining = timeRemaining / 3600;
integer daysRemaining = timeRemaining / 86400;
integer weeksRemaining = timeRemaining / 604800;
if (leaseTimeUnit=="t")
return (string)timeRemaining+"secs";
if (minsRemaining+hoursRemaining+daysRemaining+weeksRemaining==0)
return "less than a minute";
string s = "";
if (weeksRemaining > 0) {
s += (string)weeksRemaining+" week";
if (weeksRemaining>1) s += "s";
s += " ";
}
daysRemaining -= (weeksRemaining*7);
if (daysRemaining > 0) {
s += (string)daysRemaining+" day";
if (daysRemaining>1) s += "s";
s += " ";
}
hoursRemaining -= ((weeksRemaining*168)+(daysRemaining*24));
if (hoursRemaining > 0) {
s += (string)hoursRemaining+" hour";
if (hoursRemaining>1) s += "s";
s += " ";
}
minsRemaining -= ((hoursRemaining*60)+(weeksRemaining*168*60)+(daysRemaining*24*60));
if (minsRemaining > 0) {
s += (string)minsRemaining+" min";
if (minsRemaining>1) s += "s";
s += " ";
}
return s;
}
integer initialized = FALSE;
default
{
state_entry()
{
if (!initialized) {
setHoverText();
initialized=TRUE;
}
}
link_message(integer sender_num, integer num, string str, key id)
{
if (num == AutoLeaseStateChangeNum) {
// decode
list alStateParams = llParseStringKeepNulls(str, ["-=-"], [] );
integer notifyType = llList2Integer(alStateParams,0);
if (notifyType == AL_NotifyType_Init) {
autoLeaseKey = (key)llList2String(alStateParams,1);
model = llList2String(alStateParams,2);
//llOwnerSay("Got User Script Notification: "+model+" ["+(string)autoLeaseKey+"] Initialized");
}
else if (notifyType == AL_NotifyType_Update) {
//llOwnerSay("Got User Script Notification");
saveParameters(alStateParams);
}
else if (notifyType == AL_NotifyType_LeaseChange) {
//llOwnerSay("Got Lease state change Notification:");
saveParameters(alStateParams);
}
else if (notifyType == AL_NotifyType_DaysChanged) {
//llOwnerSay("Got Lease remaining time change Notification:");
saveParameters(alStateParams);
}
}
else if (num == AutoLeaseOutput) {
//llOwnerSay("Auto-Lease Output:"+str);
}
// got an update or link message activity that could indicate activity potentially setting hovertext,
// so, set a timer to restore it 10secs from now
llSetTimerEvent(0);
llSetTimerEvent(10);
}
timer()
{
// 10secs passes since any link message activity
setHoverText();
llSetTimerEvent(0); // disable timer
}
}
