zombie_move.lslp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * Part of the Sloodle project (www.sloodle.org)
  3. *
  4. * Copyright (c) 2011-06 contributors (see below)
  5. * Released under the GNU GPL v3
  6. * -------------------------------------------
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * All scripts must maintain this copyrite information, including the contributer information listed
  22. *
  23. * Contributors:
  24. * Paul Preibisch
  25. *
  26. * DESCRIPTION
  27. * Contributors:
  28. * Edmund Edgar
  29. * Paul Preibisch
  30. *
  31. * SND_JELLY_APPROACH - was mashed up from: http://www.freesound.org/people/suonho/ under the sampling license: http://creativecommons.org/licenses/sampling+/1.0/
  32. */
  33. // bending fish
  34. // 2007 Copyright by Shine Renoir (fb@frank-buss.de)
  35. //
  36. // The center position is stored on rez.
  37. // maximum swim radius from last center
  38. float radius = 6.0;
  39. // maximum swim distance for swimming up or down from last center
  40. float height = 1.0;
  41. // delay in seconds for next movement
  42. float delay = 3.0;
  43. list colors;
  44. // internal channel for communication
  45. integer CHANNEL = -87;
  46. integer MAX=30;
  47. // last center position
  48. vector center;
  49. integer target_id;
  50. list screams;
  51. float randBetween(float min, float max)
  52. {
  53. return llFrand(max - min) + min;
  54. }
  55. blood(key av){
  56. llMessageLinked(LINK_SET, BLOOD, "", av);
  57. }
  58. noblood(){
  59. llMessageLinked(LINK_SET, NOBLOOD, "", NULL_KEY);
  60. }
  61. integer BLOOD=-999922110;
  62. integer NOBLOOD=-999922111;
  63. init()
  64. {
  65. llSetPrimitiveParams([ PRIM_PHYSICS, TRUE]);
  66. llSetStatus(STATUS_ROTATE_X, FALSE);
  67. llSetStatus(STATUS_ROTATE_Y, FALSE);
  68. float t = llSqrt(2.0) / 2.0;
  69. llSetRot(<0, 0, 0, 0>);
  70. llSetBuoyancy(0.9);
  71. llSetTimerEvent(delay);
  72. }
  73. integer counter =0;
  74. vector deathTarget;
  75. key deathKey;
  76. integer attackTimes=0;
  77. integer screamCounter=0;
  78. vector RED =<1.00000, 0.00000, 0.00000>;
  79. vector ORANGE=<1.00000, 0.43763, 0.02414>;
  80. vector YELLOW=<1.00000, 1.00000, 0.00000>;
  81. vector GREEN=<0.00000, 1.00000, 0.00000>;
  82. vector BLUE=<0.00000, 0.00000, 1.00000>;
  83. vector BABYBLUE=<0.00000, 1.00000, 1.00000>;
  84. vector PINK=<1.00000, 0.00000, 1.00000>;
  85. vector PURPLE=<0.57338, 0.25486, 1.00000>;
  86. vector BLACK= <0.00000, 0.00000, 0.00000>;
  87. vector WHITE= <1.00000, 1.00000, 1.00000>;
  88. vector AVCLASSBLUE= <0.06274,0.247058,0.35294>;
  89. vector AVCLASSLIGHTBLUG=<0.8549,0.9372,0.9686>;//#daeff7
  90. vector getColor(){
  91. list colors=[RED,ORANGE,YELLOW,BLUE,BABYBLUE,PINK,PURPLE];
  92. colors = llListRandomize(colors, 1);
  93. return llList2Vector(colors,0);
  94. }
  95. //returns a random scream sound
  96. string getScream(){
  97. screams = ["scream1","scream2","scream3","scream4"];
  98. integer screamLen = llGetListLength(screams);
  99. screamCounter++;
  100. if (screamCounter>screamLen-1){
  101. screamCounter=0;
  102. }
  103. return llList2String(screams,screamCounter);
  104. }
  105. string getApproachSound(){
  106. screams = ["SND_SNARL","SND_GROWL","SND_ZOMBIE_SQUEEL","SND_ZOMBIE_CAT"];
  107. integer screamLen = llGetListLength(screams);
  108. screamCounter++;
  109. if (screamCounter>screamLen-1){
  110. screamCounter=0;
  111. }
  112. return llList2String(screams,screamCounter);
  113. }
  114. default{
  115. state_entry(){
  116. llSetPrimitiveParams([ PRIM_PHYSICS, FALSE]);
  117. noblood();
  118. counter=0;
  119. llSetTimerEvent(3);
  120. }
  121. on_rez(integer start_param) {
  122. llResetScript();
  123. }
  124. timer() {
  125. state myPos;
  126. }
  127. }
  128. state myPos{
  129. state_entry() {
  130. center = llGetPos();
  131. state ready;
  132. }
  133. on_rez(integer start_param) {
  134. llResetScript();
  135. }
  136. }
  137. state before_ready{
  138. state_entry() {
  139. state ready;
  140. }
  141. }
  142. state ready{
  143. on_rez(integer start_param) {
  144. llResetScript();
  145. }
  146. state_entry() {
  147. llSetStatus(STATUS_ROTATE_X,FALSE);
  148. llSetStatus(STATUS_ROTATE_Y,FALSE);
  149. llParticleSystem([]);
  150. noblood();
  151. deathKey=NULL_KEY;
  152. deathTarget = ZERO_VECTOR;
  153. llSetText("", <0,0,1>, 1);
  154. llSensorRepeat("", "", AGENT, 5, PI,5);
  155. init();
  156. llMoveToTarget(center, 1);
  157. }
  158. sensor(integer num_detected) {
  159. deathTarget = llDetectedPos(0);
  160. deathKey = llDetectedKey(0);
  161. vector pos = llGetPos();
  162. vector delta = pos - deathTarget;
  163. float angle = llAtan2(delta.y, delta.x) + PI / 2.0;
  164. rotation rot = llEuler2Rot(<0, 0, angle>);
  165. //llRotLookAt(rot, 1.0, 1.0);
  166. state attack;
  167. }
  168. link_message(integer sender_num, integer num, string str, key id) {
  169. if (num==-99){
  170. if (str=="DEAD"){
  171. llSleep(10);
  172. llSetTimerEvent(0);
  173. state before_ready;
  174. }
  175. }
  176. }
  177. timer()
  178. {
  179. // get current position
  180. vector pos = llGetPos();
  181. // calculate random next position
  182. vector dest = pos;
  183. dest.x += randBetween(-radius, radius);
  184. dest.y += randBetween(-radius, radius);
  185. // dest.z += randBetween(-radius, height);
  186. // move to center, if outside radius
  187. integer i;
  188. for (i = 0; i < 3; i++) {
  189. if (llVecMag(dest - center) > radius) {
  190. dest = (dest - pos) / 2.0 + pos;
  191. }
  192. }
  193. // fallback: if other objects pushes the fish, move back to center
  194. if (llVecMag(dest - center) > radius) {
  195. dest = center;
  196. }
  197. // calculate new rotation and move to target
  198. vector delta = pos - dest;
  199. float angle = llAtan2(delta.y, delta.x) + PI / 2.0;
  200. rotation rot = llEuler2Rot(<0, 0, angle>);
  201. // llRotLookAt(rot, 1.0, 1.0);
  202. llMoveToTarget(dest, 2);
  203. }
  204. }
  205. state attack{
  206. on_rez(integer start_param) {
  207. llResetScript();
  208. }
  209. state_entry() {
  210. attackTimes = 0;
  211. target_id = llTarget(deathTarget, 0.5);
  212. llTriggerSound(getApproachSound(), 1);
  213. llMoveToTarget(deathTarget, 0.1);
  214. llSensorRepeat("", "", AGENT, 10, PI,1);
  215. llSetTimerEvent(10);
  216. }
  217. sensor(integer num_detected) {
  218. deathTarget =llDetectedPos(0);
  219. deathKey = llDetectedKey(0);
  220. target_id = llTarget(deathTarget, 0.5);
  221. vector pos = llGetPos();
  222. vector delta = pos - deathTarget;
  223. float angle = llAtan2(delta.y, delta.x) + PI / 2.0;
  224. rotation rot = llEuler2Rot(<0, 0, angle>);
  225. // llRotLookAt(rot, 1.0, 1.0);
  226. llLookAt( deathTarget + <0.0, 0.0, 1.0>, 3.0, 1.0 );
  227. llMoveToTarget(deathTarget, 0.5);
  228. }
  229. link_message(integer sender_num, integer num, string str, key id) {
  230. if (num==-99){
  231. if (str=="DEAD"){
  232. llSleep(10);
  233. llSetTimerEvent(0);
  234. state ready;
  235. }
  236. }
  237. }
  238. timer() {
  239. llSetTimerEvent(0);
  240. integer i;
  241. // get current position
  242. vector pos = llGetPos();
  243. // calculate random next position
  244. vector dest = pos;
  245. for (i = 0; i < 3; i++) {
  246. if (llVecMag(dest - center) > radius) {
  247. dest = (dest - pos) / 2.0 + pos;
  248. }
  249. }
  250. // fallback: if other objects pushes the fish, move back to center
  251. if (llVecMag(dest - center) > radius) {
  252. dest = center;
  253. }
  254. // calculate new rotation and move to target
  255. vector delta = pos - dest;
  256. float angle = llAtan2(delta.y, delta.x) + PI / 2.0;
  257. rotation rot = llEuler2Rot(<0, 0, angle>);
  258. // llRotLookAt(rot, 1.0, 1.0);
  259. llMoveToTarget(dest, 2);
  260. state ready;
  261. }
  262. at_target(integer tnum, vector targetpos, vector ourpos)
  263. {
  264. if (tnum == target_id)
  265. {
  266. llTriggerSound(getScream(), 0.3);
  267. llTriggerSound(getApproachSound(), 0.5);
  268. attackTimes++;
  269. blood(deathKey);
  270. llPushObject(deathKey,<5,5,5>, <5,5,5>, TRUE);
  271. llTargetRemove(target_id);
  272. if (attackTimes>5) {
  273. attackTimes= 0;
  274. state ready;
  275. }
  276. }
  277. }
  278. }
  279. // Please leave the following line intact to show where the script lives in Git:
  280. // SLOODLE LSL Script Git Location: mod/interaction-1.0/objects/enemyrezzer/assets/zombie_move.lslp