TNT: Allow a custom explosion sound to be used
authortenplus1 <tenplus1@users.noreply.github.com>
Sat, 8 Jul 2017 20:17:33 +0000 (21:17 +0100)
committerparamat <mat.gregory@virginmedia.com>
Fri, 18 Aug 2017 17:41:15 +0000 (18:41 +0100)
game_api.txt
mods/tnt/init.lua

index 7c3c04cd7debc408486560554d9201f80c9dd79c..a6f4da7c63b8864b49f220e2610d0f857cacfcde 100644 (file)
@@ -348,6 +348,7 @@ TNT API
  * `description` A description for your TNT.
  * `radius` The radius within which the TNT can destroy nodes. The default is 3.
  * `damage_radius` The radius within which the TNT can damage players and mobs. By default it is twice the `radius`.
+ * `sound` The sound played when explosion occurs. By default it is `tnt_explode`.
  * `disable_drops` Disable drops. By default it is set to false.
  * `ignore_protection` Don't check `minetest.is_protected` before removing a node.
  * `ignore_on_blast` Don't call `on_blast` even if a node has one.
index 0326000b79cdf523f857d0f16d85794dcbe66909..18ca304efdcd6d6af1d875e956b48e730f3bafac 100644 (file)
@@ -384,7 +384,9 @@ end
 function tnt.boom(pos, def)
        local meta = minetest.get_meta(pos)
        local owner = meta:get_string("owner")
-       minetest.sound_play("tnt_explode", {pos = pos, gain = 1.5, max_hear_distance = 2*64})
+       local sound = def.sound or "tnt_explode"
+       minetest.sound_play(sound, {pos = pos, gain = 1.5,
+                       max_hear_distance = math.min(def.radius * 20, 128)})
        minetest.set_node(pos, {name = "tnt:boom"})
        local drops, radius = tnt_explode(pos, def.radius, def.ignore_protection,
                        def.ignore_on_blast, owner)