andsim

Rental lsl

Jun 16th, 2011
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.82 KB | None | 0 0
  1. //Rental Script v1.5.3
  2. //Copyright 2003-2009 by Hank Ramos
  3.  
  4. //Options
  5. vector rentalOffset = <0,0,10>;
  6. float updateInterval = 60.0; //seconds
  7. string infoNotecard = "Rent This Space Info";
  8.  
  9. //Variables
  10. string tierName;
  11. float rentalCost;
  12. integer primCount;
  13. integer rentalVolume;
  14. float refundFee;
  15. key renterID;
  16. string renterName;
  17. float rentalTime;
  18. integer listenQueryID;
  19. vector initPos;
  20. vector initScale;
  21. integer count;
  22. integer lineCount;
  23. key readKey;
  24. string rentalGrade;
  25. integer primAllotment;
  26.  
  27. //Constants
  28. float ONE_WEEK = 604800.0;
  29. float ONE_DAY = 86400.0;
  30. float ONE_HOUR = 3600.0;
  31.  
  32.  
  33. dispString(string value)
  34. {
  35. llSetText(value, <1,1,1>, 1);
  36. }
  37. sendReminder(string message)
  38. {
  39. llInstantMessage(renterID, "Your lease located in " + llGetRegionName() + " (" + (string)initPos.x + "," + (string)initPos.y + "," + (string)initPos.z + ") will expire " + message);
  40. }
  41. saveData()
  42. {
  43. list saveData;
  44. vector storageVector;
  45.  
  46. saveData += renterID;
  47. saveData += renterName;
  48. saveData += llRound(rentalTime);
  49. storageVector = initPos * 1000;
  50. saveData += "<" + (string)llRound(storageVector.x) + "," + (string)llRound(storageVector.y) + "," + (string)llRound(storageVector.z) + ">";
  51. storageVector = initScale * 1000;
  52. saveData += "<" + (string)llRound(storageVector.x) + "," + (string)llRound(storageVector.y) + "," + (string)llRound(storageVector.z) + ">";
  53.  
  54. llSetObjectDesc(llDumpList2String(saveData, "|"));
  55. }
  56. string getTimeString(integer time)
  57. {
  58. integer days;
  59. integer hours;
  60. integer minutes;
  61. integer seconds;
  62.  
  63. days = llRound(time / 86400);
  64. time = time % 86400;
  65.  
  66. hours = (time / 3600);
  67. time = time % 3600;
  68.  
  69. minutes = time / 60;
  70. time = time % 60;
  71.  
  72. seconds = time;
  73.  
  74. return (string)days + " days, " + (string)hours + " hours, " + (string)minutes + " minutes"; // + ":" + (string)seconds;
  75. }
  76.  
  77. integer setupDialogListen()
  78. {
  79. integer chatChannel = (integer)llFrand(2000000);
  80. llListenRemove(listenQueryID);
  81. listenQueryID = llListen(chatChannel, "", NULL_KEY, "");
  82. return chatChannel;
  83. }
  84.  
  85. updateTimeDisp()
  86. {
  87. dispString("Leased by: " + renterName + "\nTime Remaining: " + getTimeString(llRound(rentalTime)));
  88. }
  89.  
  90. dispData()
  91. {
  92. llSay(0, "========================");
  93. llSay(0, "Rental Space Information");
  94. llSay(0, "========================");
  95. llSay(0, "This space is currently leased by " + renterName);
  96. llSay(0, "The current rental price is L$" + (string)((integer)rentalCost) + " per week.");
  97. llSay(0, "This space will be open for lease in " + getTimeString(llRound(rentalTime)) + ".");
  98. llSay(0, "Memory Free: " + (string)llGetFreeMemory());
  99. }
  100. default
  101. {
  102. state_entry()
  103. {
  104. state initialize;
  105. }
  106. }
  107.  
  108. state initialize
  109. {
  110. state_entry()
  111. {
  112. llSetTimerEvent(300);
  113. llOwnerSay("Waiting to obtain Debit Permissions.");
  114. llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
  115. }
  116. run_time_permissions(integer permissions)
  117. {
  118. //Only wait for payment if the owner agreed to pay out money
  119. if (permissions & PERMISSION_DEBIT)
  120. {
  121. state loadSettings;
  122. }
  123. }
  124. on_rez(integer start_param)
  125. {
  126. llResetScript();
  127. }
  128. timer()
  129. {
  130. llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
  131. }
  132. touch_start(integer total_number)
  133. {
  134. integer x;
  135. for (x = 0; x < total_number; x += 1)
  136. {
  137. if (llDetectedKey(x) == llGetOwner())
  138. {
  139. llResetScript();
  140. }
  141. }
  142. llSay(0, "Waiting to obtain Debit Permissions from Owner.");
  143. }
  144. state_exit()
  145. {
  146. llSetTimerEvent(0);
  147. llSay(0, "Initialized.");
  148. }
  149. }
  150.  
  151. state loadSettings
  152. {
  153. state_entry()
  154. {
  155. integer found = FALSE;
  156. integer x;
  157.  
  158. count = 0;
  159. lineCount = 0;
  160.  
  161. list savedList = llCSV2List(llGetObjectDesc());
  162.  
  163. if (llGetListLength(savedList) == 4)
  164. {
  165. rentalGrade = llList2String(savedList, 0);
  166. }
  167. else
  168. {
  169. rentalGrade = llGetObjectDesc();
  170. }
  171. for (x = 0; x < llGetInventoryNumber(INVENTORY_NOTECARD); x += 1)
  172. {
  173. if (llGetInventoryName(INVENTORY_NOTECARD, x) == "Settings")
  174. {
  175. found = TRUE;
  176. }
  177. }
  178. if (found)
  179. {
  180. llOwnerSay("Reading Settings Notecard...");
  181. readKey = llGetNotecardLine("Settings", lineCount);
  182. }
  183. else
  184. {
  185. llOwnerSay("Settings Notecard Not Found.");
  186. llResetScript();
  187. }
  188. }
  189. dataserver(key requested, string data)
  190. {
  191. integer integerData;
  192. float floatData;
  193.  
  194. if (requested == readKey)
  195. {
  196. if (data != EOF)
  197. {
  198. if ((llSubStringIndex(data, "#") != 0) && (data != "") && (data != " "))
  199. {
  200. integerData = (integer)data;
  201. floatData = (float)data;
  202.  
  203. if (count == 0)
  204. {
  205. tierName = data;
  206. }
  207. else if (count == 1)
  208. {
  209. if (integerData >= 0)
  210. {
  211. rentalCost = integerData;
  212. }
  213. else
  214. {
  215. rentalCost = 0;
  216. }
  217. }
  218. else if (count == 2)
  219. {
  220. if (integerData >= 1)
  221. {
  222. primCount = integerData;
  223. }
  224. else
  225. {
  226. primCount = 1;
  227. }
  228. }
  229. else if (count == 3)
  230. {
  231. if (integerData >= 16)
  232. {
  233. rentalVolume = integerData;
  234. }
  235. else
  236. {
  237. rentalVolume = 16;
  238. }
  239. }
  240. else if (count == 4)
  241. {
  242. if (integerData >= 0)
  243. {
  244. refundFee = integerData;
  245. }
  246. else
  247. {
  248. refundFee = 0;
  249. }
  250. }
  251. else if (count == 5)
  252. {
  253. rentalOffset = (vector)data;
  254. }
  255. else if (count == 6)
  256. {
  257. infoNotecard = data;
  258. }
  259. count += 1;
  260. }
  261. lineCount += 1;
  262. readKey = llGetNotecardLine("Settings", lineCount);
  263. }
  264. else
  265. {
  266. llOwnerSay("===============");
  267. llOwnerSay("Settings Loaded");
  268. llOwnerSay("===============");
  269. llOwnerSay("Space Name: " + tierName);
  270. llOwnerSay("Rental Cost: L$" + (string)llRound(rentalCost));
  271. llOwnerSay("Prim Count: " + (string)primCount);
  272. llOwnerSay("Space Volume: " + (string)rentalVolume + " sqm");
  273. llOwnerSay("Refund Fee: L$" + (string)refundFee);
  274. llOwnerSay("===============");
  275. llOwnerSay("Ready for Service!");
  276.  
  277. list savedList = llParseString2List(llGetObjectDesc(), ["|"], []);
  278.  
  279. if (llGetListLength(savedList) == 5)
  280. {
  281. renterID = llList2Key(savedList, 01);
  282. renterName = llList2String(savedList, 1);
  283. rentalTime = llList2Integer(savedList, 2);
  284. initPos = (vector)llList2String(savedList, 3) / 1000;
  285. initScale = (vector)llList2String(savedList, 4) / 1000;
  286. state rented;
  287. }
  288. else
  289. {
  290. renterID = NULL_KEY;
  291. renterName = "Nobody";
  292. rentalTime = 0;
  293. initPos = llGetPos();
  294. initScale = llGetScale();
  295. state idle;
  296. }
  297. }
  298. }
  299. }
  300. }
  301. state idle
  302. {
  303. state_entry()
  304. {
  305. llSetObjectDesc("");
  306. llSetTexture("rentthisspace", ALL_SIDES);
  307. llSetScale(initScale);
  308. llSetPos(initPos);
  309. llSetTimerEvent(updateInterval);
  310.  
  311. dispString(tierName + "\nLease this space for L$" + (string)llRound(rentalCost) + " per week.\n" + (string)rentalVolume + " sq meters\n" + (string)primCount + " prims\nPay this Sign to begin your lease.");
  312. }
  313. moving_end()
  314. {
  315. initPos = llGetPos();
  316. }
  317. changed(integer change)
  318. {
  319. if (change & CHANGED_SCALE)
  320. {
  321. initScale = llGetScale();
  322. }
  323. }
  324. touch_start(integer num_detected)
  325. {
  326. integer x;
  327. integer chatChannel;
  328.  
  329. for (x = 0; x < num_detected; x += 1)
  330. {
  331. if (llDetectedKey(x) == llGetOwner())
  332. {
  333. llDialog(llGetOwner(), "Owner Options. Select one of the options below...", ["Info", "Reset"], setupDialogListen());
  334. return;
  335. }
  336. }
  337.  
  338. llSay(0, "Lease this space for L$" + (string)llRound(rentalCost) + " per week. " + (string)rentalVolume + " sq meters. " + (string)primCount + " prims. Pay this Sign to begin your lease.");
  339.  
  340. for (x = 0; x < num_detected; x += 1)
  341. {
  342. llGiveInventory(llDetectedKey(x), infoNotecard);
  343. }
  344. }
  345. listen(integer channel, string name, key id, string message)
  346. {
  347. if (message == "Reset")
  348. {
  349. llResetScript();
  350. }
  351. else if (message == "Info")
  352. {
  353. llListenRemove(listenQueryID);
  354. dispData();
  355. llSay(0, "Lease this space for L$" + (string)llRound(rentalCost) + " per week. " + (string)rentalVolume + " sq meters. " + (string)primCount + " prims. Pay this Sign to begin your lease.");
  356. llGiveInventory(id, infoNotecard);
  357. }
  358. }
  359. money(key id, integer amount)
  360. {
  361. if (amount >= rentalCost)
  362. {
  363. renterID = id;
  364. renterName = llKey2Name(renterID);
  365. rentalTime = ONE_WEEK * amount / rentalCost;
  366. saveData();
  367.  
  368. llSay(0, "Thank you " + renterName + " for leasing! Your lease will expire in " + getTimeString((integer)rentalTime) + ".");
  369.  
  370. state rented;
  371. }
  372. else
  373. {
  374. llSay(0, "This space costs L$" + (string)rentalCost + " to rent. Refunding paid balance.");
  375. llGiveMoney(id, amount);
  376. }
  377. }
  378. }
  379.  
  380. state rented
  381. {
  382. state_entry()
  383. {
  384. llSetTexture("infosign", ALL_SIDES);
  385. llSetScale(<0.5, 0.5, 0.5>);
  386. llSetPos(initPos + rentalOffset);
  387.  
  388. updateTimeDisp();
  389. llResetTime();
  390. llSetTimerEvent(updateInterval);
  391. }
  392. touch_start(integer num_detected)
  393. {
  394. integer x;
  395. key detectedKey;
  396.  
  397. for (x = 0; x < num_detected; x += 1)
  398. {
  399. detectedKey = llDetectedKey(x);
  400. if (detectedKey == llGetOwner())
  401. {
  402. llDialog(detectedKey, "Lease Options. Select one of the options below...", ["Refund Time", "Info", "Release", "Reset"], setupDialogListen());
  403. }
  404. else if (detectedKey == renterID)
  405. {
  406. llDialog(detectedKey, "Lease Options. Select one of the options below...", ["Refund Time", "Info"], setupDialogListen());
  407. }
  408. else
  409. {
  410. dispData();
  411. llGiveInventory(detectedKey, infoNotecard);
  412. }
  413. }
  414. }
  415. money(key id, integer amount)
  416. {
  417. if ((id == renterID)||(id == llGetOwner()))
  418. {
  419. float addTime;
  420.  
  421. addTime = ONE_WEEK*amount/rentalCost;
  422. rentalTime += addTime;
  423.  
  424. llInstantMessage(id, "Adding " + getTimeString(llRound(addTime)) + " to your lease. Lease Time is Now: " + getTimeString(llRound(rentalTime)) + ".");
  425. saveData();
  426. updateTimeDisp();
  427. }
  428. else
  429. {
  430. llInstantMessage(id, "Refunding Money...");
  431. llGiveMoney(id, amount);
  432. llInstantMessage(id, "This space is currently leased by " + renterName + ". This space will be open for lease in " + getTimeString(llRound(rentalTime)) + ".");
  433. }
  434. }
  435. listen(integer channel, string name, key id, string message)
  436. {
  437. integer refundAmount;
  438.  
  439. llListenRemove(listenQueryID);
  440.  
  441. if (message == "Info")
  442. {
  443. dispData();
  444. llGiveInventory(id, infoNotecard);
  445. }
  446. else if (message == "Refund Time")
  447. {
  448. llDialog(id, "Are you sure you want to TERMINATE your lease and refund your money, minus a L$" + (string)refundFee + " fee?", ["YES", "NO"], setupDialogListen());
  449. }
  450. else if (message == "YES")
  451. {
  452. refundAmount = llRound((rentalTime/ONE_WEEK)*rentalCost - refundFee);
  453. llInstantMessage(renterID, "Refunding L$" + (string)refundAmount + ", which includes a L$" + (string)refundFee + " termination fee.");
  454. llGiveMoney(renterID, refundAmount);
  455. llInstantMessage(llGetOwner(), "LEASE REFUNDED: leased by " + renterName + " located in " + llGetRegionName() + " (" + (string)initPos.x + "," + (string)initPos.y + "," + (string)initPos.z + ") has ended. Refunded L$" + (string)refundAmount + ".");
  456. state idle;
  457. }
  458. else if (message == "Release")
  459. {
  460. llDialog(id, "Are you sure you want to TERMINATE this lease with NO REFUND?", ["Yes", "No"], setupDialogListen());
  461. }
  462. else if (message == "Yes")
  463. {
  464. llInstantMessage(llGetOwner(), "LEASE TERMINATED: leased by " + renterName + " located in " + llGetRegionName() + " (" + (string)initPos.x + "," + (string)initPos.y + "," + (string)initPos.z + ") has ended. Refunded L$0.");
  465. state idle;
  466. }
  467. else if (message == "Reset")
  468. {
  469. llResetScript();
  470. }
  471. }
  472. timer()
  473. {
  474. float timeElapsed = llGetAndResetTime();
  475. if (timeElapsed > (updateInterval * 4))
  476. {
  477. timeElapsed = updateInterval;
  478. }
  479. rentalTime -= timeElapsed;
  480.  
  481. saveData();
  482.  
  483. updateTimeDisp();
  484.  
  485. //Process Reminders
  486. if (rentalTime <= 0)
  487. {
  488. llInstantMessage(llGetOwner(), "LEASE EXPIRED: leased by " + renterName + " located in " + llGetRegionName() + " (" + (string)initPos.x + "," + (string)initPos.y + "," + (string)initPos.z + ") has expired.");
  489.  
  490. state idle;
  491. }
  492. if ((rentalTime <= ONE_DAY)&&(rentalTime >= ONE_DAY - (updateInterval*2)))
  493. {
  494. sendReminder("in one day.");
  495. }
  496. else if ((rentalTime <= ONE_HOUR*12)&&(rentalTime >= ONE_HOUR*12 - (updateInterval*2)))
  497. {
  498. sendReminder("in 12 hours.");
  499. }
  500. else if ((rentalTime <= ONE_HOUR)&&(rentalTime >= ONE_HOUR - (updateInterval*2)))
  501. {
  502. sendReminder("in one hour.");
  503. }
  504. }
  505. }
Advertisement
Add Comment
Please, Sign In to add comment