Simple bullet rezzer.lsl 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // :CATEGORY:Helicopter
  2. // :NAME:Helicopter scripts
  3. // :AUTHOR:Anonymous
  4. // :CREATED:2013-09-06
  5. // :EDITED:2013-09-18 15:38:54
  6. // :ID:377
  7. // :NUM:524
  8. // :REV:1
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // bullet rezzer
  12. // :CODE:
  13. // simple cannon pointer script
  14. // just go into mouselook, it will point wherever you look
  15. // mouse button rezzes a bullet. Release the button to stop firing.
  16. // can only fire 10 rounds per second, max.
  17. // the bullet will be fired from center of the entire bullet or missile. To have the bullet rez from the center of the root prim,
  18. // change llRezObject to llRezAtRoot instead.
  19. integer debugon = FALSE; // set to TRUE for debug to owner only.
  20. vector ANGLE = <0,0,90> ; // used to point the gun 90 degrees rotated around the Z axis, this may need to be changed. It depends upon your prim and how the gun sticks out of it.
  21. string shoot = "shoot"; // the sound it makes when firing, must be in inventory. You can change this to:
  22. // key shoot = "12345000-0000-0000-0000-000000000001"; // where this is a copied UUID from your inventory and then there is no need to give away the sound file.
  23. // The avatar must be within 2 meters of the gun script, or it will not aim or fire
  24. // the original value was 20, which is horrible laggy in comparison as it must scan an area 4 * PI R squared larger ( 100 times more work), for no good reason!
  25. // But if it is made larger, you can shoot the gun from a greater distance
  26. float DISTANCE = 2; // Make this as small as possible to control lag
  27. float SPEED = 40.0; // how fast the bullet flies away, this is really fast! For a missile, set it to 0 and make the missile do its own acceleration
  28. // code bgins
  29. // general purpose Debug("some message");
  30. Debug( string msg)
  31. {
  32. if (debugon)
  33. llOwnerSay(msg);
  34. }
  35. default
  36. {
  37. state_entry()
  38. {
  39. // normally, this little bit of code is disabled by FALSE. It can be deleted entirely. But it is extremely handy!
  40. // This routine lets you change hard coded rotations to vectors so humans can work on them
  41. // It does not run unless you set this to TRUE
  42. // When it runs, it takes whatever crap quaternion has been copied from old code into a vector
  43. // It prints the vector in degrees
  44. // a crap quaternion looks like this, and has 4 numbers:
  45. // <0.00000, 0.00000, 0.70711, 0.70711> // bet you didn't know this is a rotation of 90 degrees around the Z axis!
  46. // sample output when set to TRUE:
  47. // original:<0.00000, 0.00000, 0.70711, 0.70711> This was the original, copied quaternion
  48. // replacement:<0.00000, 0.00000, 90.00000> aha, its a 90 degree rotation about Z
  49. // How to use it: Whenever you see a rotation hard-coded in like this, don't cuss at the programmer, they didn't know better.
  50. // llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>);
  51. // Paste the old crap rotation <..> in the arot line below, set the variable to TRUE, and then change the script to this line, where the <0,0,90> is whatever the script spits out:
  52. // llSetRot(llEuler2Rot(<0,0,90> * DEG_TO_RAD)); // change <0,0,90> to the vector form
  53. // much easier to change and the same as this unreadable crap:
  54. // llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>);
  55. // one last thing: <0.00000,0.0000, 0.00000, 1.0000> ( 0,0,0,1) is a ZERO rotation, or <0,0,0> as a vector. That's easy to remember so you can just change it to llSetRot(ZERO_VECTOR);
  56. // you can comment this all out, but there is really no need, it just saves a few bytes of memory if you comment it out
  57. if (FALSE) // set to TRUE to conver any 4-vector quaternion into a human readable 3-unit vector.
  58. {
  59. rotation arot = <0.00000, 0.00000, 0.70711, 0.70711>; // replace this with your crappy quaternion
  60. llOwnerSay("original:" + (string) arot);
  61. vector in_degrees = llRot2Euler(arot);
  62. in_degrees *= RAD_TO_DEG;
  63. llOwnerSay("replacement:" + (string) in_degrees); // output it as a vector in degrees instead of radians.
  64. }
  65. }
  66. touch_start(integer total_number)
  67. {
  68. integer i;
  69. // MUST scan over all people who touch, and only allow the owner to fire the weapon.
  70. // many people can click at the same time, how many is in total_number
  71. for (i = 0; i < total_number; i++)
  72. {
  73. // See if this person is the owner
  74. if (llDetectedKey(i) == llGetOwner())
  75. {
  76. llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
  77. Debug("Requesting Permissions");
  78. }
  79. }
  80. }
  81. touch_end(integer total_number)
  82. {
  83. integer i;
  84. for (i = 0; i < total_number; i++)
  85. {
  86. // See if this person is the owner
  87. if (llDetectedKey(i) == llGetOwner())
  88. {
  89. llReleaseControls();
  90. llSensorRemove();
  91. llSetRot(llEuler2Rot(ANGLE * DEG_TO_RAD));
  92. Debug("stopped firing");
  93. }
  94. }
  95. }
  96. sensor(integer sense)
  97. {
  98. rotation k = llDetectedRot(0);
  99. llRotLookAt(k, 0.1, 0.1);
  100. }
  101. // oh dear, the avatar is out of range
  102. no_sensor()
  103. {
  104. llReleaseControls();
  105. llSensorRemove();
  106. llSetRot(llEuler2Rot(ANGLE * DEG_TO_RAD)); // this is the same as the following line, but easily changed
  107. //llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>); // old crap code, actually <0.00000, 0.00000, 90.00000>
  108. Debug("No Owner nearby, check the DISTANCE variable");
  109. }
  110. run_time_permissions(integer perm)
  111. {
  112. if(perm & PERMISSION_TAKE_CONTROLS)
  113. {
  114. Debug("Permissions to take controls has been granted");
  115. llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
  116. llSensorRepeat("", llGetOwner(), AGENT, DISTANCE, TWO_PI, 0.1); // look for the owner only
  117. }
  118. }
  119. control(key name, integer levels, integer edges)
  120. {
  121. // mouse left button pressed
  122. if (levels & CONTROL_ML_LBUTTON)
  123. {
  124. rotation rot = llGetRot(); // mouselook rotation
  125. vector vel = llRot2Fwd(rot); // forward direction only
  126. vector pos = llGetPos(); // gun position
  127. pos = pos + vel; // add to gun position the forward direction
  128. pos.z += 0.0; // worthless by adding a 0, but by changing 0.0 to another number you can fire higher or lower than the prim this script is in.
  129. vel = vel * SPEED; // multiply all 3 coordinates by the constant SPEED to set a bullet speed.
  130. llTriggerSound(shoot, 1.0);
  131. llRezObject("bullet", pos, vel, rot, 1); // sends a 1 to the bullet, to the on_rez(integer start_param)
  132. }
  133. }
  134. }