Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Vendor Multiitem_Multiauthor_vendor_MAIN_B  

Multiitem_Multiauthor_vendor_MAIN_B

Multi-item, Multi-author vendor -MAIN- By Apotheus Silverman.lsl

Category: Vendor
By : Apotheus Silverman
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Multiitem_Multiauthor_vendor_MAIN_B
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Multiitem_Multiauthor_vendor_MAIN_B_1.lsl
1
2 //========== FOREWORD By Apotheus Silverman =========================
3 //
4 //the code I have here is for a vendor that rezzes display models. When someone purchases something the payment can be automatically divided between mulitiple people if desired.
5 //All the information about the items being sold and who gets paid reside in a note card.
6 //
7 //
8 //I have listed a multi-author vendor kit on SLExchange.com that anyone can use to get this vendor system up and running within a few minutes. Most people who have problems getting the scripts working find it to be of incredible value.
9 //
10 //The kit is fully open-source, just like the scripts themselves. It includes a working vendor, tutorial notecard and tools to help you along the way.
11 //
12 //You will find it HERE: http://www.slexchange.com/modules.php?name=Marketplace&file=item&ItemID=4081
13 //===================================================================
14
15
16
17
18
19 // HOW TO USE By Ulrika Zugzwang
20 //
21 // * Create a vendor prim and put the vendor script in.
22 // * Create a previous-button prim and put the previous-button (back-button) script in.
23 // * Create a next-button prim and put the next-button script in.
24 // * Link all three prims together making the vendor prim the parent prim.
25 // * Make a model by rezing an object you want to sell, copy it, shrink it, and remove all contents.
26 // * Place the display script inside this model.
27 // * Rename the model.
28 // * Place the model and the original object for sale into the vendor.
29 // * Edit the "Item Data" notecard to include the following data: object name, model name, price, agent keys
30 ////////////////////////////////////////////////////////////////////////////////////
31 //Sample "Item Data" notecard:
32 ////////////////////////////////////////////////////////////////////////////////////
33 //Abbotts Float Plane v1.0.1, Float Plane Display Model - red stripe, 500,
34 //d9bcb9e0-bfa2-4b8b-a8fc-9d996935ef51|0d994ae7-2d6a-4cd3-bdcf-81c82c35928b
35 //Abbotts Float Plane v1.0.1 black feathers, Float Plane Display Model - black feathers, 500,
36 //d9bcb9e0-bfa2-4b8b-a8fc-9d996935ef51|0d994ae7-2d6a-4cd3-bdcf-81c82c35928b
37 //Abbotts Float Plane v1.0.1 red-yellow feathers, Float Plane Display Model - red feathers, 500,
38 //d9bcb9e0-bfa2-4b8b-a8fc-9d996935ef51|0d994ae7-2d6a-4cd3-bdcf-81c82c35928b
39 //Abbotts Float Plane v1.0.1 stars stripes, Float Plane Display Model - stars stripes, 500,
40 //d9bcb9e0-bfa2-4b8b-a8fc-9d996935ef51|0d994ae7-2d6a-4cd3-bdcf-81c82c35928b
41 /////////////////////////////////////////////////////////////////////////////////////
42
43
44
45
46 // This is the name of the notecard to read items from
47 string itemDataNotecard = "Item Data";
48
49 // Type of thingy this vendor sells (inventory constant)
50 integer inventoryType = INVENTORY_OBJECT;
51
52 // Keeps track of the currently-displayed item (1-indexed)
53 integer currentItem = 0;
54
55 // Floating text color
56 vector textColor = <1,1,1>;
57
58 // Model rez position relative to parent object
59 vector rezPosition = <-0.1,0,-0.1>;
60
61 // Inter-object commands
62 string commandDerez = "derez";
63
64 // How many seconds between automatic item changes
65 float changeTimer = 300.0;
66
67
68
69 // This is the channel the main vendor talks to rezzed models on
70 integer commChannel;
71
72 // These lists are synchronized to simulate a structure for each item's data
73 list items = [];
74 list models = [];
75 list prices = [];
76 list authors = [];
77
78 // Required to read the notecard properly
79 integer notecardLine;
80 key currentDataRequest;
81
82
83 // Reads the data from the notecard. Each line in the notecard should be
84 // formatted as follows:
85 // Item Name, Model Name, Price, Authors
86 // string (no commas), string (no commas), integer, pipe-delimited list of keys
87 // Example:
88 // Abbotts Float Plane v1.0.1, Abbotts Float Plane Model, 500, key|key
89 InitializationStep1() {
90 llSay(0, "Reading item data...");
91 notecardLine = 0;
92 currentDataRequest = llGetNotecardLine(itemDataNotecard, notecardLine);
93 }
94
95 // Requests debit permission
96 InitializationStep2() {
97 // Request debit permission
99 }
100
101 // Change currently-displayed item
102 SetCurrentItem(integer item) {
103 // determine which item to display
104 integer itemCount = llGetListLength(items) - 1;
105 currentItem = item;
106 if(currentItem == -1) {
107 currentItem = itemCount;
108 } else if(currentItem > itemCount) {
109 currentItem = 0;
110 }
111
112 // derez current model
113 llWhisper(commChannel, commandDerez);
114
115 // Build and set hover text
116 string hoverText = "Item " + (string)(currentItem + 1) + " of " + (string)(itemCount + 1) + "\n" + llList2String(items, currentItem) + "\n$" + (string)llList2String(prices, currentItem);
117 llSetText(hoverText, textColor, 1.0);
118
119 // Say what item is now being displayed
120 llSay(0, "Now Showing: " + llList2String(items, currentItem));
121
122 // rez the new model
123 llRezObject(llList2String(models, currentItem), llGetPos() + rezPosition, ZERO_VECTOR, ZERO_ROTATION, commChannel);
124 }
125
126 default {
127 state_entry() {
128 llSay(0, "Starting up...");
129
130 // Initialize commChannel
131 commChannel = (integer)llFrand(2000000000.0);
132
133 // Clear text
134 llSetText("", textColor, 1.0);
135
136 // Read notecard, populate lists
137 InitializationStep1();
138 }
139
141 if(perm & PERMISSION_DEBIT) {
142 state vend;
143 } else {
144 llSay(0, "You must grant debit permission for me to work properly.");
145 }
146 }
147
148 dataserver(key query, string data) {
149 if(query == currentDataRequest) {
150 currentDataRequest = ""; // Prevent a bug that occurs with dataserver events.
151 if(data != EOF) {
152 // Read the current item
153 list currentList = llCSV2List(data);
154 string myItemName = llList2String(currentList, 0);
155 string myModelName = llList2String(currentList, 1);
156 integer myPrice = llList2Integer(currentList, 2);
157 string myAuthorsAsString = llList2String(currentList, 3);
158
159 items += [myItemName];
160 models += [myModelName];
161 prices += [myPrice];
162 authors += [myAuthorsAsString];
163
164 notecardLine++;
165 // Get the next line
166 currentDataRequest = llGetNotecardLine(itemDataNotecard, notecardLine);
167 } else {
168 // Signal that we are done getting items
169 InitializationStep2();
170 }
171 }
172 }
173 }
174
175
176
177
178 state vend {
179 state_entry() {
180 //llSay(0, "items = " + llDumpList2String(items, ","));
181 //llSay(0, "models = " + llDumpList2String(models, ","));
182 //llSay(0, "prices = " + llDumpList2String(prices, ","));
183 //llSay(0, "authors = " + llDumpList2String(authors, ","));
184
185 // Rez initial model
186 SetCurrentItem(currentItem);
187
188 // Start the timer for item autorotation
189 llSetTimerEvent(changeTimer);
190
191 llSay(0, "Multiauthor Multivendor online.");
192 }
193
194 timer() {
195 // Choose a random item to display. Make sure it's not the current item.
196 integer newItem = currentItem;
197 if(llGetListLength(items) > 1) {
198 while(newItem == currentItem) {
199 newItem = (integer)(llFrand(llGetListLength(items)) + 1.0);
200 }
201 SetCurrentItem(newItem);
202 }
203 }
204
205 touch(integer total) {
206 llSay(0, "I sell things! Use the left or right arrows to cycle through the items I am selling, then right-click and \"Pay\" me the displayed amount to purchase an item.");
207 }
208
209 // Someone has given me money
210 money(key agentkey, integer amount) {
211 string name = llKey2Name(agentkey);
212 integer currentPrice = llList2Integer(prices, currentItem);
213 integer sale;
214 integer i;
215
216 if(amount < currentPrice) {
217 // Not enough money was given. Cancel sale.
218 llSay(0, name + " you Paid $" + (string)amount + " - thats not enough money for the current item! Refunding $" + (string)amount + "...");
219 llGiveMoney(agentkey, amount);
220 sale = FALSE;
221 }
222 else if(amount > currentPrice) {
223 // Too much money was given. Refund the differnce.
224 integer change = amount - currentPrice;
225 llSay(0, name + " you Paid $" + (string)amount + " - your change is $" + (string)change + ".");
226 llGiveMoney(agentkey, change);
227 sale = TRUE;
228 } else {
229 // The proper amount was given.
230 sale = TRUE;
231 }
232
233 if(sale) {
234 // Make sure I have the item in inventory before trying to give it.
235 integer found = FALSE;
236 //llSay(0, "searching for " + llList2String(items, currentItem));
237 for (i = 0; i < llGetInventoryNumber(inventoryType); i++) {
238 if(llGetInventoryName(inventoryType, i) == llList2String(items, currentItem)) {
239 found = TRUE;
240 }
241 }
242
243 if(!found) {
244 // Display error and refund money
245 llSay(0, "Erm, I am sorry " + name + ", but it seems that I do not have that item to give to you, so I am refunding the purchase price. Please contact my owner about this issue.");
246 llGiveMoney(agentkey, currentPrice);
247 } else {
248 // Complete the sale
249 llSay(0, "Thank you for your purchase, " + name + "!");
250 llGiveInventory(agentkey, llList2String(items, currentItem));
251
252 llWhisper(0, "Please wait while I perform accounting activities...");
253
254 // Distribute money to the object authors
255 list myAuthors = llParseString2List(llList2String(authors, currentItem), ["|"], []);
256
257 if(llGetListLength(myAuthors) > 0) {
258 integer shareAmount = (integer)llList2Integer(prices, currentItem) / llGetListLength(myAuthors);
259 // Eliminate my owner from the authors list
260 for (i = 0; i < llGetListLength(myAuthors); i++) {
261 llInstantMessage(llList2Key(myAuthors, i), name + " purchased " + llList2String(items, currentItem) + ". Your share is L$" + (string)shareAmount + ".");
262 if(llList2Key(myAuthors, i) == llGetOwner()) {
263 myAuthors = llDeleteSubList(myAuthors, i, i);
264 }
265 }
266 // Pay any remaining authors accordingly
267 if(shareAmount > 0 && llGetListLength(myAuthors) > 0) {
268 for (i = 0; i < llGetListLength(myAuthors); i++) {
269 llGiveMoney(llList2Key(myAuthors, i), shareAmount);
270 }
271 }
272 }
273 llWhisper(0, "Accounting completed. Thanks again, " + name + "!");
274 }
275 }
276 }
277
278 link_message(integer sender, integer num, string message, key id) {
279 if(message == "next") {
280 llSetTimerEvent(changeTimer);
281 SetCurrentItem(currentItem + 1);
282 } else if(message == "prev") {
283 llSetTimerEvent(changeTimer);
284 SetCurrentItem(currentItem - 1);
285 }
286 }
287
288 on_rez(integer startParam) {
290 }
291 } // END //

Back to the Best Free Tools in Second Life and OpenSim.