784fdc3f05ee100d9171671589371278405f9a4b
[feisty_meow.git] / huffware / huffotronic_scripts / ama_omega_et_al_vendor_owner-only_v0.5.txt
1 //Multi Vendor by Adelle Fitzgerald
2 //Based on the Ama Omega Vendor Script v0.3.1 06/2004
3
4  
5 //Licenced under Creative Commons Attribution-Share Alike 3.0 Unported - http://creativecommons.org/licenses/by-sa/3.0/
6
7
8 //You are free:
9
10 //    * to Share — to copy, distribute and transmit the work
11 //    * to Remix — to adapt the work
12
13 //Under the following conditions:
14
15 //    * Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
16
17 //    * Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license.
18
19 //With the understanding that:
20
21 //    * Waiver — Any of the above conditions can be waived if you get permission from the copyright holder.
22 //    * Public Domain — Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license.
23 //    * Other Rights — In no way are any of the following rights affected by the license:
24 //          o Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations;
25 //          o The author's moral rights;
26 //          o Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.
27 //    * Notice — For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.
28
29 //Disclaimer
30
31 //The Commons Deed is not a license. It is simply a handy reference for understanding the Legal Code (the full license) — it is a human-readable expression of some of its key terms. Think of it as the user-friendly interface to the Legal Code beneath. This Deed itself has no legal value, and its contents do not appear in the actual license.
32
33 //Creative Commons is not a law firm and does not provide legal services. Distributing of, displaying of, or linking to this Commons Deed does not create an attorney-client relationship.
34
35
36 integer gChannel;
37 integer handle;
38 string name = "Vendor ";
39 integer display;
40 list pics;
41 list desc;
42 list items;
43 list sold;
44 list info;
45 key gUser;
46 key k;
47 list temp;
48 integer line;
49 integer l;
50 string s;
51 string hText;
52 integer totItems;
53 string button;
54
55
56 incSold(integer i)
57 {
58     sold = llListInsertList(llDeleteSubList(sold,i,i),[(integer)(llList2Integer(sold,i) + 1)],i);
59 }
60
61 doMenu()
62 {
63     //llSay(0,(string)gChannel + " : " + (string)gUser); //say gChannel
64     llSetTimerEvent(30);
65     llDialog(gUser, "Settings:", ["Cancel", "Report", "Get Item", "Reset"], gChannel);
66 }
67
68 doCancel()
69 {
70     llListenControl(handle, FALSE);
71     llSetTimerEvent(0);
72 }
73
74 next()
75 {
76     display += 1;
77     if (display >= llGetListLength(items)) display = 0;
78     llSetText("Item: " + (string)(display + 1) + " of " + (string)totItems + "\n" + llList2String(items,display) + "\n" + llList2String(desc,display),<1,1,1>,1);
79     llMessageLinked(LINK_SET,1,"PIC",llGetInventoryKey((key)llList2String(pics,display)));
80     llMessageLinked(LINK_SET,1,"LOADNEXT",llGetInventoryKey((key)llList2String(pics,display + 1)));
81     llMessageLinked(LINK_SET,1,"LOADPREV",llGetInventoryKey((key)llList2String(pics,display - 1))); 
82 }
83
84 prev()
85 {
86     display -= 1;
87     if (display < 0) display = llGetListLength(items) - 1;
88     llSetText("Item: " + (string)(display + 1) + " of " + (string)totItems + "\n" + llList2String(items,display) + "\n" + llList2String(desc,display),<1,1,1>,1);
89     llMessageLinked(LINK_SET,1,"PIC",llGetInventoryKey((key)llList2String(pics,display)));
90     llMessageLinked(LINK_SET,1,"LOADNEXT",llGetInventoryKey((key)llList2String(pics,display + 1)));
91     llMessageLinked(LINK_SET,1,"LOADPREV",llGetInventoryKey((key)llList2String(pics,display - 1)));
92 }
93
94 init()
95 {
96     display = 0;
97     if (display < 0) display = llGetListLength(items) - 1;
98     llSetText("Item: " + (string)(display + 1) + " of " + (string)totItems + "\n" + llList2String(items,display) + "\n" + llList2String(desc,display),<1,1,1>,1);
99     llMessageLinked(LINK_SET,1,"PIC",llGetInventoryKey((key)llList2String(pics,display)));
100     llMessageLinked(LINK_SET,1,"LOADNEXT",llGetInventoryKey((key)llList2String(pics,display + 1)));
101     llMessageLinked(LINK_SET,1,"LOADPREV",llGetInventoryKey((key)llList2String(pics,display - 1)));
102 }
103
104
105 default {
106     state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
107     on_rez(integer parm) { state rerun; }
108 }
109 state rerun { state_entry() { state default; } }
110
111 state real_default {
112     state_entry()
113     {
114         state
115         readCard;
116     }
117 }
118     
119 state running
120 {    
121     state_entry()
122     {
123         gChannel = (integer)llFrand(2147423647) + 10000;
124         handle = llListen(gChannel, "", llGetOwner(), "");
125         llListenControl(handle, FALSE);
126         init();
127     }
128     
129     on_rez(integer param)
130     {
131         llResetScript();
132     }
133     
134     listen(integer chan, string name, key id, string mes)
135     {
136         if (id != llGetOwner()) {
137             llWhisper(0, "Sorry, this vendor is restricted for use by its owner.");
138             return;
139         }
140         if (mes == "Reset")
141         {
142             doCancel();
143             state readCard;
144         }
145         else if (mes == "Report")
146         {
147             integer i;
148             for(i=0;i<llGetListLength(sold);i++)
149             {
150                 if (llList2Integer(sold,i) != 0) llWhisper(0,"* Sold " + (string)llList2Integer(sold,i) + " " + llList2String(items,i));
151             }
152             doCancel();
153         }
154         else if (mes == "Get Item")
155         {
156             llGiveInventory(gUser, llList2String(items,display));
157             llWhisper(0,"Thank you, please enjoy your " + llList2String(items,display));
158             doCancel();
159         }
160         else if (mes == "Cancel")
161         {
162             doCancel();
163         }
164     }
165     
166     touch_start(integer num_detected)
167     {
168         button = llGetLinkName(llDetectedLinkNumber(0));
169         gUser = llDetectedKey(0);
170         
171         if (button == "Next")
172         {
173             next();
174         }
175         else if (button == "Prev")
176         {
177             prev();
178         }
179         else if (button == "Info")
180         {
181             llGiveInventory(gUser, llList2String(info,display));
182         }
183         else
184         {
185             if (gUser != llGetOwner()) {
186                 llWhisper(0, "Sorry, this vendor is restricted for use by its owner.");
187                 return;
188             }
189             if (gUser == llGetOwner())
190             {
191                 llListenControl(handle, TRUE);
192                 doMenu();
193             }
194             else
195             {
196                 incSold(display);
197                 llGiveInventory(gUser, llList2String(items,display));
198                 llWhisper(0,"Thank you, please enjoy your " + llList2String(items,display));
199             }
200         }
201     }                   
202     timer()
203     {
204         doCancel();
205         llInstantMessage(gUser,"Menu timed out");
206     }
207 }
208
209 state readCard
210 {
211     state_entry()
212     {
213         llSay(0,"Initializing...");
214         line = 1;
215         k = llGetNotecardLine("VendorConfig",line++);
216         items = [];
217         pics = [];
218         desc = [];
219     }
220     
221     dataserver(key q, string data)
222     {
223         if (q == k)
224         {
225             if (data == "")
226             {
227                 k = llGetNotecardLine("VendorConfig",line++);
228                 return;
229             }
230             temp = llCSV2List(data);
231             if (llParseString2List(data,[" "],[]) == []);
232             else if (data == EOF)
233             {
234                 display = 0;
235                 totItems = llGetListLength(items);
236                 llMessageLinked(LINK_SET,1,"PIC",llGetInventoryKey(llList2String(pics,0)));
237                 llWhisper(0," * Vendor setup complete : " + (string)totItems + " items loaded.");
238                 state running;
239             }
240             else if (llGetListLength(temp) != 4)
241             {
242                 llWhisper(0,"Error, improperly formatted line #" + (string)(line - 1));
243                 state running;
244             }
245             else
246             {
247                 items += llList2String(temp,0);
248                 pics += llList2String(temp,1);
249                 desc += llList2String(temp,2);
250                 info += llList2String(temp,3);
251                 sold += [(integer)0];
252                 if ( llGetInventoryKey((key)llList2String(temp,0)) == NULL_KEY || llGetInventoryKey((key)llList2String(temp,1)) == NULL_KEY)
253                 {
254                     llWhisper(0,"Error, missing inventory or picture from line : " + data);
255                     state running;
256                 }
257                 k = llGetNotecardLine("VendorConfig",line++);
258             }
259         }
260     }
261 }