Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Very advanced rental space script

Kick Madonna
Registered User
Join date: 19 Feb 2006
Posts: 16
04-03-2006 03:32
here it is. I was going to sale this, but i decided to ruin the market and release mime out for free. Have fun!!

You can reply to this thread for help. You need 3 images. One for the unleased state. One for unaviable/rent due, and one for the space being rented in the same object. Also a note card with more info on the space.

This leases by $L per day, it has a min and max peroid. It stores everything in the desc tag of the object so it can be reset and updated. It provides some other neat fatures. You can see it in action on my land (look for me in game and look at my picks for a tp).

Enjoy.

CODE

list my_data;
integer MY_STATE =0;
string LEASER = "";
key LEASERID;
integer RATE =0;
integer PERIOD =0; //DAYS
integer PRIMMAX =0;
integer MAXPERIOD =0;
integer CHANNEL = 192;
integer CREDIT = 0;
integer LEASED_UNTIL = 0;
integer IS_RENEWABLE = FALSE;
integer can_renew = FALSE;
integer DAYSEC = 86400;
integer SENT_WARNING = FALSE;
integer RENTWARNING = 3; //Day allowed to renew earlier
integer GRACEPERIOD = 3; // Days allowed to miss payment
vector FULL_SIZE = <1.5,.375,1.5>;
vector SMALL_SIZE = <.25,.25,.25>;
integer INIT = FALSE;

DEBUG(string data)
{
llOwnerSay("DEBUG: " + data);
}

string get_rentalbox_info()
{
return llGetRegionName() + " @ " + (string)llGetPos() + " (Leaser: \"" + LEASER + "\", Expire: " + timespan(LEASED_UNTIL - llGetUnixTime()) + ")";
}

string timespan(integer time)
{

integer days = time / DAYSEC;
integer curtime = (time / DAYSEC) - (time % DAYSEC);
integer hours = curtime / 3600;
integer minutes = (curtime % 3600) / 60;
integer seconds = curtime % 60;

return (string)llAbs(days) + " days, " + (string)llAbs(hours) + " hours, "
+ (string)llAbs(minutes) + " minutes, " + (string)llAbs(seconds) + " seconds";

}

load_data()
{
integer len;
my_data = llCSV2List(llGetObjectDesc());
len = llGetListLength(my_data);
RATE = llList2Integer(my_data,0);
PERIOD = llList2Integer(my_data,1);
MAXPERIOD = llList2Integer(my_data,2);
PRIMMAX = llList2Integer(my_data,3);
IS_RENEWABLE = llList2Integer(my_data, 4);
MY_STATE = llList2Integer(my_data, 5);
LEASER = llList2String(my_data, 6);
LEASERID = llList2Key(my_data, 7);
CREDIT = llList2Integer(my_data, 8);
LEASED_UNTIL = llList2Integer(my_data, 9);
SENT_WARNING = llList2Integer(my_data, 10);
}

save_data()
{
my_data = [RATE,PERIOD, MAXPERIOD, PRIMMAX, IS_RENEWABLE, MY_STATE, LEASER, LEASERID, CREDIT, LEASED_UNTIL, SENT_WARNING];
llSetObjectDesc(llList2CSV(my_data));
}

default
{
state_entry()
{
if (!INIT)
{
llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);
INIT = TRUE;
}
load_data();
llSetScale(SMALL_SIZE);
llSetTexture("lease-ex",ALL_SIDES);
llOwnerSay("Click this rental box to activate after configuring.");
llSetText("DISABLED",<0,0,0>, 1.0);
}

on_rez(integer start_param)
{
load_data();
}

money(key giver, integer ammount)
{
llWhisper(0,"Unable to accept money right now");
llGiveMoney(giver,ammount);
}

touch_start(integer total_number)
{
if (llDetectedKey(0) == llGetOwner())
{
load_data();
if (PERIOD == 0 || RATE ==0 || (!IS_RENEWABLE && LEASED_UNTIL < llGetUnixTime()))
{
llSay(0,"This space is not currently purchasble or requires configuration.");
}
else
{
llSay(0,"Activating...");
if (MY_STATE == 0)
state unleased;
else if (MY_STATE == 1)
state leased;
}
}
}
}

