Use igniter as puncher when TNT deals damage

This commit is contained in:
Wuzzy 2024-03-05 18:26:35 +01:00
parent d29ef0f683
commit 263de7a865
2 changed files with 28 additions and 14 deletions

View File

@ -14,7 +14,7 @@ Note: The `igniter` is only used for logging purposes.
## `tnt.boom(pos, radius, sound)`
## `tnt.boom(pos, radius, sound, igniter)`
Blows up a TNT node.
This will remove the TNT node, cause an explosion at `pos`,
@ -26,10 +26,10 @@ Parameters:
* `pos`: Position of the TNT node. The TNT node is required!
* `radius`: Explosion radius (default: read from `tnt_radius` setting)
* `sound`: Sound name for explosion (default: `tnt_explode`)
* `igniter`: Optional player object of player who ignited it or `nil` if nobody/unknown
## `tnt.boom_notnt(pos, radius, sound, remove_nodes)`
## `tnt.boom_notnt(pos, radius, sound, remove_nodes, igniter)`
Does an explosion.
Same as `tnt.boom` but works for non-TNT nodes as well. No TNT required.
@ -40,6 +40,7 @@ Parameters:
* `radius`: Explosion radius (default: read from `tnt_radius` setting)
* `sound`: Sound name for explosion (default: `tnt_explode`)
* `remove_nodes`: If true, will remove nodes, otherwise won't. (default: false)
* `igniter`: Optional player object of player who ignited it or `nil` if nobody/unknown
## `tnt.explode(pos, radius)`

View File

@ -138,7 +138,7 @@ local function calc_velocity(pos1, pos2, power)
return vel
end
local function entity_physics(pos, radius)
local function entity_physics(pos, radius, igniter)
-- Make the damage radius larger than the destruction radius
radius = radius * 2
@ -154,7 +154,13 @@ local function entity_physics(pos, radius)
local damage = (4 / dist) * radius
local dir = vector.direction(pos, obj_pos)
obj:punch(obj, 1000000, { full_punch_interval = 0, damage_groups = { fleshy = damage } }, dir)
local puncher
if igniter then
puncher = igniter
else
puncher = obj
end
obj:punch(puncher, 1000000, { full_punch_interval = 0, damage_groups = { fleshy = damage } }, dir)
end
end
@ -280,6 +286,11 @@ function tnt.burn(pos, igniter)
minetest.set_node(pos, {name = "rp_tnt:tnt_burning"})
if igniter then
achievements.trigger_achievement(igniter, "boom")
if igniter:is_player() then
local meta = minetest.get_meta(pos)
meta:set_string("igniter", igniter:get_player_name())
end
minetest.log("action", "[rp_tnt] TNT ignited by "..igniter:get_player_name().." at "..minetest.pos_to_string(pos, 0))
else
minetest.log("verbose", "[rp_tnt] TNT ignited at "..minetest.pos_to_string(pos, 0))
@ -370,7 +381,7 @@ end
-- TNT node explosion
local function rawboom(pos, radius, sound, remove_nodes, is_tnt)
local function rawboom(pos, radius, sound, remove_nodes, is_tnt, igniter)
if is_tnt then
local node = minetest.get_node(pos)
minetest.remove_node(pos)
@ -392,27 +403,27 @@ local function rawboom(pos, radius, sound, remove_nodes, is_tnt)
else
minetest.log("verbose", "[rp_tnt] Explosion at "..minetest.pos_to_string(pos, 0))
end
entity_physics(pos, radius)
entity_physics(pos, radius, igniter)
eject_drops(drops, pos, radius)
else
entity_physics(pos, radius)
entity_physics(pos, radius, igniter)
play_tnt_sound(pos, sound)
end
add_explosion_effects(pos, radius)
end
function tnt.boom(pos, radius, sound)
function tnt.boom(pos, radius, sound, igniter)
if not radius then
radius = tnt_radius
end
if not sound then
sound = "tnt_explode"
end
rawboom(pos, radius, sound, true, true)
rawboom(pos, radius, sound, true, true, igniter)
end
function tnt.boom_notnt(pos, radius, sound, remove_nodes)
function tnt.boom_notnt(pos, radius, sound, remove_nodes, igniter)
if not radius then
radius = tnt_radius
end
@ -422,7 +433,7 @@ function tnt.boom_notnt(pos, radius, sound, remove_nodes)
if remove_nodes == nil then
remove_nodes = tnt_enable
end
rawboom(pos, radius, sound, remove_nodes, false)
rawboom(pos, radius, sound, remove_nodes, false, igniter)
end
-- On load register content IDs
@ -473,13 +484,15 @@ minetest.register_node(
return
end
tnt.burn(pos, user)
achievements.trigger_achievement(user, "boom")
return { sound = false }
end,
})
local tnt_burning_on_timer = function(pos)
tnt.boom(pos)
local meta = minetest.get_meta(pos)
local igniter_name = meta:get_string("igniter")
local igniter = minetest.get_player_by_name(igniter_name)
tnt.boom(pos, nil, nil, igniter)
end
-- Nodes