-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathController.lsl
More file actions
2012 lines (1830 loc) · 65.4 KB
/
Controller.lsl
File metadata and controls
2012 lines (1830 loc) · 65.4 KB
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
integer channel = 68;
integer PEG_CHAN=699;
integer TIMER_INTERVAL=5; // how often to run the timer
integer autoLoadOnReset=0;
string LASTNAME="(NPC)";
// Nothing to edit here, see https://github.com/opensimworld/active-npcs for configuration
list availableNames = [];
list lastNames = [];
// These will be loaded from notecards
list wNodes = [];
list wLinks = [];
list wNodeNames=[];
// list of nodes for the "Flyaround" command
list flyTargets = [];
list menuItems = ["SaveNPC", "LoadNPC", "RemoveNPC", "RemoveAll", "LoadAll", "ReConfig","InitCmds", "DumpData", "TimerOnOff", "Close"];
string userInputState ="";
integer gListener;
integer zListener;
integer howmany;
list avis;
integer curVisitors=1;
integer deflectToNode = -1; // if set, the NPCs will only run notecards at the specified waypoint
list aviUids;
list aviNames;
list aviNodes;
list aviPrevNodes;
list aviStatus;
list aviFollow;
list aviCurrentAnim;
list aviPath;
list aviAlarm;
list aviScriptIndex;
list aviScriptText;
list aviHttpId;
list aviTarget; // user we are interacting with
list scriptVars;
list aviScriptState;
list aviPrompts;
list cache;
integer aviIndex = -1;
list seenArchive;
list positionsList;
list greetedAvis;
integer timerRuns;
integer timerRunning;
integer curPoint;
integer prevPoint;
list wayPoints;
list wayNames;
list wayLinks;
list wayKeys;
string name;
key npc;
list candidateNode=[];
string vec2str(vector v)
{
return "<"+v.x+","+v.y+","+v.z+">";
}
string GetLastName(string first)
{
integer idx = llListFindList(availableNames, [first]);
if (idx >=0) return llList2String(lastNames, idx);
else return LASTNAME;
}
key getAgentByName(string firstName)
{
firstName = llToLower(firstName);
list ag = osGetAvatarList();
integer howmany = llGetListLength(ag);
integer i;
for (i =0; i < howmany; i+=3)
{
string name = llList2String(ag, i+2);
integer sep = llSubStringIndex(name, " ");
if (llToLower(llGetSubString(name, 0,sep-1)) == firstName)
{
return llList2Key(ag, i);
}
}
return NULL_KEY;
}
string GetScriptVar(string cmd3)
{
integer i;
for (i=0; i < llGetListLength(scriptVars); i+=2)
{
if (llList2String(scriptVars,i) == cmd3 )
{
return llList2String(scriptVars, i+1);
}
}
return ""; // default value;
}
integer ScriptJump(integer idx, string label, integer complain)
{
// Jump to a label in the notecard
integer foundLine = FindScriptLineAfter(llList2String(aviScriptText,idx), "@"+label,-1);
if (foundLine == -1)
{
if (complain) llOwnerSay("Error: @"+label+" label not found");
return 0;
}
else
{
aviScriptIndex = []+llListReplaceList(aviScriptIndex, [foundLine+1], idx, idx);
return 1;
}
}
list permList;
string permCache;
LoadPerms()
{
permList=[];
permCache = "";
if (llGetInventoryType("__permissions")==INVENTORY_NOTECARD)
{
llOwnerSay("Loading Permissions...");
list lines = llParseString2List(osGetNotecard("__permissions"), ["\n"], []);
integer l;
for (l=0;l<llGetListLength(lines);l++)
{
list tk = llParseString2List(llList2String(lines,l), [" "], []);
if (llList2String(tk,2) == "=")
{
string kw = llList2String(tk,3);
string rule=llToLower(llList2String(tk,0)+" "+llList2String(tk,1));
string n= llToLower(llStringTrim(llList2String(tk,4)+ " " + llList2String(tk,5), STRING_TRIM));
if (n == "" ) n= "*";
string val=kw+"|"+n+"|";
permList+=rule;
permList+=kw;
permList+=n;
if (llSubStringIndex(permCache,rule)<0) permCache+= rule;
}
}
llOwnerSay(llList2CSV(permList));
llOwnerSay(llList2CSV(permCache));
}
}
integer IsAllowed(string npc, string cmd, key uid)
{
if (uid == llGetOwner() || llGetListLength(permList)==0) return 1;
string ss = "* *";
string ns = npc+" *";
string sc = "* "+cmd;
string nc = npc+" "+cmd;
if (llSubStringIndex(permCache, ss)<0 && llSubStringIndex(permCache, ns)<0 && llSubStringIndex(permCache, sc)<0 && llSubStringIndex(permCache, nc)<0 ) return 1;
integer allow=1;
string name = llToLower(llKey2Name(uid));
integer k;
for (k=0; k< llGetListLength(permList); k+=3)
{
string rule = llList2String(permList,k);
if (rule==ss || rule==ns || rule==sc || rule==nc)
{
//llOwnerSay("R="+rule);
string r = llList2String(permList, k+1);
if (r =="ALLOW" || r == "DENY")
{
string who=llList2String(permList, k+2);
if (who == "*" || who==name)
{
if (r == "ALLOW") allow=1;
else allow=0;
}
}
else if (r=="ALLOWID")
{
if ( uid == llList2Key(permList, k+2)) allow=1;
}
else if (r=="DENYID")
{
if ( uid == llList2Key(permList, k+2)) allow=0;
}
else if (r =="ALLOWSAMEGROUP")
{
if ( llSameGroup(uid)) {
allow=1;
}
}
}
}
return allow;
}
ReloadConfig()
{
availableNames = [];
lastNames = [];
list tk = llParseString2List(osGetNotecard("__npc_names"), ["\n"] , []);
integer i=0;
for (i=0; i < llGetListLength(tk); i++)
{
list t2 = llParseString2List(llList2String(tk,i), [" "] , []);
string f = llList2String(t2, 0);
string l = llList2String(t2, 1);
if (l =="") l = LASTNAME;
if (f != "")
{
availableNames += f;
lastNames += l;
}
}
llOwnerSay("npc_names: "+llList2CSV(availableNames));
flyTargets = llParseString2List(osGetNotecard("__fly_targets"), [" ", "\n", ""] , []);
string ncName = "__config";
autoLoadOnReset=0;
if (llGetInventoryType(ncName) == INVENTORY_NOTECARD)
{
list tok = llParseString2List(osGetNotecard("__config"), ["=", "\n"] , []);
integer j;
for (j=0; j < llGetListLength(tok); j+=2)
{
string opt = llList2String(tok,j);
if (opt== "AutoLoadOnReset") autoLoadOnReset = (integer)llList2String(tok, j+1);
else if (opt== "LastName") LASTNAME = llList2String(tok, j+1);
}
}
if (LASTNAME == "") LASTNAME = "(NPC)";
LoadPerms();
}
integer countVisitors()
{
list avis = llGetAgentList(AGENT_LIST_REGION, []);
integer howmany = llGetListLength(avis);
integer i;
integer nNew =0;
for ( i = 0; i < howmany; i++ ) {
if ( ! osIsNpc(llList2Key(avis, i)) )
{
nNew++; // only non-NPC's
key uu = llList2Key(avis, i);
string nm = llKey2Name(uu);
if (nm != "")
{
integer fnd = llListFindList(seenArchive, [nm]);
if (fnd >=0)
seenArchive = [] + llListReplaceList(seenArchive, [nm, llGetUnixTime()], fnd, fnd+1);
else
seenArchive = [] + seenArchive + [nm, llGetUnixTime()];
}
}
}
return nNew;
}
doLoadNPC(string first, string last)
{
integer idx =(GetNPCIndex(first));
if (idx >=0)
{
llOwnerSay(first+ " is already in region, not loading");
osNpcStand(llList2Key(aviUids, idx));
return;
}
key unpc = osNpcCreate(first, last, llGetPos()+<0,0,3>, "APP_"+llToLower(first), OS_NPC_SENSE_AS_AGENT );
if (unpc != NULL_KEY)
doAddNpc(first, unpc);
}
doAddNpc(string name, string unpc)
{
llOwnerSay( "Adding '"+name+"'");
aviUids += unpc;
aviNames += llToLower(name);
aviNodes += 1;
aviPrevNodes += 0;
aviStatus += "";
aviFollow += "";
aviCurrentAnim += "";
aviHttpId += "";
aviAlarm += -1;
aviScriptIndex += -1;
aviScriptText += "";
aviTarget += NULL_KEY;
aviPath += "";
aviScriptState += "";
aviPrompts += "";
osNpcMoveToTarget(unpc, osNpcGetPos(unpc) + <1,0,0>, OS_NPC_NO_FLY );
}
doRemoveNpc(string who)
{
integer idx = GetNPCIndex(who);
if (idx <0) return;
key u = llList2Key(aviUids, idx);
aviNames = [] + llDeleteSubList(aviNames, idx, idx);
aviUids = [] + llDeleteSubList(aviUids, idx, idx);
aviNodes = [] + llDeleteSubList(aviNodes, idx, idx);
aviPrevNodes = [] + llDeleteSubList(aviNodes, idx, idx);
aviFollow = [] + llDeleteSubList(aviFollow, idx, idx); [];
aviStatus = [] + llDeleteSubList(aviStatus, idx, idx);
aviCurrentAnim = [] + llDeleteSubList(aviCurrentAnim, idx, idx);
aviPath = [] + llDeleteSubList(aviPath, idx, idx);
aviHttpId = [] + llDeleteSubList(aviHttpId, idx, idx);
aviAlarm = [] + llDeleteSubList(aviAlarm, idx, idx);
aviScriptIndex = [] + llDeleteSubList(aviScriptIndex, idx, idx);
aviScriptText = [] + llDeleteSubList(aviScriptText, idx, idx);
aviTarget = [] + llDeleteSubList(aviTarget, idx, idx);
aviScriptState = [] + llDeleteSubList(aviScriptState, idx, idx);
aviPrompts = [] + llDeleteSubList(aviPrompts, idx, idx);
llOwnerSay("Removing "+who + "");
osNpcStand(u);
osNpcRemove(u);
}
doLoadAll()
{
integer i;
for (i=0; i < llGetListLength(availableNames);i++)
{
doLoadNPC(llList2String(availableNames, i), llList2String(lastNames, i));
}
}
doInitCmds()
{
string notecard= "__initcommands";
integer i;
for(i=0; i<=osGetNumberOfNotecardLines(notecard); i++) {
string line = llStringTrim(osGetNotecardLine(notecard, i), STRING_TRIM);
if (llStringLength(line)>0 && line != "")
{
list l = llParseString2List(line, [" "], []);
line = "! "+(string)NULL_KEY+" "+llList2String(l,0)+" "+ line;
llOwnerSay("InitCmd="+line);
ProcessNPCCommand(line);
}
}
}
setVar(string cmd2, string cmd3)
{
integer i;
for (i=0; i < llGetListLength(scriptVars); i+=2)
{
if (llList2String(scriptVars,i) == cmd2)
{
scriptVars = [] + llListReplaceList(scriptVars, [cmd3], i+1, i+1);
return;
}
}
scriptVars += cmd2;
scriptVars += cmd3;
}
integer RescanAvis()
{
avis = osGetAvatarList();
howmany = llGetListLength(avis);
integer i;
for (i =0; i < howmany; i+=3)
{
if (osIsNpc(llList2Key(avis, i)))
{
integer sep = llSubStringIndex(llList2Key(avis, i+2), " ");
string nm = llGetSubString(llList2Key(avis, i+2), 0, sep-1 );
doAddNpc(nm, llList2Key(avis, i));
}
}
llOwnerSay(llList2CSV(aviNames));
llOwnerSay(llList2CSV(aviStatus));
return llGetListLength(aviUids);
}
LoadMapData()
{
integer tl = osGetNumberOfNotecardLines("__waypoints");
integer i;
wNodes = [];
for (i=0; i < tl; i++)
{
string line = osGetNotecardLine("__waypoints",i);
list tok = llParseStringKeepNulls(line, [","], []);
float x = llList2Float(tok,0);
if (x>0)
{
vector v = <llList2Float(tok,0), llList2Float(tok,1),llList2Float(tok,2)>;
wNodes += v;
wNodeNames += llList2String(tok,3);
}
}
llOwnerSay("loaded "+(string)(llGetListLength(wNodes))+" waypoints");
integer tnodes = llGetListLength(wNodes);
wLinks = [];
tl = osGetNumberOfNotecardLines("__links");
for (i=0; i < tl; i++)
{
string line = osGetNotecardLine("__links",i);
list tok = llParseString2List(line, [","],"");
integer a= llList2Integer(tok,0);
integer b = llList2Integer(tok,1);
if (a !=b)
wLinks += [a,b];
}
llOwnerSay("loaded "+(string)(llGetListLength(wLinks)/2)+" links");
cache = [];
}
integer GetNPCIndex(string name) /// name is in lowercase
{
return llListFindList(aviNames, [llToLower(name)]);
}
integer GetWalkTime(float distance)
{
return llCeil(distance / 1.7);
}
integer GetNearestNode(vector pos)
{
integer i;
float min = 9999991.;
integer l =-1;
for (i=0;i < llGetListLength(wNodes); i++)
{
float dist = llVecDist(pos, llList2Vector(wNodes,i));
if (dist < min)
{
min = dist;
l=i;
}
}
return l;
}
list foundPaths;
// Get path through LSL -- Slow
integer GenPaths(integer a, integer tgt, string path, integer depth)
{
if (depth > 17)
{
//llOwnerSay("Bailing at " + path);
return 0;
}
integer i;
for (i=0; i < llGetListLength(wLinks); i+=2)
{
integer ca = llList2Integer(wLinks, i);
integer cb = llList2Integer(wLinks, i+1);
integer fn = -1;
if (cb == a || ca == a)
{
if (cb == a)
fn = ca;
else if (ca == a)
fn = cb;
if (llSubStringIndex(path, ":"+fn+":")<0)
{
if (fn == tgt)
{
path += ""+fn+":";
foundPaths += (path);
return 1;
}
else
{
GenPaths(fn, tgt, path+fn+":", depth+1);
}
}
}
if (llGetListLength(foundPaths)>30)
return 2;
}
return 0;
}
string GetGotoPath(integer nodeA, integer nodeB)
{
integer i;
integer ww;
string tmpPath = ":"+(string)nodeA+":";
foundPaths = [];
GenPaths(nodeA, nodeB, tmpPath, 0);
//llOwnerSay(llList2CSV(foundPaths));
if (llGetListLength(foundPaths) ==0)
return "";
integer min = 99999;
string least = "";
for (i=0; i < llGetListLength(foundPaths); i++)
{
ww = llStringLength(llList2String(foundPaths, i));
if (ww < min)
{
min = ww;
least = llList2String(foundPaths, i);
}
}
//llOwnerSay(least);
return least;
}
integer GetNPCIndexByUid(key name)
{
return llListFindList(aviUids, [name]);
}
string GetScriptLine(string scriptData, integer line)
{
list scriptLines = llParseStringKeepNulls(scriptData, ["\n",";"], []);
return llList2String(scriptLines, line-1);
}
integer FindScriptLineAfter(string scriptData, string lineToFind, integer afterLine)
{
integer endIdx;
list scriptLines = llParseStringKeepNulls(scriptData, ["\n",";"], []);
string toFind = llToLower(lineToFind);
integer foundLine = -1;
string line;
for (endIdx = afterLine+1;endIdx < llGetListLength(scriptLines); endIdx++)
{
line = llList2String(scriptLines, endIdx);
if (llStringTrim(line, STRING_TRIM) == toFind)
{
foundLine =endIdx;
jump _foundIdxOut;
}
}
@_foundIdxOut;
return foundLine;
}
integer FindMatchingEndif(string scriptData, integer afterLine)
{
integer endIdx;
list scriptLines = llParseStringKeepNulls(scriptData, ["\n",";"], []);
string toFind = "end-if";
integer foundLine = -1;
string line;
integer ifLevel=1;
for (endIdx = afterLine+1;endIdx < llGetListLength(scriptLines); endIdx++)
{
line = llStringTrim(llList2String(scriptLines, endIdx), STRING_TRIM);
if (llGetSubString(line, 0, 1) == "if")
{
ifLevel++;
}
else if (line == "end-if")
{
ifLevel--;
if (ifLevel==0)
{
foundLine =endIdx;
jump _foundEIIdxOut;
}
}
}
@_foundEIIdxOut;
return foundLine;
}
integer GetNodeIndexByName(string nodeName)
{
integer i;
nodeName = llToLower(nodeName);
for (i=0; i < llGetListLength(wNodeNames); i++)
{
if (llToLower(llList2String(wNodeNames, i)) == nodeName)
{
return i;
}
}
return -1;
}
SetScriptAlarm(integer aviId, integer time)
{
aviAlarm = [] + llListReplaceList(aviAlarm, [llGetUnixTime() + time], aviId, aviId);
}
doStopNpc(integer idx, key uNPC)
{
aviStatus = [] + llListReplaceList(aviStatus, [""], idx, idx);
SetScriptAlarm(idx, 0);
list anToStop=llGetAnimationList(uNPC);
integer stop=llGetListLength(anToStop);
while (--stop>=0) { osNpcStopAnimation(uNPC,llList2Key(anToStop,stop)); }
osNpcStopMoveToTarget(uNPC);
osNpcStand(uNPC);
}
// Handler for all commands coming from chat
integer ProcessNPCCommand(string inputString)
{
list tokens = llParseString2List(inputString, [" "], []);
// first token should be just "!"
//llOwnerSay("<<" + inputString);
key sendUid = llList2Key(tokens,1);
string npcName = llToLower(llList2String(tokens,2));
string name2 = llToLower(llList2String(tokens,3));
//if (npcName != name2) npcName = name2;
integer idx = GetNPCIndex(npcName);
if (idx <0)
{
return 1;
}
key uNPC= llList2Key(aviUids, idx);
if (uNPC == NULL_KEY)
{
return 1;
}
if (llSubStringIndex(inputString, "$")>=0) //substiute variables
{
integer i;
for (i=4; i < llGetListLength(tokens); i++)
{
string st = llList2String(tokens,i);
if (llSubStringIndex(st, "$")==0)
{
tokens = [] + llListReplaceList(tokens, [ GetScriptVar(llGetSubString(st,1,-1) ) ], i , i);
}
}
}
string cmd1= llList2String(tokens,4);
string cmd2= llList2String(tokens,5);
list userData;
if (sendUid!= NULL_KEY && (llGetAgentSize(sendUid) != ZERO_VECTOR))
{
if (!IsAllowed(npcName, cmd1, sendUid))
{
llOwnerSay("Denied '"+cmd1+"' to "+(string)sendUid+" "+llKey2Name(sendUid));
return 1;
}
}
if (llList2String(aviStatus, idx) == "prompt")
{
aviStatus = []+llListReplaceList(aviStatus, [""], idx, idx); // Turn off prompt in sync with the listener
if (npcName != name2 ) // it (probably) a response to the prompt, rather than a command given to the npc
{
integer i;
for (i=3; i < llGetListLength(tokens); i++)
{
if ( llSubStringIndex(llList2String(aviPrompts, idx), "["+llToLower(llList2String(tokens, i))+"]" ) > 0) // label existed in prompt
{
aviTarget = []+llListReplaceList(aviTarget, [sendUid], idx, idx);
ScriptJump(idx, llToLower(llList2String(tokens, i)) , 1);
return 1;
}
}
return 1;
}
}
if (cmd1 == "stop")
{
doStopNpc(idx, uNPC);
}
else if (cmd1 == "come")
{
doStopNpc(idx, uNPC);
userData=llGetObjectDetails((key)sendUid, [OBJECT_NAME,OBJECT_POS, OBJECT_ROT]);
osNpcStopMoveToTarget(uNPC);
osTeleportAgent(uNPC, llList2Vector(userData, 1) + <1, 0, 0>, <1,1,1>);
if (sendUid != NULL_KEY) // NOTE: a real avatar sent this command - stop processing our script
aviScriptIndex = []+llListReplaceList(aviScriptIndex, -1, idx, idx);
}
else if (cmd1 == "stand")
{
aviStatus = []+llListReplaceList(aviStatus, [""], idx, idx);
osNpcStand(uNPC);
osNpcStopMoveToTarget(uNPC);
}
else if (cmd1 == "moveto" || cmd1 == "movetov" || cmd1 == "runtovr"|| cmd1 == "movetovr" || cmd1 == "flytov" || cmd1 == "runtov" || cmd1=="walk" )
{
// Walk to the specified waypoint or vector
vector v;
string anim =""; // Specify an animation to play while walking
if (cmd1 == "runtovr"||cmd1 == "movetovr")
{
// run to somewhere within the volume enclosed by v1 and v2
vector v1 = (vector) cmd2;
vector v2 = (vector) llList2String(tokens, 6);
v.x= v1.x + llFrand(v2.x-v1.x);
v.y= v1.y + llFrand(v2.y-v1.y);
v.z= v1.z + llFrand(v2.z-v1.z);
anim = llList2String(tokens, 7);
}
else if (cmd1 == "movetov" || cmd1 == "flytov" ||cmd1 == "runtov" || cmd1 =="walk")
{
v = (vector)cmd2;
if (v == ZERO_VECTOR)
{
llOwnerSay(npcName + ": "+cmd2+" is not a good position. I am not going there!");
return 1;
}
anim = llList2String(tokens, 6);
}
else
v = llList2Vector(wNodes, (integer)cmd2);
float dist = llVecDist(osNpcGetPos(uNPC), v);
if (cmd1 == "runtovr"|| cmd1 == "runtov")
{
osSetSpeed(uNPC, 1.0);
osNpcMoveToTarget(uNPC, v + <0,0,1>, OS_NPC_NO_FLY | OS_NPC_RUNNING);
SetScriptAlarm(idx, (integer)(GetWalkTime(dist)/2.));
}
else
{
if (anim == "")
osNpcStand(uNPC);
osNpcStopMoveToTarget(uNPC);
osSetSpeed(uNPC, 0.5);
if (cmd1 == "flytov")
osNpcMoveToTarget(uNPC, v + <0,0,1>, OS_NPC_FLY );
else
osNpcMoveToTarget(uNPC, v + <0,0,1>, OS_NPC_NO_FLY);
if (anim)
{
llSleep(0.5);
osNpcPlayAnimation(uNPC, anim);
}
SetScriptAlarm(idx, GetWalkTime(dist));
}
}
else if (cmd1 == "setvar")
{
string cmd3 = llList2String(tokens,6);
setVar(cmd2, cmd3);
return 0;
}
else if (cmd1 == "if" || cmd1 == "if-not" || cmd1=="if-prob")
{
integer res = 0;
if (cmd1 == "if-prob")
{
if (llFrand(1.0)<(float)cmd2)
res = 1;
}
else if (cmd2 == "name-is")
{
integer k;
res=0;
for (k=6; k < llGetListLength(tokens); k++)
{
if (llToLower(npcName) == llToLower(llList2String(tokens,k)))
{
setVar("_found", npcName);
res=1;
}
}
}
else if (cmd2 == "var-is")
{
integer k;
res=0;
for (k=6; k < llGetListLength(tokens); k+=2)
{
string nm = llList2String(tokens,k);
if (nm == "") jump varIsBreak;
string val = llList2String(tokens,k+1);
if (GetScriptVar(nm) == val)
res =1;
else
{
res=0;
jump varIsBreak;
}
}
@varIsBreak;
}
else if (cmd2 == "state-is")
{
// If state-is <avi-name> <state-value>
integer nwho = GetNPCIndex(llList2String(tokens,6));
if (nwho >=0)
{
string what = llList2String(aviScriptState,nwho);
integer k;
for (k=7; k < llGetListLength(tokens); k++)
{
if (what == llList2String(tokens,k))
res=1;
}
}
}
if (cmd1 == "if-not")
res = !res;
integer scrline = llList2Integer(aviScriptIndex, idx);
if (scrline <0)
{
return 1; // wtf
}
if (!res)
{
integer foundLine = FindMatchingEndif(llList2String(aviScriptText,idx), scrline-1); /// this used to skip a line
if (foundLine == -1)
{
llOwnerSay("Error: end-if not found afterr "+cmd1 + " "+cmd2 + "...");
}
else
{
aviScriptIndex = []+llListReplaceList(aviScriptIndex, [foundLine+1], idx, idx);// Go past the end-if -- runs notecards faster
}
}
return 0;
}
else if (cmd1 == "end-if")
{
// Do nothing
return 0;
}
else if (cmd1 == "prompt")
{
string prompt = llDumpList2String(llList2List(tokens, 5, -1), " ");
aviStatus = []+llListReplaceList(aviStatus, ["prompt"], idx, idx);
osNpcSay(uNPC, prompt);
aviPrompts = []+llListReplaceList(aviPrompts, [llToLower(inputString)], idx, idx);
aviTarget = []+llListReplaceList(aviTarget, [NULL_KEY], idx, idx);
osMessageAttachments(uNPC, "prompt", [ATTACH_RIGHT_PEC], 0);
}
else if (cmd1 == "jump")
{
// Jump to a label in the notecard
ScriptJump(idx, llToLower(cmd2), 1);
return 0; // process next cmd immediately
}
else if ((cmd1 == "go" && cmd2 == "to") || cmd1 == "goto")
{
// Pathfinding command
integer nearest = GetNearestNode(osNpcGetPos(uNPC));
integer foundId =-1;
if (cmd1 == "goto")
{
foundId = (integer) cmd2;
}
else
{
string where = llToLower(llStringTrim(llList2String(tokens,6) +" "+ llList2String(tokens,7) +" "+ llList2String(tokens,8), STRING_TRIM));
integer i;
if (where != "")
foundId = GetNodeIndexByName(where);
if (foundId <0)
{
list tmp;
for (i=0; i < llGetListLength(wNodeNames); i++)
if (llList2String(wNodeNames,i) != "")
tmp += llList2String(wNodeNames, i);
osNpcSay(uNPC, "Sorry i dont know how to get to the "+where+ ". Here's some of the places i know: " +llList2CSV(tmp));
return 1;
}
}
osNpcSay(uNPC, "Let me think... ");
string cachekey = "f,"+(string)nearest+","+(string)foundId;
string gotoPath ="";
integer fidx = llListFindList(cache, [cachekey]);
if (fidx>=0)
{
gotoPath = llList2String(cache, fidx+1);
}
else
{
gotoPath = GetGotoPath(nearest, foundId);
if (gotoPath != "")
{
cache += cachekey;
cache += gotoPath;
}
}
if (gotoPath == "")
{
osNpcSay(uNPC, "I 'm dumb. i don't know how to get there ... ");
return 1;
}
osNpcSay(uNPC, "If you want to go there, follow me.");
SetScriptAlarm(idx, 0);
aviPath = []+ llListReplaceList(aviPath, [gotoPath], idx, idx);
aviStatus = []+llListReplaceList(aviStatus, ["pathf"], idx, idx);
}
else if (cmd1 == "setpath")
{
//Path must be in format 2:4:63:22:1 where the numbers are the waypoints numbers
aviPath = []+ llListReplaceList(aviPath, [cmd2], idx, idx);
SetScriptAlarm(idx, 0);
aviStatus = []+llListReplaceList(aviStatus, ["pathf"], idx, idx);
}
else if (cmd1 == "waitvar")
{
// Wait until the value of variable named cmd2 reaches the value cmd3
string cmd3 = llList2String(tokens,6);
string vval = GetScriptVar(cmd2);
if (vval == cmd3)
{
return 1; /// OK continue with the next line
}
else if (cmd3 == "NONEMPTY" && vval != "")
{
return 1;
}
integer scriptIndex = llList2Integer(aviScriptIndex, idx);
if (scriptIndex>0)
{
aviScriptIndex = []+llListReplaceList(aviScriptIndex, [scriptIndex-1], idx, idx);
}
}
else if (cmd1 == "increase" || cmd1 == "decrease" || cmd1 == "zero")
{
integer v = (integer)GetScriptVar(cmd2);
if (cmd1=="increase") v++;
else if (cmd1 == "decrease") v--;
else v=0;
setVar(cmd2, (string)v);
return 1;
}
else if (cmd1 == "wait")
{
integer tm = (integer)cmd2;
integer tm2 = (integer)llList2String(tokens,6);
if (tm2>0)
tm = (integer)(tm + llFrand(tm2));
SetScriptAlarm(idx, tm);
}
else if (cmd1 == "say" || cmd1 == "shout")
{