Guest User

Untitled

a guest
Jul 8th, 2012
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function spawn_tnt(pos, entname)
  2. minetest.sound_play("nuke_ignite", {pos = pos,gain = 1.0,max_hear_distance = 8,})
  3. return minetest.env:add_entity(pos, entname)
  4. end
  5.  
  6. function activate_if_tnt(nname, np, tnt_np, tntr)
  7. if nname == "experimental:tnt" or nname == "nuke:iron_tnt" or nname == "nuke:mese_tnt" or nname == "nuke:hardcore_iron_tnt" or nname == "nuke:hardcore_mese_tnt" then
  8. local e = spawn_tnt(np, nname)
  9. e:setvelocity({x=(np.x - tnt_np.x)*3+(tntr / 4), y=(np.y - tnt_np.y)*3+(tntr / 3), z=(np.z - tnt_np.z)*3+(tntr / 4)})
  10. end
  11. end
  12.  
  13. function do_tnt_physics(tnt_np,tntr)
  14. local objs = minetest.env:get_objects_inside_radius(tnt_np, tntr)
  15. for k, obj in pairs(objs) do
  16. local oname = obj:get_entity_name()
  17. local v = obj:getvelocity()
  18. local p = obj:getpos()
  19. if oname == "experimental:tnt" or oname == "nuke:iron_tnt" or oname == "nuke:mese_tnt" or oname == "nuke:hardcore_iron_tnt" or oname == "nuke:hardcore_mese_tnt" then
  20. obj:setvelocity({x=(p.x - tnt_np.x) + (tntr / 2) + v.x, y=(p.y - tnt_np.y) + tntr + v.y, z=(p.z - tnt_np.z) + (tntr / 2) + v.z})
  21. else
  22. if v ~= nil then
  23. obj:setvelocity({x=(p.x - tnt_np.x) + (tntr / 4) + v.x, y=(p.y - tnt_np.y) + (tntr / 2) + v.y, z=(p.z - tnt_np.z) + (tntr / 4) + v.z})
  24. else
  25. if obj:get_player_name() ~= nil then
  26. obj:set_hp(obj:get_hp() - 1)
  27. end
  28. end
  29. end
  30. end
  31. end
  32.  
  33. -- Iron TNT
  34.  
  35. minetest.register_craft({
  36. output = 'node "nuke:iron_tnt" 4',
  37. recipe = {
  38. {'','node "default:wood" 1',''},
  39. {'craft "default:steel_ingot" 1','craft "default:coal_lump" 1','craft "default:steel_ingot" 1'},
  40. {'','node "default:wood" 1',''}
  41. }
  42. })
  43. minetest.register_node("nuke:iron_tnt", {
  44. tile_images = {"nuke_iron_tnt_top.png", "nuke_iron_tnt_bottom.png",
  45. "nuke_iron_tnt_side.png", "nuke_iron_tnt_side.png",
  46. "nuke_iron_tnt_side.png", "nuke_iron_tnt_side.png"},
  47. inventory_image = minetest.inventorycube("nuke_iron_tnt_top.png",
  48. "nuke_iron_tnt_side.png", "nuke_iron_tnt_side.png"),
  49. dug_item = '', -- Get nothing
  50. material = {
  51. diggability = "not",
  52. },
  53. description = "Iron TNT",
  54. })
  55.  
  56. minetest.register_on_punchnode(function(p, node)
  57. if node.name == "nuke:iron_tnt" then
  58. minetest.env:remove_node(p)
  59. spawn_tnt(p, "nuke:iron_tnt")
  60. nodeupdate(p)
  61. end
  62. end)
  63.  
  64. local IRON_TNT_RANGE = 6
  65. local IRON_TNT = {
  66. -- Static definition
  67. physical = true, -- Collides with things
  68. -- weight = 5,
  69. collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
  70. visual = "cube",
  71. textures = {"nuke_iron_tnt_top.png", "nuke_iron_tnt_bottom.png",
  72. "nuke_iron_tnt_side.png", "nuke_iron_tnt_side.png",
  73. "nuke_iron_tnt_side.png", "nuke_iron_tnt_side.png"},
  74. -- Initial value for our timer
  75. timer = 0,
  76. -- Number of punches required to defuse
  77. health = 1,
  78. blinktimer = 0,
  79. blinkstatus = true,
  80. }
  81.  
  82. function IRON_TNT:on_activate(staticdata)
  83. self.object:setvelocity({x=0, y=4, z=0})
  84. self.object:setacceleration({x=0, y=-10, z=0})
  85. self.object:settexturemod("^[brighten")
  86. end
  87.  
  88. function IRON_TNT:on_step(dtime)
  89. self.timer = self.timer + dtime
  90. self.blinktimer = self.blinktimer + dtime
  91. if self.timer>5 then
  92. self.blinktimer = self.blinktimer + dtime
  93. if self.timer>8 then
  94. self.blinktimer = self.blinktimer + dtime
  95. self.blinktimer = self.blinktimer + dtime
  96. end
  97. end
  98. if self.blinktimer > 0.5 then
  99. self.blinktimer = self.blinktimer - 0.5
  100. if self.blinkstatus then
  101. self.object:settexturemod("")
  102. else
  103. self.object:settexturemod("^[brighten")
  104. end
  105. self.blinkstatus = not self.blinkstatus
  106. end
  107. if self.timer > 10 then
  108. local pos = self.object:getpos()
  109. pos.x = math.floor(pos.x+0.5)
  110. pos.y = math.floor(pos.y+0.5)
  111. pos.z = math.floor(pos.z+0.5)
  112. do_tnt_physics(pos, IRON_TNT_RANGE)
  113. minetest.sound_play("nuke_explode", {pos = pos,gain = 1.0,max_hear_distance = 16,})
  114. if minetest.env:get_node(pos).name == "default:water_source" or minetest.env:get_node(pos).name == "default:water_flowing" then
  115. -- Cancel the Explosion
  116. self.object:remove()
  117. return
  118. end
  119. for x=-IRON_TNT_RANGE,IRON_TNT_RANGE do
  120. for y=-IRON_TNT_RANGE,IRON_TNT_RANGE do
  121. for z=-IRON_TNT_RANGE,IRON_TNT_RANGE do
  122. if x*x+y*y+z*z <= IRON_TNT_RANGE * IRON_TNT_RANGE + IRON_TNT_RANGE then
  123. local np={x=pos.x+x,y=pos.y+y,z=pos.z+z}
  124. local n = minetest.env:get_node(np)
  125. if n.name ~= "air" then
  126. minetest.env:remove_node(np)
  127. end
  128. activate_if_tnt(n.name, np, pos, IRON_TNT_RANGE)
  129. end
  130. end
  131. end
  132. end
  133. self.object:remove()
  134. end
  135. end
  136.  
  137. function IRON_TNT:on_punch(hitter)
  138. self.health = self.health - 1
  139. if self.health <= 0 then
  140. self.object:remove()
  141. hitter:get_inventory():add_item("main", "nuke:iron_tnt")
  142. end
  143. end
  144.  
  145. minetest.register_entity("nuke:iron_tnt", IRON_TNT)
  146.  
  147. -- Mese TNT
  148.  
  149. minetest.register_craft({
  150. output = 'node "nuke:mese_tnt" 4',
  151. recipe = {
  152. {'','node "default:wood" 1',''},
  153. {'node "default:mese" 1','craft "default:coal_lump" 1','node "default:mese" 1'},
  154. {'','node "default:wood" 1',''}
  155. }
  156. })
  157. minetest.register_node("nuke:mese_tnt", {
  158. tile_images = {"nuke_mese_tnt_top.png", "nuke_mese_tnt_bottom.png",
  159. "nuke_mese_tnt_side.png", "nuke_mese_tnt_side.png",
  160. "nuke_mese_tnt_side.png", "nuke_mese_tnt_side.png"},
  161. inventory_image = minetest.inventorycube("nuke_mese_tnt_top.png",
  162. "nuke_mese_tnt_side.png", "nuke_mese_tnt_side.png"),
  163. dug_item = '', -- Get nothing
  164. material = {
  165. diggability = "not",
  166. },
  167. description = "Mese TNT",
  168. })
  169.  
  170. minetest.register_on_punchnode(function(p, node)
  171. if node.name == "nuke:mese_tnt" then
  172. minetest.env:remove_node(p)
  173. spawn_tnt(p, "nuke:mese_tnt")
  174. nodeupdate(p)
  175. end
  176. end)
  177.  
  178. local MESE_TNT_RANGE = 12
  179. local MESE_TNT = {
  180. -- Static definition
  181. physical = true, -- Collides with things
  182. -- weight = 5,
  183. collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
  184. visual = "cube",
  185. textures = {"nuke_mese_tnt_top.png", "nuke_mese_tnt_bottom.png",
  186. "nuke_mese_tnt_side.png", "nuke_mese_tnt_side.png",
  187. "nuke_mese_tnt_side.png", "nuke_mese_tnt_side.png"},
  188. -- Initial value for our timer
  189. timer = 0,
  190. -- Number of punches required to defuse
  191. health = 1,
  192. blinktimer = 0,
  193. blinkstatus = true,
  194. }
  195.  
  196. function MESE_TNT:on_activate(staticdata)
  197. self.object:setvelocity({x=0, y=4, z=0})
  198. self.object:setacceleration({x=0, y=-10, z=0})
  199. self.object:settexturemod("^[brighten")
  200. end
  201.  
  202. function MESE_TNT:on_step(dtime)
  203. self.timer = self.timer + dtime
  204. self.blinktimer = self.blinktimer + dtime
  205. if self.timer>5 then
  206. self.blinktimer = self.blinktimer + dtime
  207. if self.timer>8 then
  208. self.blinktimer = self.blinktimer + dtime
  209. self.blinktimer = self.blinktimer + dtime
  210. end
  211. end
  212. if self.blinktimer > 0.5 then
  213. self.blinktimer = self.blinktimer - 0.5
  214. if self.blinkstatus then
  215. self.object:settexturemod("")
  216. else
  217. self.object:settexturemod("^[brighten")
  218. end
  219. self.blinkstatus = not self.blinkstatus
  220. end
  221. if self.timer > 10 then
  222. local pos = self.object:getpos()
  223. pos.x = math.floor(pos.x+0.5)
  224. pos.y = math.floor(pos.y+0.5)
  225. pos.z = math.floor(pos.z+0.5)
  226. do_tnt_physics(pos, MESE_TNT_RANGE)
  227. minetest.sound_play("nuke_explode", {pos = pos,gain = 1.0,max_hear_distance = 16,})
  228. if minetest.env:get_node(pos).name == "default:water_source" or minetest.env:get_node(pos).name == "default:water_flowing" then
  229. -- Cancel the Explosion
  230. self.object:remove()
  231. return
  232. end
  233. for x=-MESE_TNT_RANGE,MESE_TNT_RANGE do
  234. for y=-MESE_TNT_RANGE,MESE_TNT_RANGE do
  235. for z=-MESE_TNT_RANGE,MESE_TNT_RANGE do
  236. if x*x+y*y+z*z <= MESE_TNT_RANGE * MESE_TNT_RANGE + MESE_TNT_RANGE then
  237. local np={x=pos.x+x,y=pos.y+y,z=pos.z+z}
  238. local n = minetest.env:get_node(np)
  239. if n.name ~= "air" then
  240. minetest.env:remove_node(np)
  241. end
  242. activate_if_tnt(n.name, np, pos, MESE_TNT_RANGE)
  243. end
  244. end
  245. end
  246. end
  247. self.object:remove()
  248. end
  249. end
  250.  
  251. function MESE_TNT:on_punch(hitter)
  252. self.health = self.health - 1
  253. if self.health <= 0 then
  254. self.object:remove()
  255. hitter:get_inventory():add_item("main", "nuke:mese_tnt")
  256. end
  257. end
  258.  
  259. minetest.register_entity("nuke:mese_tnt", MESE_TNT)
  260.  
  261. -- Hardcore Iron TNT
  262.  
  263. minetest.register_craft({
  264. output = 'node "nuke:hardcore_iron_tnt" 1',
  265. recipe = {
  266. {'','craft "default:coal_lump" 1',''},
  267. {'craft "default:coal_lump" 1','node "nuke:iron_tnt" 1','craft "default:coal_lump" 1'},
  268. {'','craft "default:coal_lump" 1',''}
  269. }
  270. })
  271. minetest.register_node("nuke:hardcore_iron_tnt", {
  272. tile_images = {"nuke_iron_tnt_top.png", "nuke_iron_tnt_bottom.png",
  273. "nuke_hardcore_iron_tnt_side.png", "nuke_hardcore_iron_tnt_side.png",
  274. "nuke_hardcore_iron_tnt_side.png", "nuke_hardcore_iron_tnt_side.png"},
  275. inventory_image = minetest.inventorycube("nuke_iron_tnt_top.png",
  276. "nuke_hardcore_iron_tnt_side.png", "nuke_hardcore_iron_tnt_side.png"),
  277. dug_item = '', -- Get nothing
  278. material = {
  279. diggability = "not",
  280. },
  281. description = "Hardcore Iron TNT",
  282. })
  283.  
  284. minetest.register_on_punchnode(function(p, node)
  285. if node.name == "nuke:hardcore_iron_tnt" then
  286. minetest.env:remove_node(p)
  287. spawn_tnt(p, "nuke:hardcore_iron_tnt")
  288. nodeupdate(p)
  289. end
  290. end)
  291.  
  292. local HARDCORE_IRON_TNT_RANGE = 6
  293. local HARDCORE_IRON_TNT = {
  294. -- Static definition
  295. physical = true, -- Collides with things
  296. -- weight = 5,
  297. collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
  298. visual = "cube",
  299. textures = {"nuke_iron_tnt_top.png", "nuke_iron_tnt_bottom.png",
  300. "nuke_hardcore_iron_tnt_side.png", "nuke_hardcore_iron_tnt_side.png",
  301. "nuke_hardcore_iron_tnt_side.png", "nuke_hardcore_iron_tnt_side.png"},
  302. -- Initial value for our timer
  303. timer = 0,
  304. -- Number of punches required to defuse
  305. health = 1,
  306. blinktimer = 0,
  307. blinkstatus = true,
  308. }
  309.  
  310. function HARDCORE_IRON_TNT:on_activate(staticdata)
  311. self.object:setvelocity({x=0, y=4, z=0})
  312. self.object:setacceleration({x=0, y=-10, z=0})
  313. self.object:settexturemod("^[brighten")
  314. end
  315.  
  316. function HARDCORE_IRON_TNT:on_step(dtime)
  317. self.timer = self.timer + dtime
  318. self.blinktimer = self.blinktimer + dtime
  319. if self.timer>5 then
  320. self.blinktimer = self.blinktimer + dtime
  321. if self.timer>8 then
  322. self.blinktimer = self.blinktimer + dtime
  323. self.blinktimer = self.blinktimer + dtime
  324. end
  325. end
  326. if self.blinktimer > 0.5 then
  327. self.blinktimer = self.blinktimer - 0.5
  328. if self.blinkstatus then
  329. self.object:settexturemod("")
  330. else
  331. self.object:settexturemod("^[brighten")
  332. end
  333. self.blinkstatus = not self.blinkstatus
  334. end
  335. if self.timer > 10 then
  336. local pos = self.object:getpos()
  337. pos.x = math.floor(pos.x+0.5)
  338. pos.y = math.floor(pos.y+0.5)
  339. pos.z = math.floor(pos.z+0.5)
  340. minetest.sound_play("nuke_explode", {pos = pos,gain = 1.0,max_hear_distance = 16,})
  341. for x=-HARDCORE_IRON_TNT_RANGE,HARDCORE_IRON_TNT_RANGE do
  342. for z=-HARDCORE_IRON_TNT_RANGE,HARDCORE_IRON_TNT_RANGE do
  343. if x*x+z*z <= HARDCORE_IRON_TNT_RANGE * HARDCORE_IRON_TNT_RANGE + HARDCORE_IRON_TNT_RANGE then
  344. local np={x=pos.x+x,y=pos.y,z=pos.z+z}
  345. minetest.env:add_entity(np, "nuke:iron_tnt")
  346. end
  347. end
  348. end
  349. self.object:remove()
  350. end
  351. end
  352.  
  353. function HARDCORE_IRON_TNT:on_punch(hitter)
  354. self.health = self.health - 1
  355. if self.health <= 0 then
  356. self.object:remove()
  357. hitter:add_to_inventory("node nuke:hardcore_iron_tnt 1")
  358. hitter:set_hp(hitter:get_hp() - 1)
  359. end
  360. end
  361.  
  362. minetest.register_entity("nuke:hardcore_iron_tnt", HARDCORE_IRON_TNT)
  363.  
  364. -- Hardcore Mese TNT
  365.  
  366. minetest.register_craft({
  367. output = 'node "nuke:hardcore_mese_tnt" 1',
  368. recipe = {
  369. {'','craft "default:coal_lump" 1',''},
  370. {'craft "default:coal_lump" 1','node "nuke:mese_tnt" 1','craft "default:coal_lump" 1'},
  371. {'','craft "default:coal_lump" 1',''}
  372. }
  373. })
  374. minetest.register_node("nuke:hardcore_mese_tnt", {
  375. tile_images = {"nuke_mese_tnt_top.png", "nuke_mese_tnt_bottom.png",
  376. "nuke_hardcore_mese_tnt_side.png", "nuke_hardcore_mese_tnt_side.png",
  377. "nuke_hardcore_mese_tnt_side.png", "nuke_hardcore_mese_tnt_side.png"},
  378. inventory_image = minetest.inventorycube("nuke_mese_tnt_top.png",
  379. "nuke_hardcore_mese_tnt_side.png", "nuke_hardcore_mese_tnt_side.png"),
  380. dug_item = '', -- Get nothing
  381. material = {
  382. diggability = "not",
  383. },
  384. description = "Hardcore Mese TNT",
  385. })
  386.  
  387. minetest.register_on_punchnode(function(p, node)
  388. if node.name == "nuke:hardcore_mese_tnt" then
  389. minetest.env:remove_node(p)
  390. spawn_tnt(p, "nuke:hardcore_mese_tnt")
  391. nodeupdate(p)
  392. end
  393. end)
  394.  
  395. local HARDCORE_MESE_TNT_RANGE = 6
  396. local HARDCORE_MESE_TNT = {
  397. -- Static definition
  398. physical = true, -- Collides with things
  399. -- weight = 5,
  400. collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
  401. visual = "cube",
  402. textures = {"nuke_mese_tnt_top.png", "nuke_mese_tnt_bottom.png",
  403. "nuke_hardcore_mese_tnt_side.png", "nuke_hardcore_mese_tnt_side.png",
  404. "nuke_hardcore_mese_tnt_side.png", "nuke_hardcore_mese_tnt_side.png"},
  405. -- Initial value for our timer
  406. timer = 0,
  407. -- Number of punches required to defuse
  408. health = 1,
  409. blinktimer = 0,
  410. blinkstatus = true,
  411. }
  412.  
  413. function HARDCORE_MESE_TNT:on_activate(staticdata)
  414. self.object:setvelocity({x=0, y=4, z=0})
  415. self.object:setacceleration({x=0, y=-10, z=0})
  416. self.object:settexturemod("^[brighten")
  417. end
  418.  
  419. function HARDCORE_MESE_TNT:on_step(dtime)
  420. self.timer = self.timer + dtime
  421. self.blinktimer = self.blinktimer + dtime
  422. if self.timer>5 then
  423. self.blinktimer = self.blinktimer + dtime
  424. if self.timer>8 then
  425. self.blinktimer = self.blinktimer + dtime
  426. self.blinktimer = self.blinktimer + dtime
  427. end
  428. end
  429. if self.blinktimer > 0.5 then
  430. self.blinktimer = self.blinktimer - 0.5
  431. if self.blinkstatus then
  432. self.object:settexturemod("")
  433. else
  434. self.object:settexturemod("^[brighten")
  435. end
  436. self.blinkstatus = not self.blinkstatus
  437. end
  438. if self.timer > 10 then
  439. local pos = self.object:getpos()
  440. pos.x = math.floor(pos.x+0.5)
  441. pos.y = math.floor(pos.y+0.5)
  442. pos.z = math.floor(pos.z+0.5)
  443. minetest.sound_play("nuke_explode", {pos = pos,gain = 1.0,max_hear_distance = 16,})
  444. for x=-HARDCORE_MESE_TNT_RANGE,HARDCORE_MESE_TNT_RANGE do
  445. for z=-HARDCORE_MESE_TNT_RANGE,HARDCORE_MESE_TNT_RANGE do
  446. if x*x+z*z <= HARDCORE_MESE_TNT_RANGE * HARDCORE_MESE_TNT_RANGE + HARDCORE_MESE_TNT_RANGE then
  447. local np={x=pos.x+x,y=pos.y,z=pos.z+z}
  448. minetest.env:add_entity(np, "nuke:mese_tnt")
  449. end
  450. end
  451. end
  452. self.object:remove()
  453. end
  454. end
  455.  
  456. function HARDCORE_MESE_TNT:on_punch(hitter)
  457. self.health = self.health - 1
  458. if self.health <= 0 then
  459. self.object:remove()
  460. hitter:add_to_inventory("node nuke:hardcore_mese_tnt 1")
  461. hitter:set_hp(hitter:get_hp() - 1)
  462. end
  463. end
  464.  
  465. minetest.register_entity("nuke:hardcore_mese_tnt", HARDCORE_MESE_TNT)
RAW Paste Data