death_messages/init.lua

304 lines
9.7 KiB
Lua
Raw Normal View History

--[[
death_messages - A Minetest mod which sends a chat message when a player dies.
Copyright (C) 2016 EvergreenTree
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
--]]
--------------------------------------------------------------------------------
local title = "Death Messages"
local version = "0.1.4"
local mname = "death_messages"
--------------------------------------------------------------------------------
dofile(minetest.get_modpath("death_messages").."/settings.txt")
--------------------------------------------------------------------------------
-- A table of quips for death messages. The first item in each sub table is the
-- default message used when RANDOM_MESSAGES is disabled.
local messages = {}
2018-09-07 20:20:39 +02:00
-- Another one to avoid double death messages
local whacked = {}
local logfile = minetest.get_worldpath() .. "/death_logs.txt"
-- Fill this table with sounds
local sounds = {
[1] = "death_messages_player_1",
[2] = "death_messages_player_2",
}
2020-07-18 01:53:19 +02:00
-- Translation wrapper
local S = minetest.get_translator()
-- Lava death messages
messages.lava = {
2020-07-18 01:53:19 +02:00
"@1 thought lava was cool.",
"@1 felt an urgent need to touch lava.",
"@1 fell in lava.",
"@1 died in lava.",
"@1 didn't know lava was very hot.",
"@1 destroyed Sauron's ring.",
"@1 melted into a ball of fire.",
"@1 couldn't resist that warm glow of lava.",
"@1 dug straight down.",
}
-- Drowning death messages
messages.water = {
2020-07-18 01:53:19 +02:00
"@1 lacked oxygen.",
"@1 ran out of air.",
"@1 tried to impersonate an anchor.",
"@1 forgot (s)he was not a fish.",
"@1 forgot they needed to breath underwater.",
"@1 isn't good at swimming.",
"@1 looked for the secret of the Unicorn.",
"@1 forgot their scaphander.",
"@1 failed at swimming lessons.",
"@1 blew one too many bubbles.",
}
-- Burning death messages
messages.fire = {
2020-07-18 01:53:19 +02:00
"@1 was a bit too hot.",
"@1 was too close to the fire.",
"@1 just got roasted.",
"@1 got burnt.",
"@1 thought (s)he was the human torch.",
"@1 started a fire.",
"@1 burned to a crisp.",
"@1 got a little too warm.",
"@1 got too close to the camp fire.",
"@1 just got roasted, hotdog style.",
"@1 was set aflame. More light that way.",
2018-09-07 20:20:39 +02:00
}
-- Acid death messages
messages.acid = {
2020-07-18 01:53:19 +02:00
"@1 now has parts of him/her missing.",
"@1 discovered that acid is fun.",
"@1 put his/her head where it melted.",
"@1 discovered that his/her body in acid, it's like sugar in water.",
"@1 thought (s)he was swimming in apple juice.",
"@1 gave his/her body to make an infusion.",
"@1 drowned into the wrong liquid.",
"@1 tried to test his/her body's solubility in acid.",
2018-09-07 20:20:39 +02:00
}
-- Quicksands death messages
messages.sand = {
2020-07-18 01:53:19 +02:00
"@1 learned that sand is less fluid than water.",
"@1 joined the mummies.",
"@1 got buried.",
"@1 choosen to become a fossil.",
}
-- Other death messages
messages.other = {
2020-07-18 01:53:19 +02:00
"@1 did something fatal to himself/herself.",
"@1 died.",
"@1 left this world.",
"@1 reached miner's heaven.",
"@1 lost him/her life.",
"@1 saw the light.",
"@1 fell from a bit too high.",
"@1 slipped on a banana skin.",
"@1 wanted to test his/her super powers.",
"@1 gave up on life.",
"@1 is somewhat dead now.",
"@1 passed out permanently.",
"@1 died under very mysterious conditions.",
"@1 died in very mysterious circumstances.",
"@1 passed away.",
}
2018-09-07 20:20:39 +02:00
-- Whacking death messages
messages.whacking = {
2020-07-18 01:53:19 +02:00
"@1 got whacked by @2.",
"@1's grave was dug by @2.",
"@1 got recycled by @2.",
"@1 surely annoyed @2.",
"@1 can't have any more offspring because of @2.",
"@1 got beaten up by @2.",
"@1 had his suffering cut short by @2.",
"@1 died in excruciating pain because of @2's fault.",
"@1 spent his last moments in the company of @2.",
"@1's lineage was extinguished by @2.",
"@1 wasn't as strong as @2.",
2018-09-07 20:20:39 +02:00
-- Need to fill
}
messages.monsters_whacking = {
2020-07-18 01:53:19 +02:00
"@1 got whacked by a @2.",
"Darwin said : @1 was less adapted than a @2.",
"@1 was transformed into a doormat by a @2.",
"@1 thought (s)he was stronger than a @2.",
"@1 got kicked up by a @2. Next up...",
"@1 felt well that he/she could not do anything against a @2.",
"@1 versus @2? It's going bad!",
"@1 got a memorable spanking from @2.",
"@1 thought to be able to tame a @2? History shows he was wrong.",
"@1 didn't have the right reflex in front of a @2.",
"But what did @1 imagine versus a @2? Rest her soul.",
"@1 got shipped off to the afterlife in a hurry by a @2.",
"@1's attempt to reason with a @2 didn't exactly pay off.",
"@1 was severely shattered by a dirty @2.",
2018-09-07 20:20:39 +02:00
-- Need to fill
}
-- Monsters
local monsters = {
["mobs_monster:fireball"] = "dungeon master",
["mobs_monster:dungeon_master"] = "dungeon master",
["mobs_monster:spider"] = "spider",
["mobs_monster:sand_monster"] = "sand monster",
["mobs_animal:cow"] = "cow",
["creeper:creeper"] = "creeper",
["pmobs:dog"] = "dog",
["slimes:greenbig"] = "big green slim",
["slimes:greenmedium"] = "medium green slim",
["slimes:greensmall"] = "small green slim",
["slimes:lavabig"] = "big lava slim",
["slimes:lavamedium"] = "medium lava slim",
["slimes:lavasmall"] = "small lava slim",
["pmobs:yeti"] = "yeti",
["pmobs:snowball"] = "yeti",
["pmobs:npc"] = "npc",
["pmobs:npc_female"] = "female npc",
["mobs_monster:oerkki"] = "oerkki",
["mobs_monster:stone_monster"] = "stone monster",
["mobs_monster:dirt_monster"] = "dirt monster",
["mobs_animal:goat"] = "goat",
["pmobs:wolf"] = "wolf",
["mobs_monster:tree_monster"] = "tree monster",
["mobs_monster:mese_arrow"] = "mese monster",
["zombie:zombie"] = "zombie",
["mobs_monster:minotaur"] = "minotaur",
["mobs_animal:pumba"] = "warthog",
2018-09-07 20:20:39 +02:00
["tsm_pyramids:mummy"] = "mummy",
["mobs_sharks:shark_lg"] = "large shark",
["mobs_sharks:shark_md"] = "medium shark",
["mobs_sharks:shark_sm"] = "small shark",
["mobs_crocs:crocodile"] = "crocodile",
["mobs_crocs:crocodile_float"] = "crocodile",
["mobs_crocs:crocodile_swim"] = "crocodile",
["mobs_monster:lava_flan"] = "lava flan",
["mobs_animal:bee"] = "bee",
["mobs_animal:bunny"] = "evil bunny",
-- ["mobs:pumpking"] = "pumpking",
-- ["mobs:pumpboom"] = "pumpboom",
-- ["mobs:mese_dragon"] = "mese_dragon",
2018-09-07 20:20:39 +02:00
}
local function broadcast_death(msg)
minetest.chat_send_all(msg)
local logfilep = io.open(logfile, "a")
logfilep:write(os.date("[%Y-%m-%d %H:%M:%S] ") .. msg .. "\n")
logfilep:close()
if irc then
irc.say(msg)
2018-09-07 20:20:39 +02:00
end
end
local function sound_play_all(dead)
for _, p in ipairs(minetest.get_connected_players()) do
local player_name = p:get_player_name()
if player_name and player_name ~= dead then
minetest.sound_play("death_messages_people_1",{to_player=player_name, gain=1})
2018-09-07 20:20:39 +02:00
end
end
end
minetest.register_on_punchplayer(function(player, hitter, time,
tool_caps, dir, damage)
if player:get_hp() - damage <= 0 and not whacked[player:get_player_name()] then
local player_name = player:get_player_name()
local death_message
if hitter:is_player() then
2020-07-18 01:53:19 +02:00
death_message = string.format(S(messages.whacking[math.random(1,#messages.whacking)], player_name, hitter:get_player_name()))
2018-09-07 20:20:39 +02:00
else
local entity_name = monsters[hitter:get_luaentity().name] or "monster"
2020-07-18 01:53:19 +02:00
death_message = string.format(S(messages.monsters_whacking[math.random(1, #messages.monsters_whacking)], player_name, entity_name))
2018-09-07 20:20:39 +02:00
end
broadcast_death(death_message)
minetest.sound_play(sounds[math.random(1,#sounds)],{to_player=player_name,gain=1})
sound_play_all(player_name)
2018-09-07 20:20:39 +02:00
whacked[player_name] = true
end
end)
minetest.register_on_leaveplayer(function(player)
whacked[player:get_player_name()] = nil
end)
minetest.register_on_respawnplayer(function(player)
whacked[player:get_player_name()] = nil
end)
local function get_message(mtype)
if RANDOM_MESSAGES then
return messages[mtype][math.random(1, #messages[mtype])]
else
return messages[mtype][1] -- 1 is the index for the non-random message
end
end
minetest.register_on_dieplayer(function(player)
local player_name = player:get_player_name()
local node = minetest.registered_nodes[minetest.get_node(player:get_pos()).name]
if minetest.is_singleplayer() then
player_name = "You"
end
2018-09-07 20:20:39 +02:00
local death_message = ""
if not whacked[player_name] then
-- Death by lava
if node.groups.lava ~= nil then
death_message = get_message("lava")
-- Death by acid
elseif node.groups.acid ~= nil then
death_message = get_message("acid")
-- Death by drowning
elseif player:get_breath() == 0 then
if node.groups.water ~= nil then
death_message = get_message("water")
-- Death in quicksand
elseif node.name == "nalc:sand_source" or node.name == "nalc:sand_flowing" then
death_message = get_message("sand")
end
-- Death by fire
elseif node.name == "fire:basic_flame" then
death_message = get_message("fire")
-- Death by something else
2018-09-07 20:20:39 +02:00
else
death_message = get_message("other")
2018-09-07 20:20:39 +02:00
end
-- Actually tell something
2020-07-18 01:53:19 +02:00
death_message = string.format(S(death_message, player_name))
2018-09-07 20:20:39 +02:00
broadcast_death(death_message)
minetest.sound_play(sounds[math.random(1,#sounds)], {to_player=player_name,gain=1})
2018-09-07 20:20:39 +02:00
sound_play_all(player_name)
whacked[player_name] = true
end
end)
--------------------------------------------------------------------------------
2014-03-17 18:23:56 +01:00
print("[Mod] "..title.." ["..version.."] ["..mname.."] Loaded...")
--------------------------------------------------------------------------------