HUd.lsl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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:516
  8. // :REV:1
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // the HUD
  12. // :CODE:
  13. ///Putting it together:
  14. //put the Giant Hammer script in a hammer shaped object, maybe adjust params depending on hammer size, centre of rotation etc.
  15. //put the Hammer in the Bullet object (any prim will do, but I use a tiny invisible one!) and add the Bullet script
  16. //put the Bullet (now containing the Hammer) in the HUD object
  17. // When you wear the HUD it will tell you what to do.
  18. // Project: Hammer thrower
  19. // Script: Hammer launcher
  20. // Get avatar name, or target all.
  21. // Rez objects giving them target avatar name
  22. // add channel command
  23. //Simple OpenSource Licence (I am trusting you to be nice)
  24. //1. PLEASE SEND ME UPDATES TO THE CODE
  25. //2. You can do what you want with this code and object including selling it in other objects and so on.
  26. //You can sell it in closed source objects if you must, but please try to send any updates or
  27. //improvements back to me for possible inclusion in the main trunk of development.
  28. //3. You must always leave these instructions in any object created; notecard written; posting to
  29. //any electronic medium such as Forum, Email &c. of the source code & generally be nice (as
  30. //already requested!)
  31. //4. You must not claim that anyone apart from sparti Carroll wrote the original version of this software.
  32. //5. You can add and edit things below =THE LINE= but please try to keep it all making sense.
  33. //Thank you for your co-operation
  34. //sparti Carroll
  35. key k_owner;
  36. integer channel_bullet = 540123;
  37. integer channel_hammer = 477591;
  38. integer channel_owner = 324;
  39. integer channel_count = 1;
  40. string lookingfor;
  41. integer HUDcenter2 = 31;
  42. integer HUDtopright = 32;
  43. integer HUDtop = 33;
  44. integer HUDtopleft = 34;
  45. integer HUDcenter = 35;
  46. integer HUDbottomleft = 36;
  47. integer HUDbottom = 37;
  48. integer HUDbottomright = 38;
  49. integer HUD_default = HUDtopleft;
  50. set_hudpos(integer whereami) {
  51. vector my_size = llGetScale();
  52. vector v_atpos;
  53. if (whereami == HUDbottomleft) v_atpos = <0,-my_size.y/2,my_size.z/2>;
  54. else if (whereami == HUDtopleft) v_atpos = <0,-my_size.y/2,-my_size.z/2>;
  55. else if (whereami == HUDbottom || whereami == HUDbottomright) v_atpos = <0,0,my_size.z/2>;
  56. else if (whereami == HUDtop || whereami == HUDtopright) v_atpos = <0,0,-my_size.z/2>;
  57. else if (whereami == HUDcenter || whereami == HUDcenter2) v_atpos = <0,0,0>;
  58. llSetPos(v_atpos);
  59. }
  60. reset() {
  61. k_owner = llGetOwner();
  62. llOwnerSay("Activated on channel " + (string)channel_owner);
  63. integer whereami = llGetAttached();
  64. if (whereami == 0) {
  65. llOwnerSay("Please wear on the HUD");
  66. } else {
  67. set_hudpos(whereami);
  68. }
  69. llListen(channel_owner,"",k_owner,"");
  70. }
  71. attack(string avname) {
  72. llRezObject("Bullet",llGetPos() + <0,0,5>,<0,0,0>,<0,0,0,0>,channel_count);
  73. llSleep(.5); // needs time to rez an object and establish a listener
  74. llSay(channel_bullet + channel_count,"attack^" + avname);
  75. channel_count++;
  76. llOwnerSay("Now hammering " + avname);
  77. }
  78. default
  79. {
  80. on_rez(integer start_param) {
  81. reset();
  82. }
  83. state_entry() {
  84. reset();
  85. }
  86. listen(integer channel,string name,key id,string message) {
  87. if (id == k_owner) {
  88. lookingfor = llToLower(message);
  89. llSensor("",NULL_KEY,AGENT,100,PI);
  90. }
  91. }
  92. sensor(integer num_detected) {
  93. integer k;
  94. //nteger foundpos;
  95. for (k=0;k < num_detected; k++)
  96. {
  97. string name = llKey2Name(llDetectedKey(k)) ;
  98. if (name == lookingfor)
  99. {
  100. attack(name);
  101. }
  102. }
  103. }
  104. no_sensor() {
  105. llOwnerSay("No matching AV names");
  106. }
  107. attach(key id) {
  108. integer whereami = llGetAttached();
  109. set_hudpos(whereami);
  110. }
  111. }