waypoint_config_1.lsl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // :CATEGORY:Tour Guide
  2. // :NAME:waypoint_config
  3. // :AUTHOR:Anonymous
  4. // :CREATED:2010-01-10 05:20:56.000
  5. // :EDITED:2013-09-18 15:39:09
  6. // :ID:967
  7. // :NUM:1389
  8. // :REV:1.0
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // waypoint_config.lsl
  12. // :CODE:
  13. list waypoints = [];
  14. integer waypoint = 0;
  15. integer chat_listener = 0;
  16. string replaceString(string pattern, string replace, string source, integer count) {
  17. while(count-- != 0) {
  18. integer index = llSubStringIndex(source, pattern);
  19. if(index < 0)
  20. return source;
  21. source = llInsertString(llDeleteSubString(source, index, (index + llStringLength(pattern) - 1)), index, replace);
  22. }
  23. return source;
  24. }
  25. string ce(integer c, string t, string f) {
  26. if(c == TRUE)
  27. return t;
  28. else
  29. return f;
  30. }
  31. show_dialog(key user) {
  32. integer wpcount = llGetListLength(waypoints) >> 1;
  33. llDialog(user,"We are at waypoint " + ((string)(waypoint+1)) + "/" + ((string)wpcount) + "\nPosition: " + (string)llList2Vector(waypoints,waypoint<<1) + "\nRotation: " + (string)llList2Rot(waypoints,(waypoint<<1)+1),[ce(waypoint > 0, "<", " "),"save",">","clear","load"],-19923);
  34. }
  35. save() {
  36. if(waypoint >= llGetListLength(waypoints) >> 1)
  37. waypoints = (waypoints=[]) + waypoints + [llGetPos(),llGetRot()];
  38. else {
  39. waypoints = llListReplaceList(waypoints, [llGetPos(), llGetRot()], waypoint << 1, (waypoint << 1) + 1);
  40. }
  41. }
  42. unsave() {
  43. if(waypoint >= llGetListLength(waypoints) >> 1)
  44. save();
  45. else {
  46. llSetPos(llList2Vector(waypoints, waypoint << 1));
  47. llSetRot(llList2Rot(waypoints, (waypoint << 1) + 1));
  48. //llMoveToTarget(llList2Vector(waypoints, waypoint << 1),0.25);
  49. //llRotLookAt(llList2Rot(waypoints, (waypoint << 1) + 1), 1, 0.25);
  50. }
  51. }
  52. say() {
  53. list tmp = [];
  54. integer i = llGetListLength(waypoints);
  55. vector sp = llList2Vector(waypoints, 0);
  56. while(i>=2) {
  57. tmp = (tmp=[]) + [llList2Vector(waypoints, i - 2) - sp, llList2Rot(waypoints, i - 1)] + tmp;
  58. i-=2;
  59. }
  60. string str = "vector start = " + (string)sp + "; list waypoints = [" + llDumpList2String(tmp, ", ") + "];";
  61. llSay(0, str);
  62. }
  63. default {
  64. touch_start(integer num) {
  65. llListen(-19923,"","","");
  66. save();
  67. show_dialog(llDetectedKey(0));
  68. }
  69. listen(integer chan, string name, key user, string msg) {
  70. if(chan == 0) {
  71. if(llGetSubString(msg,0,4) != "load ")
  72. return;
  73. llListenRemove(chat_listener);
  74. chat_listener = 0;
  75. save();
  76. say();
  77. list tmp = llCSV2List(llGetSubString(msg,5,-1));
  78. waypoints = [];
  79. waypoint = 0;
  80. while(waypoint<llGetListLength(tmp)) {
  81. vector v = (vector)llList2String(tmp, waypoint++);
  82. rotation r = (rotation)llList2String(tmp, waypoint++);
  83. llOwnerSay((string)v);
  84. waypoints = (waypoints=[]) + waypoints + [v,r];
  85. }
  86. waypoint = 0;
  87. unsave();
  88. }
  89. else if(msg == "<") {
  90. save();
  91. if(waypoint > 0)
  92. waypoint--;
  93. unsave();
  94. }
  95. else if(msg == ">") {
  96. save();
  97. waypoint++;
  98. unsave();
  99. }
  100. else if(msg == "save") {
  101. save();
  102. say();
  103. return;
  104. }
  105. else if(msg == "clear") {
  106. save();
  107. say();
  108. waypoint = 0;
  109. waypoints = [];
  110. save();
  111. }
  112. else if(msg == "load") {
  113. llSay(0,"Type \"load <x,y,z>,<x,y,z,s>,...\" in chat...");
  114. chat_listener = llListen(0,"","","");
  115. return;
  116. }
  117. else
  118. llOwnerSay((string)name+"("+(string)chan+"): "+msg);
  119. show_dialog(user);
  120. }
  121. }
  122. // END //