Game prim script 5.5.lsl 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // :SHOW:1
  2. // :CATEGORY:Gaming
  3. // :NAME:Game Prim Script for5 Game sequence Web site.
  4. // :AUTHOR:Ferd Frederix
  5. // :KEYWORDS:Game, conteoller
  6. // :REV:5.5
  7. // :WORLD:OpenSim, Second life
  8. // :DESCRIPTION:
  9. // A chat system and controller based on a web site notecards replacement system
  10. // :CODE:
  11. // fred@mitsi.com
  12. // Game Prim script
  13. // v 5.5 NPC uses the server to send text to a NPC
  14. // LOGIN URL = http://www.outworldz.com/game
  15. string Version = "5.5"; // helps spot old scripts at the web site
  16. // fiddly bits
  17. integer debug = FALSE; // if TRUE, should be in Spanish
  18. // SET ONE OR MORE OF THESE
  19. integer COLLIDE = FALSE; // set to TRUE if you want them to collide with the prim
  20. integer TOUCH = TRUE; // set to TRUE if they can touch it to trigger this
  21. integer SIT = FALSE; // set to TRUE if this goes into a SEAT
  22. integer CollideObjects = FALSE; // set to TRUE to allow things to bump this prim (unlikely)
  23. integer SPEACHOPTION = 3; // Set to 0 for chat, 1 for IM
  24. vector OFFSET = <0,0,0>; // offset to rez items with channel = 2. <0,0,2> will rez the object 2 meters above the prim. Max = 10 meters.
  25. // not fiddly bits
  26. list stack; // place to store HTTP traffic
  27. integer HTTPSTRIDE = 2; // 3 items in a stack = 2 here as it starts option 0
  28. Ping(string AvatarName,key AvatarKey)
  29. {
  30. string Language = llEscapeURL(llGetAgentLanguage(AvatarKey));
  31. if (debug) llSay(0,"Language: " + Language);
  32. string Me = llEscapeURL(llGetObjectName());
  33. string Them = llEscapeURL(AvatarKey);
  34. string Theirname = llEscapeURL(AvatarName);
  35. string url = "http://www.outworldz.com/cgi/llgame.plx"
  36. + "?PrimName=" + (string) Me
  37. + "&Ver=" + Version
  38. + "&AvatarKey=" + (string)Them
  39. + "&Language=" + Language;
  40. if (AvatarKey != NULL_KEY)
  41. url += "&Avatar=" + (string)Theirname ;
  42. if (debug ) llOwnerSay(url);
  43. stack += AvatarKey;
  44. stack += Theirname;
  45. stack += llHTTPRequest(url, [], "");
  46. }
  47. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  48. // * The real start of the universe.
  49. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  50. default
  51. {
  52. state_entry()
  53. {
  54. llSetTimerEvent(1);
  55. if (COLLIDE == TRUE)
  56. {
  57. llSetAlpha(0,ALL_SIDES);
  58. llVolumeDetect(FALSE);
  59. llVolumeDetect(TRUE);
  60. }
  61. else {
  62. llVolumeDetect(FALSE);
  63. llSetAlpha(1,ALL_SIDES);
  64. }
  65. }
  66. timer()
  67. {
  68. llSetTimerEvent(3600); // hourly
  69. Ping("Ping", NULL_KEY);
  70. }
  71. // save the Web server data for this prim
  72. http_response(key request_id, integer status, list metadata, string body)
  73. {
  74. if (debug) llSay(0,"Response Body:" + body);
  75. integer where = llListFindList(stack, [request_id]) ;
  76. if (where > -1)
  77. {
  78. stack = llDeleteSubList(stack,where-HTTPSTRIDE,where); // key, name, request ID
  79. if (llGetListLength(stack) > 10 * HTTPSTRIDE ) // 10 at a time, the rest can go phooey
  80. stack = llDeleteSubList( stack, 0, HTTPSTRIDE ); // kill off 1st element, is old
  81. // $status|$display|$sound|$Channel|$ChannelText|$AvatarKey
  82. list my_detail = llParseString2List( body,["|"],[]);
  83. if (debug) llSay(0,"Dump:" + llDumpList2String(my_detail,","));
  84. string statusType = llList2String(my_detail,0);
  85. string storyText = llList2String(my_detail,1);
  86. string SoundUUID = llList2String(my_detail,2);
  87. integer ActionChannel = (integer) llList2String(my_detail,3);
  88. string ActionText = llList2String(my_detail,4);
  89. string AvatarKey = llList2String(my_detail,5);
  90. if (statusType == "ACK" && llStringLength(AvatarKey) > 1 )
  91. {
  92. // play sound, if any
  93. if (llStringLength(SoundUUID) > 1 ) {
  94. if (debug) llSay(0,"Playing sound " + SoundUUID);
  95. llTriggerSound(SoundUUID,1.0);
  96. }
  97. // They had the requirements, or there was no dependency, and there was text in the Channel
  98. if (ActionChannel && llStringLength(storyText) > 1)
  99. {
  100. if (debug) llSay(0,"Sending Region command " + storyText + " on channel " + (string) ActionChannel);
  101. llRegionSay(ActionChannel,storyText); // pass it to other scripts.
  102. }
  103. }
  104. }
  105. }
  106. collision_start(integer total_number)
  107. {
  108. if (COLLIDE) {
  109. if (debug)
  110. llSay(0," prim collided ");
  111. integer i;
  112. for (; i < total_number; i++)
  113. {
  114. if (debug) llSay(0,"Collided by " + (string) llDetectedKey(i));
  115. // if (! osIsNpc(llDetectedKey(i)))
  116. // {
  117. if (CollideObjects)
  118. {
  119. list reject = llGetObjectDetails(llDetectedKey(i), [OBJECT_CREATOR]);
  120. key x = llList2Key(reject,0);
  121. if (x == NULL_KEY)
  122. Ping(llDetectedName(i), llDetectedKey(i));
  123. } else {
  124. Ping(llDetectedName(i), llDetectedKey(i));
  125. }
  126. // }
  127. }
  128. }
  129. }
  130. touch_start(integer total_number)
  131. {
  132. if (TOUCH) {
  133. if (debug)
  134. llSay(0," prim touched ");
  135. integer i;
  136. for (; i < total_number; i++)
  137. {
  138. if (debug) llSay(0,"Touched by " + (string) llDetectedKey(i));
  139. Ping(llDetectedName(i), llDetectedKey(i));
  140. }
  141. }
  142. }
  143. changed(integer mask)
  144. {
  145. if (mask & CHANGED_INVENTORY)
  146. {
  147. llResetScript();
  148. }
  149. if ((mask & CHANGED_LINK) && SIT)
  150. {
  151. key avatarKey = llAvatarOnSitTarget(); // see if they sat down
  152. if (avatarKey != NULL_KEY)
  153. {
  154. Ping(llKey2Name(avatarKey), avatarKey);
  155. }
  156. }
  157. if (mask & CHANGED_REGION_START)
  158. {
  159. llResetScript();
  160. }
  161. }
  162. }