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

[Table of Contents]

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
Sign Hypergrid_Events_Sign  

Hypergrid_Events_Sign

DESCRIPTION: []::Hypergrid_Events_Sign pulls events from a datbase for display in world

Category: Sign
By : Anonymous
Created: 2017-11-19 Edited: 2017-11-19
Worlds: OpenSim

the Zip file

Download all files for Hypergrid_Events_Sign
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Script.lsl
1 //
2 // HYPEvents in-world teleporter board script
3 //
4 // Author: Tom Frost <tomfrost@linkwater.org>
5 //
6 // GPLv3
7 //
8
9
10 // configuration:
11
12 float refreshTime = 1800;
13
14 // internal, do not touch:
15 integer lineHeight = 30;
16 integer startY = 90;
17
18 integer texWidth = 512;
19 integer texHeight = 512;
20 key httpRequest;
21
22 list events;
23
24 integer channel;
25
26 integer listenHandle;
27 integer listening = 0;
28
29 list avatarDestinations = [];
30
31 //
32 // manipulate global avatarDestinations list
33 //
34 // insert or overwrite destination for agent with dest
35 //
36 tfSetAvatarDest(key agent, string dest)
37 {
38 list newList = [];
39 integer idx;
40 integer len = llGetListLength(avatarDestinations)/2;
41 integer set = FALSE;
42
43 for(idx=0;idx<len;idx++) {
44 key avatar = llList2Key(avatarDestinations, (idx*2));
45 if(avatar==agent) {
46 newList += [ agent, dest ];
47 set = TRUE;
48 } else {
49 newList += [ avatar, llList2String(avatarDestinations, (idx*2)+1) ];
50 }
51 }
52 if(!set) {
53 newList += [ agent, dest ];
54 }
55
56 avatarDestinations = newList;
57 }
58
59 //
60 // retrieve avatar dest from global avatarDestination list
61 //
62 // returns hgurl if destination set, NULL_KEY otherwise
63 //
64 string tfGetAvatarDest(key agent)
65 {
66 integer idx;
67 integer len = llGetListLength(avatarDestinations)/2;
68
69 for(idx=0;idx<len;idx++) {
70 if(llList2Key(avatarDestinations, (idx*2))==agent) {
71 return llList2String(avatarDestinations, (idx*2)+1);
72 }
73 }
74 return NULL_KEY;
75 }
76
77 doRequest()
78 {
79 httpRequest = llHTTPRequest("http://hypevents.net/events.lsl", [], "");
80 }
81
82 string tfTrimText(string in, string fontname, integer fontsize,integer width)
83 {
84 integer i;
85 integer trimmed = FALSE;
86
87 for(;llStringLength(in)>0;in=llGetSubString(in,0,-2)) {
88
89 vector extents = osGetDrawStringSize("vector",in,fontname,fontsize);
90
91 if(extents.x<=width) {
92 if(trimmed) {
93 return in + "..";
94 } else {
95 return in;
96 }
97 }
98
99 trimmed = TRUE;
100 }
101
102 return "";
103 }
104
105 refreshTexture()
106 {
107 string commandList = "";
108
109 integer fontSize=50;
110
111 commandList = osMovePen(commandList, 20, 5);
112 commandList = osDrawImage(commandList, 400, 70, "http://linkwater.org/dyntex/hypevents_logo.png");
113
114 commandList = osSetPenSize(commandList, 1);
115 commandList = osDrawLine(commandList, 0, 80, 512, 80);
116
117 integer numEvents = llGetListLength(events)/3;
118
119 integer i;
120
121 integer y = startY;
122
123 commandList = osSetFontName(commandList, "Arial");
124 commandList = osSetFontSize(commandList, 20);
125
126 for(i=0;i<numEvents;i++) {
127 integer base = i*3;
128
129 commandList = osMovePen(commandList, 10, y);
130
131 string text = llList2String(events, base+1) + " " + llList2String(events, base);
132 text = tfTrimText(text, "Arial", 20, texWidth-40);
133 commandList = osDrawText(commandList, text);
134
135 y += lineHeight;
136 }
137
138 osSetDynamicTextureData("", "vector", commandList, "width:"+(string)texWidth+",height:"+(string)texHeight, 0);
139 }
140
141 tfLoadURL(key avatar)
142 {
143 llLoadURL(avatar, "Visit the HYPEvents web-site for more detailed event information and technical information.", "http://hypevents.net/");
144 }
145
146 tfGoToEvent(key avatar, integer eventIndex)
147 {
148 integer numEvents = llGetListLength(events)/3;
149
150 integer base = eventIndex * 3;
151
152 if(eventIndex<numEvents) {
153 string text=llList2String(events, base+0);
154
155 text += "\n\n";
156
157 text += "The hypergrid url for this event is:\n\n"+llList2String(events, base+2)+"\n\n";
158
159 text += "Is this hgurl a hypergrid url for you or a local url?\n\n";
160
161 tfSetAvatarDest(avatar, llList2String(events, base+2));
162
163 llDialog(avatar, text, ["Hypergrid","Local grid", "Cancel"], channel);
164 if(listening==0) {
165 listenHandle = llListen(channel, "", NULL_KEY, "");
166 listening = (integer)llGetTime();
167 }
168 } else {
169 }
170 }
171
172 default
173 {
175 {
176 channel = -25673 - (integer)llFrand(1000000);
177 listening = 0;
178 avatarDestinations = [];
179 llSetTimerEvent(refreshTime);
180 doRequest();
181 }
182
183 http_response(key requestID, integer status, list metadata, string body)
184 {
185 if(status==200) {
186 events = llParseString2List(body, ["\n"], []);
187 refreshTexture();
188 } else {
189 llOwnerSay("Unable to fetch event.lsl, status: "+(string)status);
190 }
191 }
192
193 listen(integer chan, string name, key agent, string msg)
194 {
195 if(chan==channel) {
196 if(msg!="Cancel") {
197 string dest = tfGetAvatarDest(agent);
198 if(dest!=NULL_KEY) {
199 string dsturl = dest;
200 if(msg=="Local grid") {
201 list hgurl = llParseString2List(dest, [":"], []);
202 dsturl = llList2String(hgurl, 2);
203 }
204 osTeleportAgent(agent, dsturl, <128.0,128.0,23.0>, <1.0,1.0,0.0> );
205 }
206 }
207 }
208 }
209
211 {
212 integer i;
213 for(i=0;i<num;i++) {
214 vector touchPos = llDetectedTouchUV(i);
215 integer touchX = (integer)(touchPos.x * texWidth);
216 integer touchY = texHeight - (integer)(touchPos.y * texHeight);
217 key avatar = llDetectedKey(i);
218
219 if(touchY < 80) {
220 tfLoadURL(avatar);
221 } else if(touchY>=startY) {
222 integer touchIndex;
223
224 touchIndex = (integer)((touchY - startY) / lineHeight);
225
226 tfGoToEvent(avatar, touchIndex);
227 }
228 }
229 }
230
231 timer()
232 {
233 // timeout listener
234 if(listening!=0) {
235 if( (listening + 300) < (integer)llGetTime() ) {
236 llListenRemove(listenHandle);
237 avatarDestinations=[];
238 listening = 0;
239 }
240 }
241 // refresh texture
242 doRequest();
243 }
244 }

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