CODE
integer rentperiod = 7;
integer rentcost;
string rentinfonotecard = "_RentInformation_";
string rentadtexture = "_RentAdTexture_";
string rentscript;
string rentboardowner;
integer amountpaid = 0;
key renterkey;
string rentername;
integer countdown = 0;
string ItemNotecard="";
string ItemLandmark="";
string ItemObject="";
string ItemTexture="";
string Day2Left = "No";
string Day1Left = "No";
string tstring;
delnonowneritems()
{
integer x;
for (x = llGetInventoryNumber(INVENTORY_ALL) ; x >= 0 ; x--)
{
tstring = llGetInventoryName(INVENTORY_ALL, x);
if ((tstring != rentinfonotecard) && (tstring != rentadtexture) && (tstring != rentscript) && (tstring != ""))
{
llRemoveInventory(tstring);
}
}
}
default
{
state_entry()
{
// llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);
rentboardowner = llKey2Name(llGetOwner());
state init;
}
}
state init
{ //Initialize
state_entry()
{
amountpaid = 0;
rentername = "";
renterkey = NULL_KEY;
countdown = 0;
ItemNotecard="";
ItemLandmark="";
ItemObject="";
ItemTexture="";
Day2Left = "No";
Day1Left = "No";
rentcost = (integer)llGetObjectDesc();
rentscript = llGetScriptName();
llSetTexture(rentadtexture, 0);
delnonowneritems();
state waitforrenter;
}
on_rez(integer i) {llResetScript();}
}
state waitforrenter
{ //Accept payment or dispense "about me" notecard
state_entry()
{
llInstantMessage(llGetOwner(), "Ready to rent...");
llSetPayPrice(PAY_DEFAULT, [PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT]);
// llSetPayPrice(PAY_HIDE, [1, (rentcost*2), (rentcost*3), (rentcost*4)]);
}
touch_start(integer num)
{
if (llGetInventoryType(rentinfonotecard) == INVENTORY_NONE)
{
llInstantMessage(llDetectedKey(0), "Sorry, I don't have instructions to dispense. Please notify "+rentboardowner);
return;
}
integer perm_mask = llGetInventoryPermMask(rentinfonotecard, MASK_OWNER);
if(perm_mask & PERM_COPY)
{
llGiveInventory(llDetectedKey(0), rentinfonotecard);
}
else
{
llInstantMessage(llDetectedKey(0), "Sorry, I don't have permission to dispense instructions. Please notify "+rentboardowner);
}
}
money(key id, integer amount)
{
if ((amount/rentcost) != (integer)(amount/rentcost))
{
llGiveMoney(id, amount);
llInstantMessage(id, "Refunding, the cost to rent this per week is L$"+(string)rentcost);
return;
}
countdown = (amount / rentcost) * 7 * 24 * 60 * 60; //Seven days in a week, 24 hours in a day, 60 mins in an hour, 60 seconds in a min
llInstantMessage(id, "Thank You "+llKey2Name(id)+", you now have "+(string)(countdown/60/60/24)+" days left on your rent");
renterkey = id;
rentername = llKey2Name(renterkey);
amountpaid = amount;
state acceptitems;
}
link_message(integer sender_num, integer num, string str, key id)
{
if (str == "reset")
{
llInstantMessage(llGetOwner(), "Resetting, please wait...");
llResetScript();
}
}
on_rez(integer i) {llResetScript();}
}
state acceptitems
{ //CTRL drag items into contents
state_entry()
{
llSetTimerEvent(30 * 60);
llAllowInventoryDrop(TRUE);
llInstantMessage(renterkey, "Please hold down the CTRL key and drag an image, notecard, and landmark onto me. Click me when finished to begin displaying your advertisement");
}
timer()
{
llInstantMessage(renterkey, "Did not accept items and start advertisement within 30 minutes, issuing refund");
llGiveMoney(renterkey, amountpaid);
state init;
}
link_message(integer sender_num, integer num, string str, key id)
{
if (str == "reset")
{
llInstantMessage(llGetOwner(), "Resetting, please wait...");
llResetScript();
}
}
touch_start(integer num)
{
if (llDetectedKey(0) != renterkey)
{
return;
}
llInstantMessage(renterkey, "Preparing your advertisement...");
if (ItemTexture != "")
{ llInstantMessage(renterkey, "Texture: "+ItemTexture); }
else
{ llInstantMessage(renterkey, "Texture: <none>"); }
if (ItemNotecard != "")
{ llInstantMessage(renterkey, "Notecard: "+ItemNotecard); }
else
{ llInstantMessage(renterkey, "Notecard: <none>"); }
if (ItemObject != "")
{ llInstantMessage(renterkey, "Object: "+ItemObject); }
else
{ llInstantMessage(renterkey, "Object: <none>"); }
if (ItemLandmark != "")
{ llInstantMessage(renterkey, "Landmark: "+ItemLandmark); }
else
{ llInstantMessage(renterkey, "Landmark: <none>"); }
if ((ItemTexture == "") || (ItemNotecard == "") || (ItemObject == "") || (ItemLandmark == ""))
if ((ItemTexture == "") || (ItemNotecard == "") || (ItemLandmark == ""))
{
llInstantMessage(renterkey, "One of each item is required to start renting this board");
return;
}
llListen(50, "", renterkey, "");
llDialog(renterkey, "Are you ready?", ["Yes", "No"], 50);
}
listen(integer channel, string name, key id, string message)
{
if (channel != 50)
{
return;
}
if (message == "Yes")
{
state dispense;
}
}
changed(integer mask)
{
integer i;
for (i=0 ; i<llGetInventoryNumber(INVENTORY_ALL) ; i++)
{
string tstring = llGetInventoryName(INVENTORY_ALL, i);
if ((tstring != rentadtexture) && (tstring != rentinfonotecard) && (tstring != rentscript))
{
if (llGetInventoryPermMask(tstring, MASK_NEXT) & PERM_COPY)
{}
else
{
llInstantMessage(renterkey, "I do not have COPY permission to distribute "+tstring);
llGiveInventory(renterkey, tstring);
return;
}
}
}
if(mask & (CHANGED_ALLOWED_DROP | CHANGED_INVENTORY))
{
integer i;
for (i=0 ; i<llGetInventoryNumber(INVENTORY_TEXTURE) ; i++)
{
string tstring = llGetInventoryName(INVENTORY_TEXTURE, i);
if ((tstring != ItemTexture) && (tstring != rentadtexture) && (ItemTexture != ""))
{
llInstantMessage(renterkey, "Replacing "+ItemTexture+" with "+tstring);
llRemoveInventory(ItemTexture);
ItemTexture=tstring;
return;
}
if ((tstring != rentadtexture) && (ItemTexture == ""))
{
llInstantMessage(renterkey, "Recieved Texture: "+tstring);
ItemTexture=tstring;
return;
}
}
for (i=0 ; i<llGetInventoryNumber(INVENTORY_NOTECARD) ; i++)
{
string tstring = llGetInventoryName(INVENTORY_NOTECARD, i);
if ((tstring != ItemNotecard) && (tstring != rentinfonotecard) && (ItemNotecard != ""))
{
llInstantMessage(renterkey, "Replacing "+ItemNotecard+" with "+tstring);
llRemoveInventory(ItemNotecard);
ItemNotecard=tstring;
return;
}
if ((tstring != rentinfonotecard) && (ItemNotecard == ""))
{
llInstantMessage(renterkey, "Recieved Notecard: "+tstring);
ItemNotecard=tstring;
return;
}
}
for (i=0 ; i<llGetInventoryNumber(INVENTORY_OBJECT) ; i++)
{
string tstring = llGetInventoryName(INVENTORY_OBJECT, i);
if ((tstring != ItemObject) && (ItemObject != ""))
{
llInstantMessage(renterkey, "Replacing "+ItemObject+" with "+tstring);
llRemoveInventory(ItemObject);
ItemObject=tstring;
return;
}
if (ItemObject == "")
{
string tstring = llGetInventoryName(INVENTORY_OBJECT, i);
llInstantMessage(renterkey, "Recieved Object: "+tstring);
ItemObject=tstring;
return;
}
}
for (i=0 ; i<llGetInventoryNumber(INVENTORY_LANDMARK) ; i++)
{
string tstring = llGetInventoryName(INVENTORY_LANDMARK, i);
if ((tstring != ItemLandmark) && (ItemLandmark != ""))
{
llInstantMessage(renterkey, "Replacing "+ItemLandmark+" with "+tstring);
llRemoveInventory(ItemLandmark);
ItemLandmark=tstring;
return;
}
if (ItemLandmark == "")
{
string tstring = llGetInventoryName(INVENTORY_LANDMARK, i);
llInstantMessage(renterkey, "Recieved Landmark: "+tstring);
ItemLandmark=tstring;
return;
}
}
}
}
on_rez(integer i) {llResetScript();}
}
state dispense
{ //Also allows lease extension by either renter or owner
state_entry()
{
if (ItemTexture != "")
{
llSetTexture(ItemTexture, 0);
}
llInstantMessage(renterkey, "Your advertisement has now began...");
llSetTimerEvent(60);
llSetPayPrice(PAY_HIDE, [0, 0, 0, 0]);
if (countdown <= (3 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, 0, 0, 0]);
}
if (countdown <= (2 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, (rentcost*2), 0, 0]);
}
if (countdown <= (1 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, (rentcost*2), (rentcost*3), 0]);
}
}
link_message(integer sender_num, integer num, string str, key id)
{
if (str == "reset")
{
llInstantMessage(llGetOwner(), "Resetting, please wait...");
llResetScript();
}
}
money(key id, integer amount)
{
if ((amount/rentcost) != (integer)(amount/rentcost))
{
llGiveMoney(id, amount);
llInstantMessage(id, "Refunding, the cost to rent this per week is L$"+(string)rentcost);
return;
}
if ((id != llGetOwner()) && (id != renterkey))
{
llGiveMoney(id, amount);
llInstantMessage(id, "Only the owner or current renter can extend the rental period. Issuing refund");
return;
}
countdown += (amount / rentcost) * 7 * 24 * 60 * 60; //Seven days in a week, 24 hours in a day, 60 mins in an hour, 60 seconds in a min
llInstantMessage(id, "Thank You "+llKey2Name(id)+", you now have "+(string)(countdown/60/60/24)+" days left on your rent");
llSetPayPrice(PAY_HIDE, [0, 0, 0, 0]);
if (countdown <= (3 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, 0, 0, 0]);
}
if (countdown <= (2 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, (rentcost*2), 0, 0]);
}
if (countdown <= (1 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, (rentcost*2), (rentcost*3), 0]);
}
}
touch_start(integer num)
{
if (ItemNotecard != "")
{
llGiveInventory(llDetectedKey(0), ItemNotecard);
}
if (ItemObject != "")
{
llGiveInventory(llDetectedKey(0), ItemObject);
}
if (ItemLandmark != "")
{
llGiveInventory(llDetectedKey(0), ItemLandmark);
}
}
timer()
{
countdown -= 60;
llSetPayPrice(PAY_HIDE, [0, 0, 0, 0]);
if (countdown <= (3 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, 0, 0, 0]);
}
if (countdown <= (2 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, (rentcost*2), 0, 0]);
}
if (countdown <= (1 * 7 * 24 * 60 * 60))
{
llSetPayPrice(PAY_HIDE, [rentcost, (rentcost*2), (rentcost*3), 0]);
}
if ((Day2Left == "No") && (countdown < (3600 * 48)))
{
Day2Left="Yes";
llInstantMessage(renterkey, "You have less than two days left on your rent at "+(string)(llGetParcelDetails(llGetPos(), [PARCEL_DETAILS_NAME])));
return;
}
if ((Day1Left == "No") && (countdown < (3600 * 24)))
{
Day1Left="Yes";
llInstantMessage(renterkey, "You have less than one day left on your rent at "+(string)(llGetParcelDetails(llGetPos(), [PARCEL_DETAILS_NAME])));
return;
}
if (countdown < 0 )
{
llInstantMessage(renterkey, "Your rent at "+(string)(llGetParcelDetails(llGetPos(), [PARCEL_DETAILS_NAME]))+" has expired.");
state init;
}
}
on_rez(integer i) {
llResetScript();
}
}

