-
Notifications
You must be signed in to change notification settings - Fork 7
/
sl-rp-player-hud.lsl
481 lines (468 loc) · 18.5 KB
/
sl-rp-player-hud.lsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
#include "config.lsl"
string allowed_region = ALLOWED_REGION;
list creators = [CREATORS];
string hash_seed = HASH_SEED;
integer meter_chan = METER_CHAN;
key http_request_id;
list creator_keys;
string character;
string title;
integer currency_banked = -1;
integer experience;
integer level;
integer xp_needed;
integer health;
integer attack;
integer defense;
integer boost_attack; //Not implemented
integer boost_defense; //Not implemented
integer attackable; //Not fully implemented
vector hover_color;
integer is_ooc;
integer is_afk;
integer dialog_listener;
string dialog_state;
integer dialog_chan;
integer dialog_page = 1;
string dialog_prompt;
key owner;
integer scanning_for_payees;
list nearby_players;
integer pay_person_idx;
integer scanning_for_victims;
integer attack_person_idx;
key requesting_attacker;
string attack_type;
integer update_chan = HUD_UPDATE_CHAN;
integer update_listener;
integer is_current_version;
string update_msg;
setTitle() {
string hover_text = "";
float alpha = 1;
vector col = hover_color;
if (is_current_version) {
hover_text = "\n" + CURRENCY_PREFIX + (string)currency_banked + CURRENCY_SUFFIX
+ "\nLevel: " + (string)level + " XP: " + (string)experience + "/" + (string)xp_needed
+ "\nHealth: " + (string)health + "/10"
+ "\nAttack: " + (string)attack
+ "\nDefense: " + (string)defense;
if (is_ooc) {
hover_text += "\n (( OOC ))";
}
} else {
hover_text = "NEW VERSION\n \nCheck Inventory\n \n" + update_msg;
col = <1, 0, 0>;
alpha = 1;
}
llSetText(hover_text, col, alpha);
}
showDialogPage(integer page) {
string player_list = "";
dialog_page = page;
integer num_pages = (integer)(llGetListLength(nearby_players)/20) + 1;
if (dialog_page > num_pages) {
dialog_page = 1;
} else if (dialog_page < 1) {
dialog_page = num_pages;
}
dialog_listener = llListen(dialog_chan, "", owner, "");
list dialog_buttons = [];
if (dialog_page > 1) {
dialog_buttons += ["⇐"];
} else {
dialog_buttons += [" "];
}
dialog_buttons += ["CLOSE"];
integer num_buttons_this_page = 9;
if (dialog_page < num_pages) {
dialog_buttons += ["⇒"];
} else {
num_buttons_this_page = llGetListLength(nearby_players)/2 - (dialog_page - 1) * 9;
dialog_buttons += [" "];
}
integer i;
for(i=0;i<num_buttons_this_page;i++) {
dialog_buttons += [(string)((dialog_page - 1) * 9 + i + 1)];
player_list += (string)((dialog_page - 1) * 9 + i + 1) + ") " + llList2String(nearby_players, (dialog_page - 1) * 18 + i*2 + 1) + "\n";
}
llSetTimerEvent(60);
llDialog(owner, "\n" + dialog_prompt + player_list, dialog_buttons, dialog_chan);
}
init() {
string params = "action=r&uuid=" + (string)owner + "&hash=" + llSHA1String((string)owner + hash_seed);
http_request_id = llHTTPRequest(API_URL,
[
HTTP_METHOD, "POST",
HTTP_MIMETYPE, "application/x-www-form-urlencoded"
],
params);
}
default {
state_entry() {
integer i;
for (;i<llGetListLength(creators);i++) {
creator_keys += [llList2Key(creators, i)];
}
owner = llGetOwner();
is_ooc = FALSE;
is_afk = FALSE;
if (llGetRegionName() == allowed_region) {
llAllowInventoryDrop(TRUE);
is_current_version = TRUE;
string obj_name = llGetObjectName();
update_listener = llListen(update_chan, "", NULL_KEY, "");
llSetTimerEvent(15);
llRegionSay(update_chan, llGetSubString(obj_name, 14, llStringLength(obj_name) - 1));
dialog_chan = (integer)llFrand(DEBUG_CHANNEL)*-1;
currency_banked = -1;
llSetText("", <1,1,1>, 1);
init();
} else {
llOwnerSay("You are not in " + allowed_region + ". This HUD can only be used in " + allowed_region + ".");
llRequestPermissions(owner, PERMISSION_ATTACH);
}
}
touch_start(integer total_number) {
if (llDetectedKey(0) == owner) {
if (is_current_version) {
if (dialog_listener) {
llListenRemove(dialog_listener);
}
dialog_listener = llListen(dialog_chan, "", owner, "");
string ooc_btn = "OOC On";
if (is_ooc) {
ooc_btn = "OOC Off";
}
string afk_btn = "AFK On";
if (is_afk) {
afk_btn = "AFK Off";
}
llDialog(owner,
"\n" + allowed_region + " HUD Menu\n \n" + CURRENCY_PREFIX + (string)currency_banked + CURRENCY_SUFFIX + "\n \n",
[
"Pay",
"Change",
"CLOSE",
"Attack",
ooc_btn,
afk_btn,
"Speaker"
],
dialog_chan);
} else {
//Re-check versioning (crashes were interfering with checking, invalidating)
llResetScript();
}
}
}
http_response(key request_id, integer status, list metadata, string body) {
if (request_id == http_request_id) {
if (llSubStringIndex(body, "ERR,") == 0) {
if (body == "ERR,Player with UUID Key of " + (string)owner + " not found.") {
dialog_state = "character";
dialog_listener = llListen(dialog_chan, "", owner, "");
llSetTimerEvent(60);
llTextBox(owner, "\nSetup Your Character\n \nWhat is your character's name?", dialog_chan);
} else {
llSay(0, "Error: " + llGetSubString(body, 4, llStringLength(body) - 1));
}
} else if (llSubStringIndex(body, "STAT,") == 0) {
list fields = llCSV2List(llGetSubString(body, 5, llStringLength(body) - 1));
character = llList2String(fields, 0);
title = llList2String(fields, 1);
currency_banked = llList2Integer(fields, 2);
experience = llList2Integer(fields, 3);
level = llList2Integer(fields, 14);
xp_needed = llList2Integer(fields, 15);
health = llList2Integer(fields, 4);
attack = llList2Integer(fields, 5);
defense = llList2Integer(fields, 6);
boost_attack = llList2Integer(fields, 7);
boost_defense = llList2Integer(fields, 8);
attackable = llList2Integer(fields, 9) == 1;
hover_color = <llList2Float(fields, 10), llList2Float(fields, 11), llList2Float(fields, 12)>;
setTitle();
if (llStringLength(llList2String(fields, 13)) > 0) {
llRegionSayTo((key)llList2String(fields, 13), meter_chan, "1");
}
if (dialog_state == "saving_update") {
llRegionSayTo(owner, meter_chan, "REFRESH");
dialog_state = "";
}
llRegionSayTo(owner, meter_chan, "1");
llListen(meter_chan, "", NULL_KEY, "");
if (dialog_state == "pay now") {
llSay(0, "Monies transferred.");
dialog_state = "";
}
} else if (llSubStringIndex(body, "ATTACK,") == 0) {
list fields = llCSV2List(llGetSubString(body, 7, llStringLength(body) - 1));
llRegionSayTo(owner, 0, llList2String(fields, 0));
llRegionSayTo(llList2Key(nearby_players, attack_person_idx), 0, llList2String(fields, 0));
nearby_players = [];
attack_person_idx = -1;
init();
llRegionSayTo(llList2Key(fields, 1), meter_chan, "1");
} else {
llSay(0, "Unexpected response: " + body);
}
}
}
listen(integer channel, string name, key id, string message) {
if (channel == dialog_chan) {
if (message == " " || message == "CLOSE") { return; }
if (message == "⇐") {
showDialogPage(dialog_page - 1);
} else if (message == "⇒") {
showDialogPage(dialog_page + 1);
} else if (message == "OOC On") {
is_ooc = TRUE;
is_afk = FALSE;
llRegionSayTo(owner, meter_chan, "OOC On");
setTitle();
} else if (message == "OOC Off") {
is_ooc = FALSE;
llRegionSayTo(owner, meter_chan, "OOC Off");
setTitle();
} else if (message == "AFK On") {
is_afk = TRUE;
is_ooc = FALSE;
llRegionSayTo(owner, meter_chan, "AFK On");
setTitle();
} else if (message == "AFK Off") {
is_afk = FALSE;
llRegionSayTo(owner, meter_chan, "AFK Off");
setTitle();
} else if (message == "Speaker") {
llRegionSayTo(owner, meter_chan, "Voice Chan17");
} else if (message == "Pay") {
scanning_for_payees = TRUE;
nearby_players = [];
pay_person_idx = -1;
llSay(0, "Searching for players to pay.");
llRegionSay(meter_chan, "Can Pay");
llSetTimerEvent(5);
} else if (message == "Change") {
dialog_state = "character";
dialog_listener = llListen(dialog_chan, "", owner, "");
llSetTimerEvent(60);
llTextBox(owner, "\nSetup Your Character\n \nWhat is your character's name?", dialog_chan);
} else if (message == "Attack") {
scanning_for_victims = TRUE;
nearby_players = [];
attack_person_idx = -1;
llSay(0, "Searching for potential victims.");
llRegionSay(meter_chan, "Can Attack");
llSetTimerEvent(5);
} else {
if (dialog_state == "pay") {
integer idx = (integer)message;
if (idx > 0 && idx <= (llFloor(llGetListLength(nearby_players)/2) + 1)) {
pay_person_idx = (idx - 1)*2;
dialog_state = "pay now";
llSetTimerEvent(60);
llTextBox(owner, "\nPay Player\n \nEnter the amount to pay " + llList2String(nearby_players, pay_person_idx + 1) + ".", dialog_chan);
} else {
llOwnerSay("Please select a number from the list provided. Payment cancelled");
}
} else if (dialog_state == "attack") {
attack_person_idx = ((integer)message - 1)*2;
dialog_state = "attack type";
dialog_listener = llListen(dialog_chan, "", owner, "");
llSetTimerEvent(60);
llDialog(owner, "\nAttack Player\n \nSelect the type of attack.", ["Pick Winner", "Win w/ Stats"], dialog_chan);
} else if (dialog_state == "attack type") {
attack_type = message;
dialog_state = "";
llSetTimerEvent(60);
llSay(0, "Sending your attack request.");
llRegionSayTo(llList2Key(nearby_players, attack_person_idx), meter_chan, "Attack Request," + (string)owner + "," + message);
} else if (dialog_state == "attack confirm") {
if (message == "Accept RP") {
llRegionSayTo(requesting_attacker, meter_chan, "Attack Accept");
} else {
llRegionSayTo(requesting_attacker, meter_chan, "Attack Reject");
}
} else if (dialog_state == "pay now") {
integer amt = (integer)message;
if (amt > 0) {
if (amt <= currency_banked) {
string params = "uuid=" + (string)owner + "&hash=" + llSHA1String((string)owner + hash_seed)
+ "&action=u"
+ "¤cy_banked=-" + (string)amt
+ "&pass=" + llList2String(nearby_players, pay_person_idx);
http_request_id = llHTTPRequest(API_URL,
[
HTTP_METHOD, "POST",
HTTP_MIMETYPE, "application/x-www-form-urlencoded"
],
params);
} else {
llOwnerSay("Payment cancelled. You cannot pay more than you have.");
}
} else {
llOwnerSay("Payment cancelled. No amount entered.");
}
} else if (dialog_state == "character") {
if (llStringLength(message) == 0) {
message = "-";
}
character = message;
dialog_state = "title";
if (dialog_listener) {
llListenRemove(dialog_listener);
}
dialog_listener = llListen(dialog_chan, "", owner, "");
llSetTimerEvent(60);
llTextBox(owner, "\nSetup Your Character\n \nWhat is your character's title (text under the character's name)?", dialog_chan);
} else if (dialog_state == "title") {
title = message;
dialog_state = "hover_color";
if (dialog_listener) {
llListenRemove(dialog_listener);
}
dialog_listener = llListen(dialog_chan, "", owner, "");
llSetTimerEvent(60);
llTextBox(owner, "\nSetup Your Character\n \nWhat color would you like your hover text? (Use hex format. For example, FF9900)", dialog_chan);
} else if (dialog_state == "hover_color") {
if (dialog_listener) {
llListenRemove(dialog_listener);
}
dialog_state = "saving_update";
string params = "uuid=" + (string)owner + "&hash=" + llSHA1String((string)owner + hash_seed);
if (currency_banked < 0) {
params += "&action=c&user=" + llEscapeURL(llGetUsername(owner));
} else {
params += "&action=u";
}
params += "&name=" + llEscapeURL(character)
+ "&title=" + llEscapeURL(title)
+ "&hover_color=" + llEscapeURL(message);
http_request_id = llHTTPRequest(API_URL,
[
HTTP_METHOD, "POST",
HTTP_MIMETYPE, "application/x-www-form-urlencoded"
],
params);
}
}
} else if (channel == meter_chan) {
list info = llGetObjectDetails(id, [OBJECT_CREATOR]);
if (llListFindList(creator_keys, [llList2Key(info, 0)]) > -1) {
if (message == "Can Pay") {
llRegionSayTo(id, meter_chan, "Found Me," + (string)owner + "," + llGetDisplayName(owner));
} else if (message == "Can Attack") {
llRegionSayTo(id, meter_chan, "Found Me," + (string)owner + "," + llGetDisplayName(owner));
} else if (message == "Ping") {
llRegionSayTo(id, meter_chan, "Pong," + (string)owner);
} else if (message == "1") {
init();
} else if (message == "Attack Accept") {
string params = "uuid=" + (string)owner + "&hash=" + llSHA1String((string)owner + hash_seed)
+ "&action=a"
+ "&defender=" + llList2String(nearby_players, attack_person_idx)
+ "&stats=" + llEscapeURL(attack_type);
http_request_id = llHTTPRequest(API_URL,
[
HTTP_METHOD, "POST",
HTTP_MIMETYPE, "application/x-www-form-urlencoded"
],
params);
} else if (message == "Attack Reject") {
llSay(0, "The request to attack secondlife:///app/agent/" + llList2String(nearby_players, attack_person_idx) + "/about was rejected.");
} else {
list changes = llParseStringKeepNulls(message, [","], []);
string action = llList2String(changes, 0);
if (action == "STAT") {
string params = "uuid=" + (string)owner + "&hash=" + llSHA1String((string)owner + hash_seed)
+ "&action=u"
+ "&experience=" + llList2String(changes, 1)
+ "&health=" + llList2String(changes, 2)
+ "&attack=" + llList2String(changes, 3)
+ "&defense=" + llList2String(changes, 4)
+ "&boost_attack=" + llList2String(changes, 5)
+ "&boost_defense=" + llList2String(changes, 6)
+ "¤cy_banked=" + llList2String(changes, 7)
+ "&pass=" + (string)id;
http_request_id = llHTTPRequest(API_URL,
[
HTTP_METHOD, "POST",
HTTP_MIMETYPE, "application/x-www-form-urlencoded"
],
params);
} else if (action == "Found Me") {
nearby_players += [llList2Key(changes, 1), llList2String(changes, 2)];
} else if (action == "Attack Request") {
dialog_state = "attack confirm";
dialog_listener = llListen(dialog_chan, "", owner, "");
llSetTimerEvent(60);
requesting_attacker = (key)llList2String(changes, 1);
llDialog(owner, "\nIncoming Attack\n \nsecondlife:///app/agent/" + llList2String(changes, 1) + "/about has requested a " + llList2String(changes, 2) + " attack.", ["Accept RP", "Not RP"], dialog_chan);
}
}
}
} else if (channel == update_chan) {
is_current_version = FALSE;
update_msg = HUD_NAME + "\n" + message;
setTitle();
}
}
timer() {
if (scanning_for_payees) {
scanning_for_payees = FALSE;
integer num_players = llGetListLength(nearby_players);
if (num_players > 0) {
integer i;
dialog_prompt = "\n ** Select A Player To Pay **\n";
dialog_state = "pay";
showDialogPage(1);
return;
} else {
llSay(0, "No one is nearby to pay.");
}
} else if (scanning_for_victims) {
scanning_for_victims = FALSE;
integer num_players = llGetListLength(nearby_players);
if (num_players > 0) {
integer i;
dialog_prompt = "\n ** Select A Player To Attack **\n";
dialog_state = "attack";
showDialogPage(1);
return;
} else {
dialog_state = "";
llSay(0, "No one is nearby to attack.");
}
}
if (dialog_listener) {
nearby_players = [];
pay_person_idx = -1;
requesting_attacker = NULL_KEY;
llListenRemove(dialog_listener);
}
if (update_listener) {
llListenRemove(update_listener);
}
}
run_time_permissions(integer perm) {
if(perm & PERMISSION_ATTACH) {
if (llGetRegionName() != allowed_region) {
llDetachFromAvatar();
}
}
}
attach(key id) {
if (id) {
llResetScript();
}
}
changed(integer change) {
if (change & CHANGED_REGION) {
if (llGetRegionName() != allowed_region) {
llOwnerSay("You are not in " + allowed_region + ". This HUD can only be used in " + allowed_region + ".");
llRequestPermissions(owner, PERMISSION_ATTACH);
}
}
}
}