state unleased
{
state_entry()
{
load_data();
if (MY_STATE !=0 || PERIOD == 0 || RATE == 0 || !IS_RENEWABLE)
{
llOwnerSay("Returning to default. Data might not be correct.");
state default;
}
llSetScale(FULL_SIZE);
//Blank texture
llSetTexture("5748decc-f629-461c-9a36-a35a221fe21f",ALL_SIDES);
llSetTexture("lease-large",1);
llSetTexture("lease-large",3);
llOwnerSay("Lease script is active...");
llSetText("",<1,0,0>, 1.0);

}

money(key giver, integer ammount)
{
load_data();
if (ammount < RATE * PERIOD)
{
llSay(0,"Sorry, you didn't pay anough.");
llGiveMoney(giver, ammount);
}
else if (ammount > MAXPERIOD * RATE)
{
llSay(0,"Sorry, you payed more then the max allows.");
llGiveMoney(giver, ammount);
}
else
{
llSay(0,"Thanks for renting! Please wait a few moments...");
MY_STATE = 1;
LEASER = llKey2Name(giver);
LEASERID = giver;
if ((ammount % RATE) != 0)
{
llSay(0,"oops, you overpaid. Here is a partial refund");
llGiveMoney(giver,(ammount % RATE));
}
CREDIT = (ammount - (ammount % RATE))/RATE;
LEASED_UNTIL = llGetUnixTime() + (CREDIT * DAYSEC);
SENT_WARNING = FALSE;
save_data();
llInstantMessage(llGetOwner(), "NEW LEASE - $" + (string)(ammount - (ammount % RATE)) + "L - " + get_rentalbox_info());
state leased;
}

}

touch_start(integer total_number)
{
load_data();
llSay(0,"Bay Hills Lease");
//llSay(0,"Only $L" + (string)RATE + " per day");
llSay(0, "Only $L" + (string)(RATE * PERIOD) + " for " + (string)PERIOD + " days ($L" + (string)RATE + " per day)");
llSay(0, "Initial Min. Lease Time: " + (string)PERIOD + " days");
llSay(0, "Max Lease Payment Length: " + (string)MAXPERIOD + " days");
llSay(0, "Max Prims: " + (string)PRIMMAX);
llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_NOTECARD,0));
}
}

