explosives.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. local he_boom = {
  2. name = "rangedweapons:he_explosion",
  3. --description = "DuN mInD mEh...",
  4. radius = 2,
  5. tiles = {
  6. side = "rangedweapons_invisible.png",
  7. top = "rangedweapons_invisible.png",
  8. bottom = "rangedweapons_invisible.png",
  9. burning = "rangedweapons_invisible.png"
  10. },
  11. }
  12. tnt.register_tnt(he_boom)
  13. local rocket_boom = {
  14. name = "rangedweapons:rocket_explosion",
  15. --description = "DuN mInD mEh...",
  16. radius = 3,
  17. tiles = {
  18. side = "rangedweapons_invisible.png",
  19. top = "rangedweapons_invisible.png",
  20. bottom = "rangedweapons_invisible.png",
  21. burning = "rangedweapons_invisible.png"
  22. },
  23. }
  24. tnt.register_tnt(rocket_boom)
  25. local rangedweapons_rocket = {
  26. physical = false,
  27. timer = 0,
  28. visual = "sprite",
  29. visual_size = {x=0.0, y=0.0},
  30. textures = {"rangedweapons_invisible.png"},
  31. lastpos= {},
  32. collisionbox = {0, 0, 0, 0, 0, 0},
  33. }
  34. rangedweapons_rocket.on_step = function(self, dtime, pos)
  35. self.timer = self.timer + dtime
  36. local tiem = 0.002
  37. local pos = self.object:getpos()
  38. local node = minetest.get_node(pos)
  39. if self.timer >= 0.002 then
  40. minetest.add_particle({
  41. pos = pos,
  42. velocity = 0,
  43. acceleration = {x=0, y=0, z=0},
  44. expirationtime = 0.04,
  45. size = 7,
  46. collisiondetection = false,
  47. vertical = false,
  48. texture = "rangedweapons_rocket_fly.png",
  49. glow = 15,
  50. })
  51. minetest.add_particle({
  52. pos = pos,
  53. velocity = 0,
  54. acceleration = {x=0, y=6, z=0},
  55. expirationtime = 0.4,
  56. size = 4,
  57. collisiondetection = false,
  58. vertical = false,
  59. texture = "tnt_smoke.png",
  60. glow = 5,
  61. })
  62. tiem = tiem + 0.002
  63. end
  64. if self.timer >= 0.375 then
  65. local objs = minetest.get_objects_inside_radius({x = pos.x, y = pos.y, z = pos.z}, 1.5)
  66. for k, obj in pairs(objs) do
  67. if obj:get_luaentity() ~= nil then
  68. if obj:get_luaentity().name ~= "rangedweapons:rocket" and obj:get_luaentity().name ~= "__builtin:item" then
  69. tnt.boom(pos, rocket_boom)
  70. self.object:remove()
  71. end
  72. end
  73. end
  74. end
  75. if self.lastpos.x ~= nil then
  76. if minetest.registered_nodes[node.name].walkable then
  77. tnt.boom(pos, rocket_boom)
  78. self.object:remove()
  79. end
  80. if self.timer >= 7.5 then
  81. tnt.boom(pos, rocket_boom)
  82. self.object:remove()
  83. end
  84. end
  85. self.lastpos= {x = pos.x, y = pos.y, z = pos.z}
  86. end
  87. minetest.register_entity("rangedweapons:rocket", rangedweapons_rocket)
  88. local rangedweapons_he_grenade = {
  89. physical = false,
  90. timer = 0,
  91. visual = "sprite",
  92. visual_size = {x=0.0, y=0.0},
  93. textures = {"rangedweapons_invisible.png"},
  94. lastpos= {},
  95. collisionbox = {0, 0, 0, 0, 0, 0},
  96. }
  97. rangedweapons_he_grenade.on_step = function(self, dtime, pos)
  98. self.timer = self.timer + dtime
  99. local tiem = 0.002
  100. local pos = self.object:getpos()
  101. local node = minetest.get_node(pos)
  102. if self.timer >= 0.002 then
  103. minetest.add_particle({
  104. pos = pos,
  105. velocity = 0,
  106. acceleration = {x=0, y=0, z=0},
  107. expirationtime = 0.04,
  108. size = 7,
  109. collisiondetection = false,
  110. vertical = false,
  111. texture = "rangedweapons_rocket_fly.png",
  112. glow = 15,
  113. })
  114. minetest.add_particle({
  115. pos = pos,
  116. velocity = 0,
  117. acceleration = {x=0, y=16, z=0},
  118. expirationtime = 0.4,
  119. size = 4,
  120. collisiondetection = false,
  121. vertical = false,
  122. texture = "tnt_smoke.png",
  123. glow = 5,
  124. })
  125. tiem = tiem + 0.002
  126. end
  127. if self.timer >= 0.4 then
  128. local objs = minetest.get_objects_inside_radius({x = pos.x, y = pos.y, z = pos.z}, 1.5)
  129. for k, obj in pairs(objs) do
  130. if obj:get_luaentity() ~= nil then
  131. if obj:get_luaentity().name ~= "rangedweapons:he_grenade" and obj:get_luaentity().name ~= "__builtin:item" then
  132. tnt.boom(pos, rocket_boom)
  133. self.object:remove()
  134. end
  135. end
  136. end
  137. end
  138. if self.lastpos.x ~= nil then
  139. if minetest.registered_nodes[node.name].walkable then
  140. tnt.boom(pos, he_boom)
  141. self.object:remove()
  142. end
  143. if self.timer >= 7.5 then
  144. tnt.boom(pos, he_boom)
  145. self.object:remove()
  146. end
  147. end
  148. self.lastpos= {x = pos.x, y = pos.y, z = pos.z}
  149. end
  150. minetest.register_entity("rangedweapons:he_grenade", rangedweapons_he_grenade)
  151. local barrel_boom = {
  152. name = "rangedweapons:explosion",
  153. --description = "DuN mInD mEh...",
  154. radius = 3,
  155. tiles = {
  156. side = "rangedweapons_invisible.png",
  157. top = "rangedweapons_invisible.png",
  158. bottom = "rangedweapons_invisible.png",
  159. burning = "rangedweapons_invisible.png"
  160. },
  161. }
  162. tnt.register_tnt(barrel_boom)
  163. minetest.register_node("rangedweapons:barrel", {
  164. description = "" ..core.colorize("#35cdff","Explosive barrel\n")..core.colorize("#FFFFFF", "It will explode if shot by gun"),
  165. tiles = {
  166. "rangedweapons_barrel_top.png",
  167. "rangedweapons_barrel_top.png",
  168. "rangedweapons_barrel_side.png",
  169. "rangedweapons_barrel_side.png",
  170. "rangedweapons_barrel_side.png",
  171. "rangedweapons_barrel_side.png"
  172. },
  173. drawtype = "nodebox",
  174. paramtype = "light",
  175. groups = {choppy = 3, oddly_breakable_by_hand = 3},
  176. on_blast = function(pos)
  177. tnt.boom(pos, {radius = 3})
  178. end,
  179. sounds = default.node_sound_wood_defaults(),
  180. node_box = {
  181. type = "fixed",
  182. fixed = {
  183. {-0.1875, -0.5, -0.5, 0.1875, 0.5, 0.5}, -- NodeBox1
  184. {-0.5, -0.5, -0.1875, 0.5, 0.5, 0.1875}, -- NodeBox2
  185. {-0.4375, -0.5, -0.3125, 0.4375, 0.5, 0.3125}, -- NodeBox3
  186. {-0.3125, -0.5, -0.4375, 0.3125, 0.5, 0.4375}, -- NodeBox4
  187. {-0.375, -0.5, -0.375, 0.375, 0.5, 0.375}, -- NodeBox5
  188. }
  189. }
  190. })