From 653979051f4da9247c474c94f2fc3eae08f24fbf Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 12 Jul 2021 13:50:11 +0200 Subject: [PATCH] Add death messages --- mods/hades_core/liquids.lua | 3 + mods/hades_core/simple_nodes.lua | 36 ++++ mods/hades_death_messages/description.txt | 1 + mods/hades_death_messages/init.lua | 208 +++++++++++++++++++ mods/hades_death_messages/mod.conf | 1 + mods/hbhunger/hunger.lua | 3 + mods/hbhunger/init.lua | 5 +- mods/hbhunger/mod.conf | 2 +- mods/mesecons/mesecons_commandblock/init.lua | 8 + settingtypes.txt | 3 + 10 files changed, 268 insertions(+), 2 deletions(-) create mode 100644 mods/hades_death_messages/description.txt create mode 100644 mods/hades_death_messages/init.lua create mode 100644 mods/hades_death_messages/mod.conf diff --git a/mods/hades_core/liquids.lua b/mods/hades_core/liquids.lua index 976f3ea..aa83018 100644 --- a/mods/hades_core/liquids.lua +++ b/mods/hades_core/liquids.lua @@ -1,4 +1,5 @@ local S = minetest.get_translator("hades_core") +local N = function(s) return s end local WATER_VISC = 1 local LAVA_VISC = 7 @@ -111,6 +112,7 @@ minetest.register_node("hades_core:lava_flowing", { post_effect_color = {a=192, r=255, g=64, b=0}, groups = {lava=3, liquid=2, igniter=1, not_in_creative_inventory=1}, sounds = hades_sounds.node_sound_lava_defaults(), + _hades_node_death_message = { N("Overheating in lava") }, }) @@ -147,5 +149,6 @@ minetest.register_node("hades_core:lava_source", { post_effect_color = {a=192, r=255, g=64, b=0}, groups = {lava=3, liquid=2, igniter=1}, sounds = hades_sounds.node_sound_lava_defaults(), + _hades_node_death_message = { N("Overheating in lava") }, }) diff --git a/mods/hades_core/simple_nodes.lua b/mods/hades_core/simple_nodes.lua index 5c8f01a..f0f2933 100644 --- a/mods/hades_core/simple_nodes.lua +++ b/mods/hades_core/simple_nodes.lua @@ -384,6 +384,42 @@ minetest.register_node("hades_core:dirt", { sounds = hades_sounds.node_sound_dirt_defaults(), }) +minetest.register_node("hades_core:coarse_dirt", { + description = S("Coarse Dirt"), + tiles = {"mtg_plus_graveldirt.png"}, + is_ground_content = true, + groups = {crumbly=3, porous=1}, + sounds = hades_sounds.node_sound_dirt_defaults(), +}) + +minetest.register_node("hades_core:gravel_cobble", { + description = S("Cobbled Gravel"), + tiles = {"mtg_plus_gravel_cobble.png"}, + is_ground_content = false, + groups = {cracky=3}, + sounds = hades_sounds.node_sound_stone_defaults(), +}) + +minetest.register_node("hades_core:sandstone_cobble", { + description = S("Cobbled Sandstone"), + tiles = {"hades_core_sandstone_cobble.png"}, + is_ground_content = false, + groups = {cracky=3}, + sounds = hades_sounds.node_sound_stone_defaults(), +}) + +minetest.register_node("hades_core:sandstone_volcanic_cobble", { + description = S("Cobbled Volcanic Sandstone"), + tiles = {"hades_core_sandstone_volcanic_cobble.png"}, + is_ground_content = false, + groups = {cracky=3}, + sounds = hades_sounds.node_sound_stone_defaults(), +}) + + + + + minetest.register_node("hades_core:ash", { description = S("Volcanic Ash"), diff --git a/mods/hades_death_messages/description.txt b/mods/hades_death_messages/description.txt new file mode 100644 index 0000000..7c322f6 --- /dev/null +++ b/mods/hades_death_messages/description.txt @@ -0,0 +1 @@ +Shows messages in chat when a player dies. diff --git a/mods/hades_death_messages/init.lua b/mods/hades_death_messages/init.lua new file mode 100644 index 0000000..bdaf4da --- /dev/null +++ b/mods/hades_death_messages/init.lua @@ -0,0 +1,208 @@ +local S = minetest.get_translator("hades_death_messages") +local N = function(s) return s end + +hades_death_messages = {} + +-- Death messages +local msgs = { + ["drown"] = { + N("Drowning"), + }, + ["drown_water"] = { + N("Drowning in water"), + }, + ["drown_lava"] = { + N("Drowning in lava"), + }, + ["node"] = { + N("Damage from a block"), + }, + ["projectile_mese_arrow"] = { + N("Shot by a mese monster crystal shard"), + }, + ["projectile_fireball"] = { + N("Shot by a fireball"), + }, + ["murder"] = { + N("Melee attack from an unknown source"), + }, + ["murder_any"] = { + N("Melee attack from an unknown source"), + }, + ["mob_kill"] = { + N("Hit from a hostile creature"), + }, + ["fall"] = { + N("Falling"), + }, + ["other"] = { + N("Unknown"), + } +} + +local mobkills = { + ["mobs_hades:mutant"] = N("Punch from a mutant"), + ["mobs_hades:cave_master"] = N("Hit from a cave master"), + ["mobs_hades:cave_elder"] = N("Hit from a cave elder"), + ["mobs_hades:mese_monster"] = N("Headbutt from a mese monster"), + ["mobs_hades:deep_mese_monster"] = N("Headbutt from a deep mese monster"), + ["mobs_hades:oerkki"] = N("Hit from an oerkki"), + ["mobs_hades:stone_monster"] = N("Hit from a stone monster"), + ["mobs_hades:deep_stone_monster"] = N("Hit from a deep stone monster"), + ["mobs_hades:spider_gold"] = N("Bite from a gold spider"), + ["mobs_hades:spider_sapphire"] = N("Bite from a sapphire spider"), + ["mobs_hades:spider_ruby"] = N("Bite from a ruby spider"), + ["mobs_hades:spider_mese"] = N("Bite from a mese spider"), +} + +-- Select death message +local smsg = function(msg) + return S("Cause of death: @1.", msg) +end + +local dmsg = function(mtype, ...) + local r = math.random(1, #msgs[mtype]) + return S("Cause of death: @1.", msgs[mtype][r], ...) +end + +-- Select death message for death by mob +local mmsg = function(mtype, ...) + if mobkills[mtype] then + return S("Cause of death: @1.", S(mobkills[mtype], ...)) + else + return dmsg("mob_kill", ...) + end +end + +local last_damages = { } + +minetest.register_on_dieplayer(function(player, reason) + -- Death message + local message = minetest.settings:get_bool("hades_show_death_messages", true) + if message == nil then + message = true + end + if message then + local name = player:get_player_name() + if not name then + return + end + local msg + if last_damages[name] then + -- custom message + msg = smsg(last_damages[name].message) + elseif reason.type == "node_damage" then + local pos = player:get_pos() + local node = reason.node + local node_def = minetest.registered_nodes[node] + if node_def and node_def._hades_node_death_message then + local field = node_def._hades_node_death_message + local field_msg + if type(field) == "table" then + field_msg = field[math.random(1, #field)] + else + field_msg = field + end + local textdomain + if node_def.mod_origin then + textdomain = node_def.mod_origin + else + textdomain = "hades_death_messages" + end + -- We assume the textdomain of the death message in the node definition + -- equals the modname. + msg = smsg(minetest.translate(textdomain, field_msg)) + else + msg = dmsg("node") + end + elseif reason.type == "drown" then + local pos = player:get_pos() + -- check "head position" to estimate in which node the player drowned + local cpos = {x=pos.x,y=pos.y+1,z=pos.z} + local dnode = minetest.get_node(cpos) + if minetest.get_item_group(dnode.name, "water") then + msg = dmsg("drown_water") + elseif minetest.get_item_group(dnode.name, "lava") then + msg = dmsg("drown_lava") + else + msg = dmsg("drown") + end + elseif reason.type == "punch" then + -- Punches + local hitter = reason.object + local hittername, hittertype, hittersubtype, shooter + -- Custom message + if last_damages[name] then + msg = smsg(last_damages[name].message) + -- Unknown hitter + elseif hitter == nil then + msg = dmsg("murder_any") + -- Player + elseif hitter:is_player() then + hittername = hitter:get_player_name() + if hittername ~= nil then + msg = dmsg("murder", hittername) + else + msg = dmsg("murder_any") + end + -- Mob (according to Common Mob Interface) + elseif hitter:get_luaentity()._cmi_is_mob then + if hitter:get_luaentity().nametag and hitter:get_luaentity().nametag ~= "" then + hittername = hitter:get_luaentity().nametag + end + hittersubtype = hitter:get_luaentity().name + if hittername then + msg = dmsg("murder", hittername) + elseif hittersubtype ~= nil and hittersubtype ~= "" then + msg = mmsg(hittersubtype) + else + msg = dmsg("murder_any") + end + elseif hitter:get_luaentity().name == "mobs_hades:mese_arrow" then + msg = dmsg("projectile_mese_arrow") + elseif hitter:get_luaentity().name == "mobs_hades:fireball" then + msg = dmsg("projectile_fireball") + end + -- Falling + elseif reason.type == "fall" then + msg = dmsg("fall") + -- Other + elseif reason.type == "set_hp" then + if last_damages[name] then + msg = smsg(last_damages[name].message) + end + end + if not msg then + msg = dmsg("other") + end + -- Send message after short delay so it appears after "You died.". + minetest.after(0.25, function(data) + minetest.chat_send_player(data.name, minetest.colorize("#FF8080", data.msg)) + end, {name=name, msg=msg}) + last_damages[name] = nil + end +end) + +-- dmg_sequence_number is used to discard old damage events +local dmg_sequence_number = 0 +local start_damage_reset_countdown = function (player, sequence_number) + minetest.after(1, function(playername, sequence_number) + if last_damages[playername] and last_damages[playername].sequence_number == sequence_number then + last_damages[playername] = nil + end + end, player:get_player_name(), sequence_number) +end + +-- Send a custom death mesage when damaging a player via set_hp or punch. +-- To be called directly BEFORE damaging a player via set_hp or punch. +-- The next time the player dies due to a set_hp, the message will be shown. +-- The player must die via set_hp within 0.1 seconds, otherwise the message will be discarded. +function hades_death_messages.player_damage(player, message) + last_damages[player:get_player_name()] = { message = message, sequence_number = dmg_sequence_number } + start_damage_reset_countdown(player, dmg_sequence_number) + dmg_sequence_number = dmg_sequence_number + 1 + if dmg_sequence_number >= 65535 then + dmg_sequence_number = 0 + end +end + diff --git a/mods/hades_death_messages/mod.conf b/mods/hades_death_messages/mod.conf new file mode 100644 index 0000000..37af37a --- /dev/null +++ b/mods/hades_death_messages/mod.conf @@ -0,0 +1 @@ +name = hades_death_messages diff --git a/mods/hbhunger/hunger.lua b/mods/hbhunger/hunger.lua index 5b6c4c3..6a2feb6 100644 --- a/mods/hbhunger/hunger.lua +++ b/mods/hbhunger/hunger.lua @@ -1,3 +1,5 @@ +local S = minetest.get_translator("hbhunger") + -- Keep these for backwards compatibility function hbhunger.save_hunger(player) hbhunger.set_hunger_raw(player) @@ -72,6 +74,7 @@ local function poisenp(tick, time, time_left, player) end end if player:get_hp()-1 > 0 then + hades_death_messages.player_damage(player, S("Food poisoning")) player:set_hp(player:get_hp()-1) end diff --git a/mods/hbhunger/init.lua b/mods/hbhunger/init.lua index 20a896c..35265dd 100644 --- a/mods/hbhunger/init.lua +++ b/mods/hbhunger/init.lua @@ -124,7 +124,10 @@ minetest.register_globalstep(function(dtime) player:set_hp(hp+1) -- or damage player by 1 hp if satiation is < 2 elseif h <= 1 then - if hp-1 >= 0 then player:set_hp(hp-1) end + if hp-1 >= 0 then + hades_death_messages.player_damage(player, S("Starvation")) + player:set_hp(hp-1) + end end end -- lower satiation by 1 point after xx seconds diff --git a/mods/hbhunger/mod.conf b/mods/hbhunger/mod.conf index da6c465..4543b15 100644 --- a/mods/hbhunger/mod.conf +++ b/mods/hbhunger/mod.conf @@ -1,4 +1,4 @@ name = hbhunger description = Adds a simple hunger meachanic with satiation, food poisoning and different healing. -depends = hudbars +depends = hudbars, hades_death_messages optional_depends = default, flowers, animalmaterials, bucket, bushes, bushes_classic, cooking, creatures, docfarming, dwarves, ethereal, farming, farming_plus, ferns, fishing, fruit, glooptest, jkanimals, jkfarming, jkwine, kpgmobs, mobfcooking, mobs, moretrees, mtfoods, mush45, mushroom, seaplants, pizza, nssm diff --git a/mods/mesecons/mesecons_commandblock/init.lua b/mods/mesecons/mesecons_commandblock/init.lua index 7fbc8e7..f8cfca3 100644 --- a/mods/mesecons/mesecons_commandblock/init.lua +++ b/mods/mesecons/mesecons_commandblock/init.lua @@ -1,3 +1,5 @@ +local S = minetest.get_translator("mesecons_commandblock") + minetest.register_chatcommand("say", { params = "", description = "Say as the server", @@ -35,6 +37,12 @@ minetest.register_chatcommand("hp", { end local player = minetest.get_player_by_name(target) if player then + if name == target then + hades_death_messages.player_damage(player, S("A death wish")) + else + -- You took damage from "a higher power" ;-) + hades_death_messages.player_damage(player, S("A higher power")) + end player:set_hp(value) else minetest.chat_send_player(name, "Invalid target: " .. target) diff --git a/settingtypes.txt b/settingtypes.txt index b103028..849f407 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -8,6 +8,9 @@ hades_greeting (Show greeting message) bool true # ash and drop apples and pickaxes when they die. give_initial_stuff (Give starter items) bool true +# If enabled, dead players will get a message that says how they died. +hades_show_death_messages (Show cause of death) bool true + # If enabled, the item identifier of the wielded item will be shown in HUD. show_wielded_item_itemname (Show itemstring in HUD) bool false