state leased
{
state_entry()
{
DEBUG("Leased mode");
DEBUG((string)llGetUnixTime());

load_data();
llSetScale(SMALL_SIZE);
llSetTexture("lease-question",ALL_SIDES);
llSetText("",<1,0,0>, 1.0);
if (MY_STATE != 1 || PERIOD == 0 || RATE == 0 || LEASER == "" || CREDIT == 0)
{
MY_STATE = 0;
save_data();
llOwnerSay("Returning to unleased. Data might not be correct.");
state unleased;
}
llSetTimerEvent(900); //15 minute checks

}

money(key giver, integer ammount)
{
load_data();
if (MY_STATE != 1 || PERIOD == 0 || RATE == 0 || LEASER == "" || CREDIT == 0)
{
MY_STATE = 0;
save_data();
llSay(0,"Returning to unleased. Data might not be correct.");
llGiveMoney(giver,ammount);
state unleased;
}

if (llGetOwner() != giver && giver != LEASERID)
{
llSay(0,"Well thats nice that you want to pay this rent but only the leaser may do so.");
llGiveMoney(giver,ammount);
}

else if (IS_RENEWABLE || llGetOwner() == giver)
{

integer timeleft = LEASED_UNTIL - llGetUnixTime();
integer curammount = (ammount - (ammount % RATE))/RATE; //Caculated sum after refund

if (((curammount * DAYSEC) + timeleft) > MAXPERIOD * DAYSEC)
{
llSay(0,"Sorry, you can not purchase more then the max time");
llGiveMoney(giver,ammount);
}
//**
//** - Not going to punish anyone right now after they sigh up. let them pay day by day
//**
//else if (((curammount * DAYSEC) + timeleft) < PERIOD * DAYSEC)
//{
// llSay(0,"You have to pay anough to meet the min time");
// llGiveMoney(giver,ammount);
//}
else
{

//Refund code
if ((ammount % RATE) != 0)
{
llSay(0,"oops, you overpaid. Here is a partial refund");
llGiveMoney(giver,(ammount % RATE));
}
CREDIT = curammount;
SENT_WARNING = FALSE;
LEASED_UNTIL += (curammount * DAYSEC);
save_data();
llSetScale(SMALL_SIZE);
llSetTexture("bayhill-question",ALL_SIDES);
llSetText("",<1,0,0>, 1.0);
llInstantMessage(llGetOwner(), "LEASE CREDIT - $" + (string) (curammount * RATE) + "L - " + get_rentalbox_info());
}
}
else
{
llGiveMoney(giver,ammount);
llSay(0,"Sorry you can not renew at this time.");
}

}

timer()
{
load_data();
if (MY_STATE != 1 || PERIOD == 0 || RATE == 0 || LEASER == "" || CREDIT == 0)
{
MY_STATE = 0;
save_data();
llSay(0,"Returning to unleased. Data might not be correct.");
state unleased;
}

if (IS_RENEWABLE)
{
if (LEASED_UNTIL > llGetUnixTime() && LEASED_UNTIL - llGetUnixTime() < RENTWARNING * DAYSEC)
{
llSetTexture("lease-ex",ALL_SIDES);
llSetText("Rent Due!",<1,0,0>, 1.0);
}
else if (LEASED_UNTIL < llGetUnixTime() && llGetUnixTime() - LEASED_UNTIL < GRACEPERIOD * DAYSEC)
{
if (!SENT_WARNING)
{
llInstantMessage(LEASERID, "Your rent is due! - " + get_rentalbox_info());
llInstantMessage(llGetOwner(), "RENT DUE - " + get_rentalbox_info());
SENT_WARNING = TRUE;
save_data();
}
llSetTexture("lease-ex",ALL_SIDES);
llSetText("RENT PAST DUE!",<1,0,0>, 1.0);
}
else if (LEASED_UNTIL < llGetUnixTime())
{
llInstantMessage(LEASERID, "Your lease has expired. Please clean up the space or contact the space owner.");
llInstantMessage(llGetOwner(), "LEASE EXPIRED: CLEANUP! - " + get_rentalbox_info());
MY_STATE = 0;
save_data();
state default;

}
}
else if (LEASED_UNTIL < llGetUnixTime())
{
llInstantMessage(llGetOwner(), "LEASE EXPIRED: CLEANUP! - " + get_rentalbox_info());
DEBUG("TIME EXPIRED. RETURNING TO DEFAULT");
state default;
}
}

touch_start(integer total_number)
{
load_data();
if (MY_STATE != 1 || PERIOD == 0 || RATE == 0 || LEASER == "" || CREDIT == 0)
{
MY_STATE = 0;
save_data();
llSay(0,"Returning to unleased. Data might not be correct.");
state unleased;
}


llSay(0,"Space currently rented by " + LEASER);
llSay(0,"Rent due in " + timespan(llGetUnixTime()-LEASED_UNTIL));
}

}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
04-03-2006 08:39
/15/47/98031/1.html
_____________________
i've got nothing. ;)
Persephone Phoenix
loving laptopvideo2go.com
Join date: 5 Nov 2004
Posts: 1,012
04-03-2006 19:59
From: Kick Madonna
here it is. I was going to sale this, but i decided to ruin the market and release mime out for free.


Dang. I just paid a small fortune for the rental script I use now, too. :-) Thank you though, Kick, for sharing your knowledge and work.
_____________________
Events are everyone's business.
Elliott Eldrich
Registered User
Join date: 8 Feb 2006
Posts: 4
Some documentation and/or examples and/or tutorials would be good
05-29-2006 15:37
Hello,

It's nice that you posted this script. However, many of us have very limited scripting skills, and while we would love to use a script like this, we simply do not have the skills to be able to use it. Some documentation would be awfully handy here, maybe an example or two, and for bonus points provide a tutorial? Because I really, really wanted to use this script, but after a couple of hours of working on it, finally gave up and bought a system from a vendor.
Ener Hax
disenfranchised $3K user
Join date: 18 Jun 2007
Posts: 29
05-16-2008 07:34
holy smokes! som eloquent scripting! thank you for making it public, can't wait to try it out!