diff --git a/mods/ITEMS/mcl_nether/depends.txt b/mods/ITEMS/mcl_nether/depends.txt index 492887c93b..c5d5193f73 100644 --- a/mods/ITEMS/mcl_nether/depends.txt +++ b/mods/ITEMS/mcl_nether/depends.txt @@ -1,5 +1,6 @@ mcl_sounds mcl_util walkover +mcl_death_messages doc_items doc? diff --git a/mods/ITEMS/mcl_nether/init.lua b/mods/ITEMS/mcl_nether/init.lua index 4f103ef7ea..f6275c78b7 100644 --- a/mods/ITEMS/mcl_nether/init.lua +++ b/mods/ITEMS/mcl_nether/init.lua @@ -60,7 +60,10 @@ minetest.register_node("mcl_nether:magma", { -- From walkover mod on_walk_over = function(loc, nodeiamon, player) -- Hurt players standing on top of this block - player:set_hp(player:get_hp() - 1) + if player:get_hp() > 0 then + mcl_death_messages.player_damage(player, string.format("%s stood too long on a magma block.", player:get_player_name())) + player:set_hp(player:get_hp() - 1) + end end, _mcl_blast_resistance = 2.5, _mcl_hardness = 0.5, diff --git a/mods/PLAYER/mcl_death/mod.conf b/mods/PLAYER/mcl_death/mod.conf deleted file mode 100644 index a090fb79e5..0000000000 --- a/mods/PLAYER/mcl_death/mod.conf +++ /dev/null @@ -1 +0,0 @@ -name = mcl_death diff --git a/mods/PLAYER/mcl_death/depends.txt b/mods/PLAYER/mcl_death_drop/depends.txt similarity index 100% rename from mods/PLAYER/mcl_death/depends.txt rename to mods/PLAYER/mcl_death_drop/depends.txt diff --git a/mods/PLAYER/mcl_death/description.txt b/mods/PLAYER/mcl_death_drop/description.txt similarity index 100% rename from mods/PLAYER/mcl_death/description.txt rename to mods/PLAYER/mcl_death_drop/description.txt diff --git a/mods/PLAYER/mcl_death_drop/init.lua b/mods/PLAYER/mcl_death_drop/init.lua new file mode 100644 index 0000000000..d69290f05c --- /dev/null +++ b/mods/PLAYER/mcl_death_drop/init.lua @@ -0,0 +1,37 @@ +minetest.register_on_dieplayer(function(player) + local keep = minetest.setting_getbool("mcl_keepInventory") or false + if keep == false then + -- Drop inventory, crafting grid and armor + local inv = player:get_inventory() + local pos = player:getpos() + local name, player_armor_inv, armor_armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]") + local lists = { + { inv = inv, listname = "main", drop = true }, + { inv = inv, listname = "craft", drop = true }, + { inv = player_armor_inv, listname = "armor", drop = true }, + { inv = armor_armor_inv, listname = "armor", drop = false }, + } + for l=1,#lists do + local inv = lists[l].inv + local listname = lists[l].listname + local drop = lists[l].drop + if inv ~= nil then + for i, stack in ipairs(inv:get_list(listname)) do + local x = math.random(0, 9)/3 + local z = math.random(0, 9)/3 + pos.x = pos.x + x + pos.z = pos.z + z + if drop then + minetest.add_item(pos, stack) + end + stack:clear() + inv:set_stack(listname, i, stack) + pos.x = pos.x - x + pos.z = pos.z - z + end + end + end + armor:set_player_armor(player) + armor:update_inventory(player) + end +end) diff --git a/mods/PLAYER/mcl_death_drop/mod.conf b/mods/PLAYER/mcl_death_drop/mod.conf new file mode 100644 index 0000000000..93ed70ad41 --- /dev/null +++ b/mods/PLAYER/mcl_death_drop/mod.conf @@ -0,0 +1 @@ +name = mcl_death_drop diff --git a/mods/PLAYER/mcl_death_messages/description.txt b/mods/PLAYER/mcl_death_messages/description.txt new file mode 100644 index 0000000000..7c322f644d --- /dev/null +++ b/mods/PLAYER/mcl_death_messages/description.txt @@ -0,0 +1 @@ +Shows messages in chat when a player dies. diff --git a/mods/PLAYER/mcl_death/init.lua b/mods/PLAYER/mcl_death_messages/init.lua similarity index 73% rename from mods/PLAYER/mcl_death/init.lua rename to mods/PLAYER/mcl_death_messages/init.lua index 13d316d009..65277a5e66 100644 --- a/mods/PLAYER/mcl_death/init.lua +++ b/mods/PLAYER/mcl_death_messages/init.lua @@ -1,13 +1,11 @@ +mcl_death_messages = {} + -- Death messages local msgs = { ["arrow"] = { "%s was fatally hit by an arrow.", "%s has been killed with an arrow.", }, - ["cactus"] = { - "%s was killed by a cactus.", - "%s was pricked to death.", - }, ["fire"] = { "%s has been cooked crisp.", "%s felt the burn.", @@ -123,45 +121,9 @@ local mmsg = function(mtype, ...) end end -local last_punches = { } +local last_damages = { } minetest.register_on_dieplayer(function(player) - local keep = minetest.setting_getbool("mcl_keepInventory") or false - if keep == false then - -- Drop inventory, crafting grid and armor - local inv = player:get_inventory() - local pos = player:getpos() - local name, player_armor_inv, armor_armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]") - local lists = { - { inv = inv, listname = "main", drop = true }, - { inv = inv, listname = "craft", drop = true }, - { inv = player_armor_inv, listname = "armor", drop = true }, - { inv = armor_armor_inv, listname = "armor", drop = false }, - } - for l=1,#lists do - local inv = lists[l].inv - local listname = lists[l].listname - local drop = lists[l].drop - if inv ~= nil then - for i, stack in ipairs(inv:get_list(listname)) do - local x = math.random(0, 9)/3 - local z = math.random(0, 9)/3 - pos.x = pos.x + x - pos.z = pos.z + z - if drop then - minetest.add_item(pos, stack) - end - stack:clear() - inv:set_stack(listname, i, stack) - pos.x = pos.x - x - pos.z = pos.z - z - end - end - end - armor:set_player_armor(player) - armor:update_inventory(player) - end - -- Death message local message = minetest.setting_getbool("mcl_showDeathMessages") if message == nil then message = true end @@ -185,31 +147,31 @@ minetest.register_on_dieplayer(function(player) -- Void elseif node.name == "mcl_core:void" then msg = dmsg("void", name) - -- Cactus - elseif node.name == "mcl_core:cactus" then - msg = dmsg("cactus", name) -- Other else -- Killed by entity - if last_punches[name] then + if last_damages[name] then -- Mob - if last_punches[name].hittertype == "mob" then - if last_punches[name].hittername then - msg = dmsg("murder", name, last_punches[name].hittername) + if last_damages[name].hittertype == "mob" then + if last_damages[name].hittername then + msg = dmsg("murder", name, last_damages[name].hittername) else - msg = mmsg(last_punches[name].hittersubtype, name) + msg = mmsg(last_damages[name].hittersubtype, name) end -- Player - elseif last_punches[name].hittertype == "player" then - msg = dmsg("murder", name, last_punches[name].hittername) + elseif last_damages[name].hittertype == "player" then + msg = dmsg("murder", name, last_damages[name].hittername) -- Arrow - elseif last_punches[name].hittertype == "arrow" then + elseif last_damages[name].hittertype == "arrow" then msg = dmsg("arrow", name) -- Fireball - elseif last_punches[name].hittertype == "blaze_fireball" then + elseif last_damages[name].hittertype == "blaze_fireball" then msg = dmsg("blaze_fireball", name) - elseif last_punches[name].hittertype == "ghast_fireball" then + elseif last_damages[name].hittertype == "ghast_fireball" then msg = dmsg("ghast_fireball", name) + -- Custom death message + elseif last_damages[name].custom then + msg = last_damages[name].message end -- Other reason else @@ -222,6 +184,11 @@ minetest.register_on_dieplayer(function(player) end end) +local start_damage_reset_countdown = function (player) + minetest.after(1, function(playername) + last_damages[playername] = nil + end, player:get_player_name()) +end minetest.register_on_punchplayer(function(player, hitter) if not player or not player:is_player() or not hitter then @@ -256,8 +223,12 @@ minetest.register_on_punchplayer(function(player, hitter) return end - last_punches[player:get_player_name()] = { shooter = shooter, hittername = hittername, hittertype = hittertype, hittersubtype = hittersubtype } - minetest.after(1, function(playername) - last_punches[playername] = nil - end, player:get_player_name()) + last_damages[player:get_player_name()] = { shooter = shooter, hittername = hittername, hittertype = hittertype, hittersubtype = hittersubtype } + start_damage_reset_countdown(player) end) + +-- To be called to notify this mod that a player has been damaged, with a custom death message if the player died +function mcl_death_messages.player_damage(player, message) + last_damages[player:get_player_name()] = { custom = true, message = message } + start_damage_reset_countdown(player) +end diff --git a/mods/PLAYER/mcl_death_messages/mod.conf b/mods/PLAYER/mcl_death_messages/mod.conf new file mode 100644 index 0000000000..4e43960742 --- /dev/null +++ b/mods/PLAYER/mcl_death_messages/mod.conf @@ -0,0 +1 @@ +name = mcl_death_messages diff --git a/mods/PLAYER/mcl_playerplus/depends.txt b/mods/PLAYER/mcl_playerplus/depends.txt index d76b6ecef9..e5b017ff7b 100644 --- a/mods/PLAYER/mcl_playerplus/depends.txt +++ b/mods/PLAYER/mcl_playerplus/depends.txt @@ -3,4 +3,5 @@ mcl_util mcl_core mcl_particles mcl_hunger +mcl_death_messages 3d_armor? diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 4532fcb6c8..4e7ee95467 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -167,10 +167,11 @@ minetest.register_globalstep(function(dtime) -- am I touching the cactus? if so it hurts for _,object in pairs(minetest.get_objects_inside_radius(near, 1.1)) do if object:get_hp() > 0 then - object:set_hp(object:get_hp() - 1) if object:is_player() then + mcl_death_messages.player_damage(object, string.format("%s was prickled by a cactus", object:get_player_name())) mcl_hunger.exhaust(object:get_player_name(), mcl_hunger.EXHAUST_DAMAGE) end + object:set_hp(object:get_hp() - 1) end end