1
0
Fork 0

Rewrite all deathmessages

This commit is contained in:
Code-Sploit 2021-02-18 17:59:44 +00:00
parent 793b5f616e
commit ae7c4d7a8b
1 changed files with 297 additions and 281 deletions

View File

@ -1,281 +1,297 @@
local S = minetest.get_translator("mcl_death_messages") local S = minetest.get_translator("mcl_death_messages")
local N = function(s) return s end local N = function(s) return s end
mcl_death_messages = {} local function get_tool_name(item)
local name = item:get_meta():get_string("name")
-- Death messages if name ~= "" then
local msgs = { return name
["arrow"] = { end
N("@1 was fatally hit by an arrow."), local def = item:get_definition()
N("@1 has been killed by an arrow."), return def._tt_original_description or def.description
}, end
["arrow_name"] = {
N("@1 was shot by an arrow from @2."), mcl_death_messages = {}
},
["arrow_skeleton"] = { -- Death messages
N("@1 was shot by an arrow from a skeleton."), local msgs = {
}, ["arrow"] = {
["arrow_stray"] = { N("@1 was fatally hit by an arrow."),
N("@1 was shot by an arrow from a stray."), N("@1 has been killed by an arrow."),
}, },
["arrow_illusioner"] = { ["arrow_name"] = {
N("@1 was shot by an arrow from an illusioner."), N("@1 was shot by @2 using [@3]"),
}, },
["arrow_mob"] = { ["arrow_skeleton"] = {
N("@1 was shot by an arrow."), N("@1 was shot by Skeleton."),
}, },
["drown"] = { ["arrow_stray"] = {
N("@1 forgot to breathe."), N("@1 was shot by Stray."),
N("@1 drowned."), },
N("@1 ran out of oxygen."), ["arrow_illusioner"] = {
}, N("@1 was shot by Illusioner."),
["murder"] = { },
N("@1 was killed by @2."), ["arrow_mob"] = {
}, N("@1 was shot."),
["murder_any"] = { },
N("@1 was killed."), ["drown"] = {
}, N("@1 forgot to breathe."),
["mob_kill"] = { N("@1 drowned."),
N("@1 was killed by a mob."), N("@1 ran out of oxygen."),
}, },
["blaze_fireball"] = { ["murder"] = {
N("@1 was burned to death by a blaze's fireball."), N("@1 was slain by @2 using [@3]"),
N("@1 was killed by a fireball from a blaze."), },
}, ["murder_any"] = {
["fire_charge"] = { N("@1 was killed."),
N("@1 was burned by a fire charge."), },
}, ["mob_kill"] = {
["ghast_fireball"] = { N("@1 was slain by a mob."),
N("A ghast scared @1 to death."), },
N("@1 has been fireballed by a ghast."), ["blaze_fireball"] = {
}, N("@1 was burned to death by a Blaze's fireball."),
["fall"] = { N("@1 was fireballed by a Blaze"),
N("@1 fell from a high cliff."), },
N("@1 took fatal fall damage."), ["fire_charge"] = {
N("@1 fell victim to gravity."), N("@1 was burned by a fire charge."),
}, },
["other"] = { ["ghast_fireball"] = {
N("@1 died."), N("A ghast scared @1 to death."),
} N("@1 has been fireballed by a Ghast."),
} },
["fall"] = {
local mobkills = { N("@1 fell from a high cliff."),
["mobs_mc:zombie"] = N("@1 was killed by a zombie."), N("@1 took fatal fall damage."),
["mobs_mc:baby_zombie"] = N("@1 was killed by a baby zombie."), N("@1 fell victim to gravity."),
["mobs_mc:blaze"] = N("@1 was killed by a blaze."), N("@1 hit the ground too hard.")
["mobs_mc:slime"] = N("@1 was killed by a slime."), },
["mobs_mc:witch"] = N("@1 was killed by a witch."),
["mobs_mc:magma_cube_tiny"] = N("@1 was killed by a magma cube."), ["other"] = {
["mobs_mc:magma_cube_small"] = N("@1 was killed by a magma cube."), N("@1 died."),
["mobs_mc:magma_cube_big"] = N("@1 was killed by a magma cube."), }
["mobs_mc:wolf"] = N("@1 was killed by a wolf."), }
["mobs_mc:cat"] = N("@1 was killed by a cat."),
["mobs_mc:ocelot"] = N("@1 was killed by an ocelot."), local mobkills = {
["mobs_mc:enderdragon"] = N("@1 was killed by an ender dragon."), ["mobs_mc:zombie"] = N("@1 was slain by Zombie."),
["mobs_mc:wither"] = N("@1 was killed by a wither."), ["mobs_mc:baby_zombie"] = N("@1 was slain by Baby Zombie."),
["mobs_mc:enderman"] = N("@1 was killed by an enderman."), ["mobs_mc:blaze"] = N("@1 was burnt to a crisp while fighting Blaze."),
["mobs_mc:endermite"] = N("@1 was killed by an endermite."), ["mobs_mc:slime"] = N("@1 was slain by Slime."),
["mobs_mc:ghast"] = N("@1 was killed by a ghast."), ["mobs_mc:witch"] = N("@1 was slain by Witch using magic."),
["mobs_mc:guardian_elder"] = N("@1 was killed by an elder guardian."), ["mobs_mc:magma_cube_tiny"] = N("@1 was slain by Magma Cube."),
["mobs_mc:guardian"] = N("@1 was killed by a guardian."), ["mobs_mc:magma_cube_small"] = N("@1 was slain by Magma Cube."),
["mobs_mc:iron_golem"] = N("@1 was killed by an iron golem."), ["mobs_mc:magma_cube_big"] = N("@1 was slain by Magma Cube."),
["mobs_mc:polar_bear"] = N("@1 was killed by a polar_bear."), ["mobs_mc:wolf"] = N("@1 was slain by Wolf."),
["mobs_mc:killer_bunny"] = N("@1 was killed by a killer bunny."), ["mobs_mc:cat"] = N("@1 was slain by Cat."),
["mobs_mc:shulker"] = N("@1 was killed by a shulker."), ["mobs_mc:ocelot"] = N("@1 was slain byn Ocelot."),
["mobs_mc:silverfish"] = N("@1 was killed by a silverfish."), ["mobs_mc:enderdragon"] = N("@1 was slain byn Enderdragon."),
["mobs_mc:skeleton"] = N("@1 was killed by a skeleton."), ["mobs_mc:wither"] = N("@1 was slain by Wither."),
["mobs_mc:stray"] = N("@1 was killed by a stray."), ["mobs_mc:enderman"] = N("@1 was slain byn Enderman."),
["mobs_mc:slime_tiny"] = N("@1 was killed by a slime."), ["mobs_mc:endermite"] = N("@1 was slain byn Endermite."),
["mobs_mc:slime_small"] = N("@1 was killed by a slime."), ["mobs_mc:ghast"] = N("@1 was fireballed by a Ghast."),
["mobs_mc:slime_big"] = N("@1 was killed by a slime."), ["mobs_mc:guardian_elder"] = N("@1 was slain byn Elder Guardian."),
["mobs_mc:spider"] = N("@1 was killed by a spider."), ["mobs_mc:guardian"] = N("@1 was slain by Guardian."),
["mobs_mc:cave_spider"] = N("@1 was killed by a cave spider."), ["mobs_mc:iron_golem"] = N("@1 was slain byn Iron Golem."),
["mobs_mc:vex"] = N("@1 was killed by a vex."), ["mobs_mc:polar_bear"] = N("@1 was slain by Polar Bear."),
["mobs_mc:evoker"] = N("@1 was killed by an evoker."), ["mobs_mc:killer_bunny"] = N("@1 was slain by Killer Bunny."),
["mobs_mc:illusioner"] = N("@1 was killed by an illusioner."), ["mobs_mc:shulker"] = N("@1 was slain by Shulker."),
["mobs_mc:vindicator"] = N("@1 was killed by a vindicator."), ["mobs_mc:silverfish"] = N("@1 was slain by Silverfish."),
["mobs_mc:villager_zombie"] = N("@1 was killed by a zombie villager."), ["mobs_mc:skeleton"] = N("@1 was slain by Skeleton."),
["mobs_mc:husk"] = N("@1 was killed by a husk."), ["mobs_mc:stray"] = N("@1 was slain by Stray."),
["mobs_mc:baby_husk"] = N("@1 was killed by a baby husk."), ["mobs_mc:slime_tiny"] = N("@1 was slain by Slime."),
["mobs_mc:pigman"] = N("@1 was killed by a zombie pigman."), ["mobs_mc:slime_small"] = N("@1 was slain by Slime."),
["mobs_mc:baby_pigman"] = N("@1 was killed by a baby zombie pigman."), ["mobs_mc:slime_big"] = N("@1 was slain by Slime."),
} ["mobs_mc:spider"] = N("@1 was slain by Spider."),
["mobs_mc:cave_spider"] = N("@1 was slain by Cave spider."),
-- Select death message ["mobs_mc:vex"] = N("@1 was slain by Vex."),
local dmsg = function(mtype, ...) ["mobs_mc:evoker"] = N("@1 was slain byn Evoker."),
local r = math.random(1, #msgs[mtype]) ["mobs_mc:illusioner"] = N("@1 was slain byn Illusioner."),
return S(msgs[mtype][r], ...) ["mobs_mc:vindicator"] = N("@1 was slain by Vindicator."),
end ["mobs_mc:villager_zombie"] = N("@1 was slain by Zombie Villager."),
["mobs_mc:husk"] = N("@1 was slain by Husk."),
-- Select death message for death by mob ["mobs_mc:baby_husk"] = N("@1 was slain by Baby Husk."),
local mmsg = function(mtype, ...) ["mobs_mc:pigman"] = N("@1 was slain by Zombie Pigman."),
if mobkills[mtype] then ["mobs_mc:baby_pigman"] = N("@1 was slain by Baby Zombie Pigman."),
return S(mobkills[mtype], ...) }
else
return dmsg("mob_kill", ...) -- Select death message
end local dmsg = function(mtype, ...)
end local r = math.random(1, #msgs[mtype])
return S(msgs[mtype][r], ...)
local last_damages = { } end
minetest.register_on_dieplayer(function(player, reason) -- Select death message for death by mob
-- Death message local mmsg = function(mtype, ...)
local message = minetest.settings:get_bool("mcl_showDeathMessages") if mobkills[mtype] then
if message == nil then return S(mobkills[mtype], ...)
message = true else
end return dmsg("mob_kill", ...)
if message then end
local name = player:get_player_name() end
if not name then
return local last_damages = { }
end
local msg minetest.register_on_dieplayer(function(player, reason)
if last_damages[name] then -- Death message
-- custom message local message = minetest.settings:get_bool("mcl_showDeathMessages")
msg = last_damages[name].message if message == nil then
elseif reason.type == "node_damage" then message = true
local pos = player:get_pos() end
-- Check multiple nodes because players occupy multiple nodes if message then
-- (we add one additional node because the check may fail if the player was local name = player:get_player_name()
-- just barely touching the node with the head) if not name then
local posses = { pos, {x=pos.x,y=pos.y+1,z=pos.z}, {x=pos.x,y=pos.y+2,z=pos.z}} return
local highest_damage = 0 end
local highest_damage_def = nil local msg
-- Show message for node that dealt the most damage if last_damages[name] then
for p=1, #posses do -- custom message
local def = minetest.registered_nodes[minetest.get_node(posses[p]).name] msg = last_damages[name].message
local dmg = def.damage_per_second elseif reason.type == "node_damage" then
if dmg and dmg > highest_damage then local pos = player:get_pos()
highest_damage = dmg -- Check multiple nodes because players occupy multiple nodes
highest_damage_def = def -- (we add one additional node because the check may fail if the player was
end -- just barely touching the node with the head)
end local posses = { pos, {x=pos.x,y=pos.y+1,z=pos.z}, {x=pos.x,y=pos.y+2,z=pos.z}}
if highest_damage_def and highest_damage_def._mcl_node_death_message then local highest_damage = 0
local field = highest_damage_def._mcl_node_death_message local highest_damage_def = nil
local field_msg -- Show message for node that dealt the most damage
if type(field) == "table" then for p=1, #posses do
field_msg = field[math.random(1, #field)] local def = minetest.registered_nodes[minetest.get_node(posses[p]).name]
else local dmg = def.damage_per_second
field_msg = field if dmg and dmg > highest_damage then
end highest_damage = dmg
local textdomain highest_damage_def = def
if highest_damage_def.mod_origin then end
textdomain = highest_damage_def.mod_origin end
else if highest_damage_def and highest_damage_def._mcl_node_death_message then
textdomain = "mcl_death_messages" local field = highest_damage_def._mcl_node_death_message
end local field_msg
-- We assume the textdomain of the death message in the node definition if type(field) == "table" then
-- equals the modname. field_msg = field[math.random(1, #field)]
msg = minetest.translate(textdomain, field_msg, name) else
end field_msg = field
elseif reason.type == "drown" then end
msg = dmsg("drown", name) local textdomain
elseif reason.type == "punch" then if highest_damage_def.mod_origin then
-- Punches textdomain = highest_damage_def.mod_origin
local hitter = reason.object else
local hittername, hittertype, hittersubtype, shooter textdomain = "mcl_death_messages"
-- Custom message end
if last_damages[name] then -- We assume the textdomain of the death message in the node definition
msg = last_damages[name].message -- equals the modname.
-- Unknown hitter msg = minetest.translate(textdomain, field_msg, name)
elseif hitter == nil then end
msg = dmsg("murder_any", name) elseif reason.type == "drown" then
-- Player msg = dmsg("drown", name)
elseif hitter:is_player() then elseif reason.type == "punch" then
hittername = hitter:get_player_name() -- Punches
if hittername ~= nil then local hitter = reason.object
msg = dmsg("murder", name, hittername)
else -- Player was slain by potions
msg = dmsg("murder_any", name) if not hitter then return end
end
-- Mob (according to Common Mob Interface) local hittername, hittertype, hittersubtype, shooter
elseif hitter:get_luaentity()._cmi_is_mob then local hitter_toolname = get_tool_name(hitter:get_wielded_item())
if hitter:get_luaentity().nametag and hitter:get_luaentity().nametag ~= "" then
hittername = hitter:get_luaentity().nametag -- Custom message
end if last_damages[name] then
hittersubtype = hitter:get_luaentity().name msg = last_damages[name].message
if hittername then -- Unknown hitter
msg = dmsg("murder", name, hittername) elseif hitter == nil then
elseif hittersubtype ~= nil and hittersubtype ~= "" then msg = dmsg("murder_any", name)
msg = mmsg(hittersubtype, name) -- Player
else elseif hitter:is_player() then
msg = dmsg("murder_any", name) hittername = hitter:get_player_name()
end if hittername ~= nil then
-- Arrow msg = dmsg("murder", name, hittername, minetest.colorize("#00FFFF", hitter_toolname))
elseif hitter:get_luaentity().name == "mcl_bows:arrow_entity" or hitter:get_luaentity().name == "mobs_mc:arrow_entity" then else
local shooter msg = dmsg("murder_any", name)
if hitter:get_luaentity()._shooter then end
shooter = hitter:get_luaentity()._shooter -- Mob (according to Common Mob Interface)
end elseif hitter:get_luaentity()._cmi_is_mob then
local is_mob = false if hitter:get_luaentity().nametag and hitter:get_luaentity().nametag ~= "" then
local s_ent = shooter and shooter:get_luaentity() hittername = hitter:get_luaentity().nametag
if shooter == nil then end
msg = dmsg("arrow", name) hittersubtype = hitter:get_luaentity().name
elseif shooter:is_player() then if hittername then
msg = dmsg("arrow_name", name, shooter:get_player_name()) msg = dmsg("murder", name, hittername)
elseif s_ent and s_ent._cmi_is_mob then elseif hittersubtype ~= nil and hittersubtype ~= "" then
if s_ent.nametag ~= "" then msg = mmsg(hittersubtype, name)
msg = dmsg("arrow_name", name, shooter:get_player_name()) else
elseif s_ent.name == "mobs_mc:skeleton" then msg = dmsg("murder_any", name)
msg = dmsg("arrow_skeleton", name) end
elseif s_ent.name == "mobs_mc:stray" then -- Arrow
msg = dmsg("arrow_stray", name) elseif hitter:get_luaentity().name == "mcl_bows:arrow_entity" or hitter:get_luaentity().name == "mobs_mc:arrow_entity" and not killed_by_potion then
elseif s_ent.name == "mobs_mc:illusioner" then local shooter
msg = dmsg("arrow_illusioner", name) if hitter:get_luaentity()._shooter then
else shooter = hitter:get_luaentity()._shooter
msg = dmsg("arrow_mob", name) end
end local is_mob = false
else local s_ent = shooter and shooter:get_luaentity()
msg = dmsg("arrow", name) if shooter == nil then
end msg = dmsg("arrow", name)
-- Blaze fireball elseif shooter:is_player() then
elseif hitter:get_luaentity().name == "mobs_mc:blaze_fireball" then msg = dmsg("arrow_name", name, shooter:get_player_name(), minetest.colorize("#00FFFF", get_tool_name(shooter:get_wielded_item())))
if hitter:get_luaentity()._shot_from_dispenser then elseif s_ent and s_ent._cmi_is_mob then
msg = dmsg("fire_charge", name) if s_ent.nametag ~= "" then
else msg = dmsg("arrow_name", name, shooter:get_player_name(), get_tool_name(shooter:get_wielded_item()))
msg = dmsg("blaze_fireball", name) elseif s_ent.name == "mobs_mc:skeleton" then
end msg = dmsg("arrow_skeleton", name)
-- Ghast fireball elseif s_ent.name == "mobs_mc:stray" then
elseif hitter:get_luaentity().name == "mobs_monster:fireball" then msg = dmsg("arrow_stray", name)
msg = dmsg("ghast_fireball", name) elseif s_ent.name == "mobs_mc:illusioner" then
end msg = dmsg("arrow_illusioner", name)
-- Falling else
elseif reason.type == "fall" then msg = dmsg("arrow_mob", name)
msg = dmsg("fall", name) end
-- Other else
elseif reason.type == "set_hp" then msg = dmsg("arrow", name)
if last_damages[name] then end
msg = last_damages[name].message -- Blaze fireball
end elseif hitter:get_luaentity().name == "mobs_mc:blaze_fireball" then
end if hitter:get_luaentity()._shot_from_dispenser then
if not msg then msg = dmsg("fire_charge", name)
msg = dmsg("other", name) else
end msg = dmsg("blaze_fireball", name)
minetest.chat_send_all(msg) end
last_damages[name] = nil -- Ghast fireball
end elseif hitter:get_luaentity().name == "mobs_monster:fireball" then
end) msg = dmsg("ghast_fireball", name)
end
-- dmg_sequence_number is used to discard old damage events -- Falling
local dmg_sequence_number = 0 elseif reason.type == "fall" then
local start_damage_reset_countdown = function (player, sequence_number) msg = dmsg("fall", name)
minetest.after(1, function(playername, sequence_number) -- Other
if last_damages[playername] and last_damages[playername].sequence_number == sequence_number then elseif reason.type == "set_hp" then
last_damages[playername] = nil if last_damages[name] then
end msg = last_damages[name].message
end, player:get_player_name(), sequence_number) end
end end
if not msg then
-- Send a custom death mesage when damaging a player via set_hp or punch. msg = dmsg("other", name)
-- To be called directly BEFORE damaging a player via set_hp or punch. end
-- The next time the player dies due to a set_hp, the message will be shown. minetest.chat_send_all(msg)
-- The player must die via set_hp within 0.1 seconds, otherwise the message will be discarded. last_damages[name] = nil
function mcl_death_messages.player_damage(player, message) end
last_damages[player:get_player_name()] = { message = message, sequence_number = dmg_sequence_number } end)
start_damage_reset_countdown(player, dmg_sequence_number)
dmg_sequence_number = dmg_sequence_number + 1 -- dmg_sequence_number is used to discard old damage events
if dmg_sequence_number >= 65535 then local dmg_sequence_number = 0
dmg_sequence_number = 0 local start_damage_reset_countdown = function (player, sequence_number)
end minetest.after(1, function(playername, sequence_number)
end 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 mcl_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