big hammer.lsl 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // :CATEGORY:Weapon
  2. // :NAME:HammerThrower
  3. // :AUTHOR:Anonymous
  4. // :CREATED:2013-09-06
  5. // :EDITED:2013-09-18 15:38:54
  6. // :ID:372
  7. // :NUM:515
  8. // :REV:1
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // a hammer to toss on people
  12. // :CODE:
  13. // Script: The hammer
  14. // die() after 10mins
  15. // chase avatar around bashing them
  16. // non physical object, but use damage if they collide
  17. // particle system of little hammers/anvils/sparks/lightning?
  18. //Simple OpenSource Licence (I am trusting you to be nice)
  19. //1. PLEASE SEND ME UPDATES TO THE CODE
  20. //2. You can do what you want with this code and object including selling it in other objects and so on.
  21. //You can sell it in closed source objects if you must, but please try to send any updates or
  22. //improvements back to me for possible inclusion in the main trunk of development.
  23. //3. You must always leave these instructions in any object created; notecard written; posting to
  24. //any electronic medium such as Forum, Email &c. of the source code & generally be nice (as
  25. //already requested!)
  26. //4. You must not claim that anyone apart from sparti Carroll wrote the original version of this software.
  27. //5. You can add and edit things below =THE LINE= but please try to keep it all making sense.
  28. //Thank you for your co-operation
  29. //sparti Carroll
  30. integer FLAGdebug = FALSE;
  31. integer channel_bullet = 540123;
  32. integer channel_hammer = 477591;
  33. // working
  34. key hammer_avkey;
  35. vector hammer_avpos; // current position of AV being attacked
  36. string hammer_targetting; // name of AV being attacked
  37. integer hammer_attacks; // how many attacks left
  38. // configuration
  39. integer hammer_new_attacks_on_touch = 3;
  40. float hammer_attack_timeout = 120.0; // how long before die if in attack mode
  41. // how long before start attack again in resting mode
  42. float hammer_resting_timeout_min = 15.0; // minimum
  43. float hammer_resting_timeout_range = 50.0; // range
  44. set_position(vector targetpos) {
  45. // fly to position
  46. while (llVecDist(llGetPos(),targetpos) > 0.001)
  47. llSetPos(targetpos);
  48. }
  49. // can have several of these
  50. animate_bash() {
  51. //spin around to an arbitrary attack angle
  52. //bash the av a random number of times
  53. //do particle effects
  54. //go to rest position
  55. //set orientation
  56. if (FLAGdebug)
  57. llOwnerSay("attack starts");
  58. llSetPrimitiveParams([PRIM_PHYSICS,FALSE]);
  59. vector v_random_rot = <0,0,llFrand(360)> * DEG_TO_RAD;
  60. rotation random_rot = llEuler2Rot(v_random_rot);
  61. vector anim_blow_ready = <0,9,0> * random_rot;
  62. anim_blow_ready += <0,0,9>;
  63. vector nowpos = hammer_avpos + anim_blow_ready;
  64. set_position(nowpos);
  65. vector v_base_rotation = <45,0,0> * DEG_TO_RAD;
  66. vector v_swipe_down_rotation = <135,0,0> * DEG_TO_RAD;
  67. vector v_finish_rotation= <95,llFrand(90),llFrand(90)> * DEG_TO_RAD;
  68. rotation hammer_base_rotation = llEuler2Rot(v_base_rotation);
  69. rotation hammer_swipe_down_rotation = llEuler2Rot(v_swipe_down_rotation);
  70. rotation hammer_finish_rotation = llEuler2Rot(v_finish_rotation);
  71. hammer_base_rotation *= random_rot;
  72. hammer_swipe_down_rotation *= random_rot;
  73. hammer_finish_rotation *= random_rot;
  74. llSetRot(hammer_base_rotation);
  75. llSleep(1.0);
  76. // pound on AV!
  77. integer c_swipe;
  78. float swipes_random = 10.0;
  79. float swipes_base = 4.0;
  80. integer num_swipes = (integer)(llFrand(swipes_random) + swipes_base);
  81. for (c_swipe=0;c_swipe < num_swipes; c_swipe++)
  82. {
  83. llSleep(0.5);
  84. llSetRot(hammer_swipe_down_rotation);
  85. llSleep(0.5);
  86. llSetRot(hammer_finish_rotation);
  87. llSleep(0.5);
  88. llSetRot(hammer_base_rotation);
  89. }
  90. }
  91. animate_resting() {
  92. llSetPrimitiveParams([PRIM_PHYSICS,TRUE]);
  93. }
  94. reset() {
  95. hammer_attacks = (integer)(llFrand(10.0) + 5.0);
  96. llSetTimerEvent(120.0); // time to init
  97. }
  98. default {
  99. on_rez(integer start_param) {
  100. llListen(channel_hammer,"","","");
  101. reset();
  102. llSetPrimitiveParams([PRIM_PHYSICS,TRUE]);
  103. }
  104. state_entry() {
  105. if (FLAGdebug) llOwnerSay("Starting up");
  106. reset();
  107. }
  108. listen(integer channel,string name,key id, string message) {
  109. list cmdline = llParseString2List(message,["^"],[]);
  110. string cmd = llList2String(cmdline,0);
  111. string par = llList2String(cmdline,1);
  112. if (cmd == "attack") {
  113. hammer_targetting = par;
  114. state attack;
  115. } else if (cmd == "die") {
  116. llDie();
  117. }
  118. }
  119. touch_start(integer num_detected) {
  120. key k_touch = llDetectedKey(0);
  121. if (k_touch == hammer_avkey) {
  122. //start attack now and add some more attacks
  123. hammer_attacks += (integer)llFrand(hammer_new_attacks_on_touch);
  124. state attack;
  125. } else {
  126. string name = llKey2Name(k_touch);
  127. float dowhat = llFrand(3.0);
  128. if (dowhat < 2.0) {
  129. llSay(0,"I have not come for you " + name + " so don't tempt me!");
  130. } else {
  131. llSay(0,"I had not come for you " + name);
  132. llSleep(3.0);
  133. llSay(0,"But I have changed my mind !!!");
  134. hammer_targetting = name;
  135. state attack;
  136. }
  137. }
  138. }
  139. timer() {
  140. // failed to init
  141. llOwnerSay("failed to initialise hammer: llDie");
  142. }
  143. }
  144. state attack {
  145. on_rez(integer start_param) {
  146. // should not rez in this state
  147. llDie();
  148. }
  149. state_entry() {
  150. // find them (again) and attack
  151. // turn off phys
  152. hammer_attacks--;
  153. llSensor(hammer_targetting,NULL_KEY,AGENT,300,PI);
  154. llSetTimerEvent(hammer_attack_timeout);
  155. }
  156. no_sensor() {
  157. // fly around looking for them
  158. // die if not found after N seconds
  159. }
  160. sensor(integer num_detected) {
  161. hammer_avkey = llDetectedKey(0);
  162. hammer_avpos = llDetectedPos(0);
  163. animate_bash();
  164. // finshed attacking ?
  165. if (hammer_attacks <= 0) {
  166. llDie();
  167. } else {
  168. state resting;
  169. }
  170. }
  171. touch_start(integer num_detected) {
  172. // advertise ?
  173. }
  174. timer() {
  175. llDie();
  176. }
  177. }
  178. state resting {
  179. // wait before attacking av again
  180. on_rez(integer start_param) {
  181. // should not be rezzed in this state
  182. llDie();
  183. }
  184. state_entry() {
  185. animate_resting();
  186. llSetTimerEvent(hammer_resting_timeout_min + llFrand(hammer_resting_timeout_range));
  187. }
  188. touch_start(integer num_detected) {
  189. key k_touch = llDetectedKey(0);
  190. if (k_touch == hammer_avkey) {
  191. //start attack now and add some more attacks
  192. hammer_attacks += (integer)llFrand(hammer_new_attacks_on_touch);
  193. state attack;
  194. } else {
  195. string name = llKey2Name(k_touch);
  196. float dowhat = llFrand(3.0);
  197. if (dowhat < 2.0) {
  198. llSay(0,"I have not come for you " + name + " so don't tempt me!");
  199. } else {
  200. llSay(0,"I had not come foo you " + name);
  201. llSleep(3.0);
  202. llSay(0,"But I have changed my mind !!!");
  203. hammer_targetting = name;
  204. state attack;
  205. }
  206. }
  207. }
  208. timer() {
  209. state attack;
  210. }
  211. }