Join us in Phaze Demesnes

LSL Script Library Home   Add a script Show All
Category: Contributor: Description
Suggestion Box dakar Muliaina Suggestion Box
drop a notecard in the box and it will store it until you log in to check the box and it will deliver the notecards to you
To use this script, simply copy/paste the contents below into a New Script in the game. Then place the script into a ‘prim’ (in the shape of a mailbox or suggestion box?). That’s all there is to it.

Download this script - Please use this link to get this script. If you see all the code on one long line, please use Wordpad or another editor, such as LSLEdit.exe. The .LSL file you will download is an ordinary text file.

1 // --------------------------------------//
2 // This script transform a prim to a Mail Box.
3 // Folks can drop notecard to the box.
4 // Read/unread information is displayed as hovering text.
5 // You can copy/modify this script, it's totally free.
6 // --------------------------------------//
7 // Modified by dakar Muliaina, converted to The king's English
8 // and a few other enhancements.
9 //-------------------------------------------//
10
11 list lMail = [];
12 // column 1 = notecard name, column 2 = read by user
13 integer MAIL_UNREADED = 0;
14 integer MAIL_READED = 1;
15 integer DIALOG_CHANNEL = 49383;
16 list DIALOG_CHOICE =
17 ["Unread",
18 "Read",
19 "Delete"];
20 integer nLastCardCount = 0;
21 integer nLastItemCount = 0;
22
23 TxtRefresh()
24 {
25 // show the unreadable notecard
26 integer nTotalCard = 0;
27 integer nNotReaded = 0;
28 integer nCount = 0;
29 for (nCount = 0; nCount < llGetListLength(lMail); nCount += 2)
30 {
31 if (llList2Integer(lMail, nCount + 1) == MAIL_UNREADED)
32 nNotReaded += 1;
33 nTotalCard += 1;
34 }
35
36 // total string
37 string cPost = (string)nTotalCard + " card";
38 if (nTotalCard > 1) cPost += "s";
39 cPost += " posted";
40
41 // unreaded string
42 string cUnreaded = (string)nNotReaded + " unread";
43 llSetText("Suggestion Box!\n" + cPost + "\n" + cUnreaded, <.95, .75, 0>, 1);
44 }
45
46 default
47 {
49 {
50 // Allowing dropping of object
52 llListen(DIALOG_CHANNEL, "", NULL_KEY, "");
53 nLastCardCount = llGetInventoryNumber(INVENTORY_ALL);
55
56 // Auto complete list
58 integer n_CurObj = 0;
59 string c_Name = "NotEmpty";
60 while (c_Name != "")
61 {
62 c_Name = llGetInventoryName(INVENTORY_NOTECARD, n_CurObj);
63 n_CurObj += 1;
64 if (c_Name != "")
65 {
66 lMail += [c_Name];
67 lMail += MAIL_UNREADED;
68 }
69 }
70 TxtRefresh();
71 }
72
73 touch_start(integer total_number)
74 {
75 llSay(0, "Drop a notecard to be sent to MY OWNER.");
76 //---- Change MY OWNER above to suit your likes and needs. //
77 // if owner
78 key id = llDetectedKey(0);
79 if (id == llGetOwner())
80 {
81 // Show a dialog
82 llDialog(id, "What do you want to do ?", DIALOG_CHOICE,
83 DIALOG_CHANNEL);
84 }
85 }
86
87 listen(integer channel, string name, key id, string message)
88 {
89 if (llGetOwner() == id && llListFindList(DIALOG_CHOICE,
90 [message]) != -1)
91 {
93 string cName;
94 list lRemove;
95 integer nStatus;
96 for (i = 0; i < llGetListLength(lMail); i += 2)
97 {
98 cName = llList2String(lMail, i);
99 nStatus = llList2Integer(lMail, i + 1);
100 if (message == llList2String(DIALOG_CHOICE, 0)
101 && nStatus == MAIL_UNREADED)
102 {
103 // open un-readed
104 llGiveInventory(id, cName);
105 // mark for readed
106 lMail = llListReplaceList(lMail, [MAIL_READED],
107 i + 1, i + 1);
108 }
109 if (message == llList2String(DIALOG_CHOICE, 1)
110 && nStatus == MAIL_READED)
111 {
112 // open readed
113 llGiveInventory(id, cName);
114 }
115 if (message == llList2String(DIALOG_CHOICE, 2)
116 && nStatus == MAIL_READED)
117 {
118 // delete readed
119 llSay(0, cName);
120 llRemoveInventory(cName);
121 lRemove += i;
122 }
123 }
124 // remove from the list
125 if (llGetListLength(lRemove) > 0)
126 {
128 for (k = 0; k < llGetListLength(lRemove); k++)
129 {
130 i = llList2Integer(lRemove, k);
131 lMail = llDeleteSubList(lMail, i, i+1);
132 }
133 }
134 TxtRefresh();
135 }
136 }
137
138 changed(integer change)
139 {
140 // dont accept other than a notecard
142 if (nItemCount < 2)
143 {
144 // clear the list
145 lMail = [];
146 }
147
148 if (nItemCount != nLastItemCount)
149 {
150 // delete other item type than notecard
151 string cName = "NotEmpty";
152 integer nCurObj = 0;
154 list lRemove = [];
155 while (cName != "")
156 {
157 cName = llGetInventoryName(INVENTORY_ALL, nCurObj);
158 nCurObj += 1;
159 nObjType = llGetInventoryType(cName);
160 if (nObjType != INVENTORY_NOTECARD)
161 {
162 // add for deletion, its not a notecard
163 lRemove += cName;
164 }
165 }
166
167 // delete other object than notecard
168 integer nD = 0;
169 for (nD = 0; nD < llGetListLength(lRemove); nD += 1)
170 {
171 // dont remove this script !
172 cName = llList2String(lRemove, nD);
173 if (cName != llGetScriptName() && cName != "")
174 {
175 llSay(0, "Sorry but " + cName + " is not a notecard.");
176 llRemoveInventory(cName);
177 }
178 }
179
180 // search for a new notecard
181 integer n_CurObj = 0;
182 string c_Name = "NotEmpty";
183 while (c_Name != "")
184 {
185 c_Name = llGetInventoryName(INVENTORY_NOTECARD, n_CurObj);
186 llSay(0, c_Name);
187 n_CurObj += 1;
188 // search for this card
189 if (llListFindList(lMail, [c_Name]) == -1 && c_Name != "")
190 {
191 // ok its a new card
192 lMail += [c_Name];
193 lMail += MAIL_UNREADED;
194 llSay(0, c_Name + " added to the mailbox.");
195 }
196 }
197 }
198 nLastItemCount = llGetInventoryNumber(INVENTORY_ALL);
200 // refresh the text
201 TxtRefresh();
202 }
203 }