024309af-b426-483c-7565-b156ae45fc3b_script.lsl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Sloodle PrimDrop inventory checker.
  4. // Receives dropped prims, and checks for the most recently added one
  5. // Part of the Sloodle project (www.sloodle.org)
  6. //
  7. // Copyright (c) 2007-8 Sloodle
  8. // Released under the GNU GPL
  9. //
  10. // Contributors:
  11. // Jeremy Kemp
  12. // Peter R. Bloomfield
  13. //
  14. ///// DATA /////
  15. // Link message channel
  16. integer SLOODLE_CHANNEL_PRIMDROP_INVENTORY = -1639270071;
  17. // Link message identifiers
  18. string PRIMDROP_RECEIVE_DROP = "do:receivedrop"; // Instructs the object to receive a drop
  19. string PRIMDROP_CANCEL_DROP = "do:canceldrop"; // Cancel drop receiving
  20. string PRIMDROP_FINISHED_DROP = "set:droppedobject"; // The drop has finished (object name passed as parameter after pipe character)
  21. // Stores the inventory
  22. list inventory = [];
  23. ///// FUNCTIONS /////
  24. // Returns a list of all inventory (all types)
  25. list get_inventory(integer type)
  26. {
  27. list inv = [];
  28. integer num = llGetInventoryNumber(type);
  29. integer i;
  30. for (i = 0; i < num; i++) {
  31. inv += [llGetInventoryName(type, i)];
  32. }
  33. return inv;
  34. }
  35. // Compares 2 lists
  36. // Returns the first item on list1 that is not on list2
  37. // Returns an empty string if nothing is found
  38. string ListDiff(list list1, list list2) {
  39. integer i;
  40. for (i = 0; i < llGetListLength(list1); i++) {
  41. if (llListFindList(list2, llList2List(list1, i, i)) == -1) {
  42. return(llList2String(list1, i));
  43. }
  44. }
  45. return("");
  46. }
  47. ///// STATES /////
  48. // Idle state - waiting to be instructed to receive a drop
  49. default
  50. {
  51. state_entry()
  52. {
  53. llAllowInventoryDrop(FALSE);
  54. }
  55. link_message(integer sender_num, integer num, string sval, key kval)
  56. {
  57. // Check the channel
  58. if (num == SLOODLE_CHANNEL_PRIMDROP_INVENTORY) {
  59. if (sval == PRIMDROP_RECEIVE_DROP) {
  60. // Start awaiting a drop
  61. state drop;
  62. return;
  63. }
  64. }
  65. }
  66. }
  67. // Waiting for a drop to take place
  68. state drop
  69. {
  70. state_entry()
  71. {
  72. // Check our current inventory
  73. inventory = get_inventory(INVENTORY_ALL);
  74. // Prepare to receive drops
  75. llAllowInventoryDrop(TRUE);
  76. }
  77. state_exit()
  78. {
  79. llAllowInventoryDrop(FALSE);
  80. }
  81. changed(integer change)
  82. {
  83. // Has out inventory changed?
  84. if ((change & CHANGED_INVENTORY) || (change & CHANGED_ALLOWED_DROP)) {
  85. // Stop receiving inventory drops
  86. llAllowInventoryDrop(FALSE);
  87. // Check our new inventory, and find what's changed
  88. list new_inventory = get_inventory(INVENTORY_ALL);
  89. string submit_obj = ListDiff(new_inventory, inventory);
  90. new_inventory = [];
  91. inventory = [];
  92. // Notify the other script(s)
  93. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_PRIMDROP_INVENTORY, PRIMDROP_FINISHED_DROP + "|" + submit_obj, NULL_KEY);
  94. state default;
  95. return;
  96. }
  97. }
  98. link_message(integer sender_num, integer num, string sval, key kval)
  99. {
  100. // Check the channel
  101. if (num == SLOODLE_CHANNEL_PRIMDROP_INVENTORY) {
  102. if (sval == PRIMDROP_CANCEL_DROP) {
  103. // Stop waiting for a drop
  104. llAllowInventoryDrop(FALSE);
  105. state default;
  106. return;
  107. }
  108. }
  109. }
  110. on_rez(integer par)
  111. {
  112. llResetScript();
  113. }
  114. }
  115. // Please leave the following line intact to show where the script lives in Git:
  116. // SLOODLE LSL Script Git Location: mod/primdrop-1.0/objects/default/assets/sloodle_primdrop_inventory.lslp