Sequencer.lsl 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // :SHOW:1
  2. // :CATEGORY:Gaming
  3. // :NAME:Sequencer and Collider for All in One NPC Controller
  4. // :AUTHOR:Ferd Frederix
  5. // :KEYWORDS:Game, Collider
  6. // :REV:1.0
  7. // :WORLD:Opensim
  8. // :DESCRIPTION:
  9. // Sequencer script for NPC animator for HyperGrid Story nine sim. It sequences multiple NPCs in order thru a scenarios
  10. // each 'things' entry is the NPC number, a (float) time to take between sending commands ( 0 is not allowed, but a small number is()
  11. ///and a @command that is sent to the NPC.
  12. // :CODE:
  13. // Notes: Link messages arte as follows
  14. // Rev: 2 fixes the Linux bug for collisions.
  15. //
  16. integer debug = 1; // set to TRUE or FALSE for debug chat on various actions
  17. // list of NPCs and their linked prim numbers
  18. list npcName = ["namaka",2,"dylan",3,"npc1",4,"npc2",5,"npc3",6,"npc4",7,"npc5",8,"npc6",9];
  19. integer CommandChannel = 23;
  20. // DEBUG(string) will chat a string or display it as hovertext if debug == TRUE
  21. DEBUG(string str) {
  22. if (debug ==1 )
  23. llSay(0, llGetScriptName() + ":" + str);
  24. if (debug ==2 )
  25. llSetText(str,<1,1,1>,1.0);
  26. }
  27. integer osIsNpc(key id){
  28. return FALSE;
  29. }
  30. string osGetNotecard(string name) {
  31. // sample notecard for testing
  32. string str = "NPC #| seconds | Command\n"
  33. +"npc1|0|@pause=1\n"
  34. +"sylan|0|@animate=avatar_jumpforjoy|5\n"
  35. +"namaka|0|@say=Hello! What happened to you two?\n"
  36. +"Derf|0|@say=error\n"
  37. +"dylan|2|@animate=avatar_type|2\n"
  38. +"dylan|8|@say=I think we can transform back to our original selves, at last.\n";
  39. return str;
  40. }
  41. integer SENSE = FALSE; // sensor for an avatar
  42. float RATE = 5; // every 5 seconds
  43. integer COLLIDE = TRUE; // if they collide, trigger the sequence
  44. float RANGE = 96; // a very short range as this goes into a ring around the avatar
  45. integer Rezzed;
  46. list things ;
  47. // CODE follows
  48. Send(string who, string cmd)
  49. {
  50. DEBUG("Sending to " + who + "(" + (string) lookup(who) + ") the command " + cmd);
  51. llMessageLinked(lookup(who),0,cmd,"");
  52. }
  53. integer lookup(string Name)
  54. {
  55. integer i = llListFindList(npcName,[Name]);
  56. if (i != -1)
  57. return llList2Integer(npcName,i+1);
  58. return 0;
  59. }
  60. // For rezzing in
  61. RezIn()
  62. {
  63. DEBUG("Rezz In = @reset");
  64. llMessageLinked(LINK_SET,0,"@reset","");
  65. }
  66. DoIt()
  67. {
  68. string note = osGetNotecard("Sequence");
  69. list stuff= llParseString2List(note,["\n"],[]);
  70. DEBUG("stuff:" + llDumpList2String(stuff,":"));
  71. integer i;
  72. integer j = llGetListLength(stuff);
  73. for (i=0; i < j; i++)
  74. {
  75. string noteline = llList2String(stuff,i);
  76. DEBUG("noteline:" + noteline);
  77. list line = llParseString2List(noteline,["|"],[]);
  78. string primName = llList2String(line,0);
  79. float sleepTime = llList2Integer(line,1);
  80. string atCmd = llList2String(line,2);
  81. string param1= llList2String(line,3);
  82. string param2= llList2String(line,4);
  83. DEBUG("prim:" + primName);
  84. DEBUG("num:" + (string) lookup(primName));
  85. DEBUG("time:" + (string) sleepTime);
  86. DEBUG("atCmd:" +atCmd);
  87. if (lookup(primName) && llSubStringIndex(atCmd,"@") == 0)
  88. {
  89. things += lookup(primName);
  90. things += sleepTime;
  91. things += atCmd+"|" + param1 + "|" + param2;
  92. }
  93. }
  94. DEBUG("Things:" + llDumpList2String(things,":"));
  95. }
  96. Speak() {
  97. integer prim = llList2Integer(things,0);
  98. float time = llList2Float(things,1);
  99. string msg = llList2String(things,2);
  100. DEBUG("Prim:" + (string) prim + " time:" + (string) time + " Msg:" + msg);
  101. if (llStringLength(msg)) {
  102. things = llDeleteSubList(things,0,2);
  103. DEBUG("LINK:" +(string) prim + ":" + msg);
  104. llMessageLinked(prim,0, msg,"");
  105. if (time > 0) {
  106. llSetTimerEvent(time);
  107. } else {
  108. llSetTimerEvent(0.1);
  109. }
  110. } else {
  111. DEBUG("Done");
  112. Rezzed = 0;
  113. llSetTimerEvent(0);
  114. if (SENSE)
  115. llSensorRepeat("","",AGENT,RANGE,PI,RATE);
  116. }
  117. }
  118. default
  119. {
  120. state_entry()
  121. {
  122. llSetText("",<1,1,1>,1.0);
  123. RezIn();
  124. llSetTimerEvent(0);
  125. if (SENSE)
  126. llSensorRepeat("","",AGENT,RANGE,PI,RATE);
  127. llListen(CommandChannel,"","","");
  128. }
  129. touch_start(integer p) {
  130. DEBUG("touched");
  131. if (llGetOwner() == llDetectedKey(0))
  132. {
  133. Send("Claire","@say=touched");
  134. }
  135. }
  136. listen(integer channel, string name, key id, string message)
  137. {
  138. DEBUG(message);
  139. list vars = llParseString2List(message,["|"],[]);
  140. string num = llList2String(vars,0);
  141. string cmd = llList2String(vars,1);
  142. Send(num, cmd);
  143. }
  144. sensor(integer n) {
  145. DEBUG("Sensed");
  146. if (! osIsNpc(llDetectedKey(0))) {
  147. DEBUG("Sensed avatar");
  148. llSensorRemove();
  149. RezIn();
  150. }
  151. }
  152. timer()
  153. {
  154. Speak();
  155. }
  156. collision_start(integer n) {
  157. DEBUG("Collided with " + llKey2Name(llDetectedKey(0)));
  158. if (! osIsNpc(llDetectedKey(0)))
  159. {
  160. DoIt();
  161. Speak();
  162. }
  163. }
  164. on_rez(integer p)
  165. {
  166. llResetScript();
  167. }
  168. changed(integer what)
  169. {
  170. if (what & CHANGED_REGION_START)
  171. {
  172. llResetScript();
  173. }
  174. }
  175. }