Controller.lsl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. // :SHOW:1
  2. // :CATEGORY:NPC
  3. // :NAME:HyperGrid Story Nine
  4. // :AUTHOR:Ferd Frederix
  5. // :KEYWORDS:NPC, controller, console
  6. // :CREATED:2015-11-24 20:25:33
  7. // :EDITED:2015-11-24 19:25:33
  8. // :ID:1087
  9. // :NUM:1838
  10. // :REV:1.0
  11. // :WORLD:OpenSim
  12. // :DESCRIPTION:
  13. // NPC console controller
  14. // Accepts button input from 8 buttons in a compass rose configuration
  15. // Controls a pait of NPCS to xap 6 other NPCs.
  16. // :CODE:
  17. //vector osNpcGetPos(key id) { return <128,128,20>; }
  18. // TUNABLES
  19. integer debug = 0;
  20. integer CommandChannel = 23;
  21. integer BUSY;
  22. string errorbeep = "back-in-time";
  23. string footsteps = "footstepmuffled";
  24. string click = "coins_bag_2_3";
  25. string sex="Sex";
  26. string effect="magic-string-spell-2";
  27. integer gFireworksChannel =20;
  28. integer STATE = 0;
  29. float LASTDIST = 1;
  30. integer counter = 0;
  31. list FarAway = ["She is too far away","Move her closer to the dancers", "Move her near the dancers and press the center button.","What button did you just push?","Is she stuck?", "I hope this is working"];
  32. integer counter1 = 0;
  33. list Instructions = ["She is moving","Move her next to the dancers", "Try the center button.","Try the other direction","I think you have to get near a dancer", "Move her close to the dancers and press the center button", "Keep going", " This looks good"];
  34. float MAXDIST = 15;
  35. float MaxBeam = 3.0; // how far the helmet beam happens
  36. vector centerPoint = <213.89366, 129.07689, 39.56485>;
  37. // first three are root, namaka, and dylan
  38. list avatarDancePos= [ZERO_VECTOR,ZERO_VECTOR,ZERO_VECTOR,ZERO_VECTOR,ZERO_VECTOR,ZERO_VECTOR,ZERO_VECTOR,ZERO_VECTOR,ZERO_VECTOR,ZERO_VECTOR];
  39. list avatars;
  40. // Link Numbers of the NPC controller
  41. integer namaka =2;
  42. integer dylan =3;
  43. integer npc1 =4;
  44. integer npc2 =5;
  45. integer npc3 =6;
  46. integer npc4 =7;
  47. integer npc5 =8;
  48. integer npc6 =9; // MaryAnne
  49. // GLOBALS
  50. integer busy ;
  51. key NamakaKey;
  52. key DylanKey ;
  53. // npc counters
  54. integer FIRST = 0;
  55. integer LAST = 6;
  56. integer currNpcNum;
  57. // FUNCTIONS
  58. DEBUG(string msg)
  59. {
  60. if (debug ==1 || debug ==3)
  61. llOwnerSay(llGetScriptName() + ":" + msg);
  62. if (debug ==2 || debug ==3) {
  63. llSetText(msg, <1,0,0>,1.0);
  64. llSleep(0.25);
  65. }
  66. }
  67. string NpcSayInstructions()
  68. {
  69. if (counter1 ++ >= llGetListLength(Instructions))
  70. counter1 = 0;
  71. return llList2String(Instructions,counter1);
  72. }
  73. string NpcSayTooFar()
  74. {
  75. if (counter++ >= llGetListLength(FarAway))
  76. counter = 0;
  77. return llList2String(FarAway,counter);
  78. }
  79. Command(integer Npc,string msg)
  80. {
  81. //DEBUG("Command:" +(string) Npc +":" + msg);
  82. llMessageLinked(Npc,0,msg,"");
  83. }
  84. ChangeNpcToDemon(integer npc)
  85. {
  86. DEBUG("Change to demon " + (string) npc);
  87. llMessageLinked(npc,100,"BOOM",""); // tell the effect to play
  88. llMessageLinked(LINK_SET,200,"BANG",""); // tell the spiral effect to play
  89. Command(npc,"@notecard=!Changed");
  90. }
  91. Win()
  92. {
  93. DEBUG("Win");
  94. llRegionSay(gFireworksChannel,"Go");
  95. STATE=1;
  96. DEBUG("FIREWORKS");
  97. llSetTimerEvent(1);
  98. }
  99. InitAllNpc()
  100. {
  101. DEBUG("Init all Npc");
  102. currNpcNum = FIRST;
  103. llMessageLinked(LINK_SET,99,"reset","");
  104. busy = FALSE;
  105. STATE = 0;
  106. avatars = [0,0,0,0,1,1,1,1,1,1]; // 0 is skipped, 1 = root, 2 - namaka
  107. llShout(CommandChannel,"0006");
  108. BUSY = FALSE;
  109. }
  110. default
  111. {
  112. state_entry()
  113. {
  114. DEBUG("Reset");
  115. busy = FALSE;
  116. llSetText("",<1,1,1>,1.0);
  117. InitAllNpc();
  118. }
  119. timer()
  120. {
  121. llShout(CommandChannel,(string) (180 - STATE));
  122. llSetTimerEvent(1);
  123. if (STATE == 15 || STATE== 20 || STATE == 25) {
  124. llRegionSay(gFireworksChannel,"Go");
  125. }
  126. if (STATE==30)
  127. {
  128. Command(namaka,"@notecard=dragon");
  129. Command(dylan,"@notecard=dragon");
  130. }
  131. if (STATE == 180)
  132. {
  133. InitAllNpc();
  134. llSetTimerEvent(0);
  135. }
  136. STATE++;
  137. }
  138. link_message(integer sender_number, integer number, string message, key id)
  139. {
  140. if (BUSY)
  141. return;
  142. // DEBUG("Num:" + (string) number + " str:" + message);
  143. // --10 is the link num and pos of the dancer
  144. // -2 is dylans key
  145. // -1 is Namakas key
  146. // 4 is for NPC direction commands
  147. // 1 is for doorway
  148. // 2 is the helmet beam channel
  149. if (number == -10) {
  150. list x = llParseString2List(message,["|"],[]);
  151. integer linknum = (integer) llList2String( x,0);
  152. vector v = (vector) llList2String( x,1);
  153. avatarDancePos = llListReplaceList(avatarDancePos,[v],linknum,linknum);
  154. //DEBUG("Npc Count = " + (string) llGetListLength(avatarDancePos));
  155. }
  156. else if (number == -2){ // -2 is Dylans key fromt the modified NPC controller script
  157. DylanKey = id;
  158. //DEBUG("Dylan Key set to " + (string) id);
  159. } else if (number == -1){ // -1 is Namakas key
  160. NamakaKey = id;
  161. //DEBUG("Namaka Key set to " + (string) id);
  162. } else if (number == 4){ // 4 is for NPC direction commands
  163. llMessageLinked(LINK_SET,0," ",""); // stimulate back a NPC key message
  164. vector direction = (vector) message;
  165. direction *= 2.5;
  166. DEBUG((string) direction);
  167. llTriggerSound(click,1.0);
  168. //DEBUG("Key: " + (string) NamakaKey);
  169. list stuff = llGetObjectDetails(NamakaKey, [OBJECT_POS]);
  170. vector namakaPos = llList2Vector(stuff,0);
  171. //vector namakaPos = osNpcGetPos(NamakaKey);
  172. // DEBUG("NPC at " + (string) namakaPos);
  173. vector newNpcPos = namakaPos;
  174. newNpcPos.z = 0;
  175. centerPoint.z = 0;
  176. //DEBUG("Roam dist:" + (string) llVecDist(newNpcPos, centerPoint));
  177. llTriggerSound(footsteps,1.0);
  178. // Move the npc some direction
  179. if (llVecDist(newNpcPos, centerPoint) > MAXDIST) {
  180. DEBUG("Went too far");
  181. llTriggerSound(errorbeep,1.0);
  182. string toSay = NpcSayTooFar();
  183. Command(dylan,"@animate=avatar_type|3");
  184. Command(dylan,"@say=" + toSay);
  185. // string newPos2 = (string) (namakaPos + (direction *-2));
  186. // DEBUG("Reversing to @walk=" + newPos2);
  187. Command(namaka,"@teleport=<207, 126, 41>" );
  188. Command(dylan,"@teleport=<198.4, 130, 41.5>" );
  189. return;
  190. }
  191. string newPos = (string) (namakaPos + direction + <0,0,0.2>);
  192. //DEBUG("Moving to @walk=" + newPos);
  193. Command(namaka,"@walk=" + newPos);
  194. } else if (number == 1) { // 1 is for doorway
  195. if (busy) {
  196. DEBUG("Busy");
  197. return;
  198. }
  199. InitAllNpc();
  200. busy++;
  201. } else if (number == 2){ // 2 is the helmet beam channel
  202. DEBUG(llDumpList2String(avatars,":"));
  203. llTriggerSound(effect,1.0);
  204. llMessageLinked(LINK_SET,0," ",""); // stimulate back a NPC key message
  205. LASTDIST = 99;
  206. integer i;
  207. integer j = llGetListLength(avatarDancePos);
  208. for (i = 0; i < j; i++)
  209. {
  210. if (llList2Integer(avatars,i) != 0)
  211. {
  212. //DEBUG("I:" + (string) i);
  213. // get Namakas position and compare it to all the npcs
  214. vector npcPos = llList2Vector(avatarDancePos,i);
  215. npcPos.z = 0;
  216. list stuff = llGetObjectDetails(NamakaKey, [OBJECT_POS]);
  217. vector namakaPos = llList2Vector(stuff,0);
  218. if (namakaPos == ZERO_VECTOR)
  219. {
  220. DEBUG("Oops");
  221. return;
  222. }
  223. namakaPos.z = 0;
  224. //DEBUG("namakaPos:" + (string) namakaPos);
  225. //DEBUG("npcPos:" + (string) npcPos);
  226. float dist = llVecDist(npcPos,namakaPos);
  227. //DEBUG("dist:" + (string) dist);
  228. if (dist < LASTDIST)
  229. {
  230. LASTDIST = dist;
  231. }
  232. if (dist < MaxBeam)
  233. {
  234. llSetText("Distance\n" + (string) dist,<0,1,0>,1.0);
  235. Command(dylan,"@say=Something is happening!" );
  236. ChangeNpcToDemon(i); //1 = root, 2 = namake, 3 = dylan
  237. avatars= llListReplaceList(avatars,[0],i,i);
  238. integer k;
  239. integer l = llGetListLength(avatars);
  240. integer count;
  241. for (k=0; k < l; k++)
  242. {
  243. count += llList2Integer(avatars,k);
  244. }
  245. DEBUG("count:" + (string) count);
  246. llShout(CommandChannel,(string) count);
  247. if (count <2) {
  248. llTriggerSound(sex,1.0);
  249. Win();
  250. BUSY++;
  251. return;
  252. }
  253. llTriggerSound(effect,1.0);
  254. return;
  255. }
  256. }
  257. }
  258. llSetText("Distance\n" + (string) LASTDIST,<0,1,0>,1.0);
  259. string toSay2 = NpcSayInstructions();
  260. Command(dylan,"@animate=avatar_type|3");
  261. Command(dylan,"@say=" + toSay2);
  262. integer d = (integer) LASTDIST;
  263. Command(dylan,"@say=The closest dancer is about " + d + " meters away from her");
  264. }
  265. }
  266. }