init.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. --[[
  2. death_messages - A Minetest mod which sends a chat message when a player dies.
  3. Copyright (C) 2016 EvergreenTree
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. --]]
  15. -----------------------------------------------------------------------------------------------
  16. local title = "Death Messages"
  17. local version = "1.1"
  18. local mname = "death_messages"
  19. -----------------------------------------------------------------------------------------------
  20. dofile(minetest.get_modpath("death_messages").."/settings.txt")
  21. -----------------------------------------------------------------------------------------------
  22. death_messages = {}
  23. death_messages.messages = {} -- Contains tables of messages for different ways to die.
  24. death_messages.punched = {} -- (key) was last punched by (value)
  25. death_messages.punchedWith = {} -- (key) was last punched with an item whose description is (value)
  26. death_messages.punched_forget = {} -- Forget who punched (key) after (value) seconds
  27. death_messages.mightBeFalling = {} -- (key) was falling fast enough to take damage (value) seconds ago.
  28. death_messages.mob_names = {
  29. --["mod:entity"]="an entity"
  30. ["mobs_monster:oerkki"]="the dreaded Oerkki",
  31. ["mobs_monster:fireball"] = "an angry dungeon_master",
  32. ["mobs_monster:mese_arrow"] = "an angry mese_monster",
  33. ["zombies:1arm"] = "a hungry zombie",
  34. ["zombies:crawler"] = "a crawling zombie",
  35. ["zombies:normal"] = "a hungry zombie",
  36. ["slimes:lavasmall"]="a deadly lava slime",
  37. ["slimes:lavamedium"]="a deadly lava slime",
  38. ["slimes:lavabig"]="a deadly lava slime",
  39. ["slimes:greensmall"]="a deadly jungle slime",
  40. ["slimes:greenmedium"]="a deadly jungle slime",
  41. ["slimes:greenbig"]="a deadly jungle slime",
  42. ["dmobs:golem"]="a wandering golem",
  43. ["dmobs:golem_friendly"]="a golem",
  44. }
  45. local name
  46. minetest.register_on_punchplayer(function(player, hitter)
  47. name = player:get_player_name()
  48. if hitter then
  49. if hitter:is_player() then
  50. if hitter:get_player_name() == name then return end -- Some mods like to have the player punch themself for some odd reason.
  51. death_messages.punched[name] = hitter:get_player_name()
  52. death_messages.punchedWith[name] = hitter:get_wielded_item():get_name()
  53. if death_messages.punchedWith[name] == "" or not death_messages.punchedWith[name] then
  54. death_messages.punchedWith[name] = "bare hands"
  55. end
  56. if minetest.registered_items[death_messages.punchedWith[name]] then
  57. if minetest.registered_items[death_messages.punchedWith[name]].description then
  58. death_messages.punchedWith[name] = minetest.registered_items[death_messages.punchedWith[name]].description
  59. end
  60. end
  61. elseif hitter:get_luaentity() then
  62. local entname = hitter:get_luaentity().name
  63. if type(entname) ~= "string" then return end
  64. if death_messages.mob_names[entname] then
  65. death_messages.punched[name] = death_messages.mob_names[entname]
  66. else
  67. if string.split(entname, ":")[2] then
  68. if hitter:get_luaentity()._cmi_is_mob then
  69. death_messages.punched[name] = "an angry "..(string.split(entname, ":")[2]):gsub("_", " ")
  70. else
  71. death_messages.punched[name] = string.split(entname, ":")[2]
  72. end
  73. else
  74. death_messages.punched[name] = entname
  75. end
  76. end
  77. death_messages.punchedWith[name] = ""
  78. else
  79. return
  80. end
  81. else
  82. death_messages.punched[name] = nil
  83. end
  84. death_messages.punched_forget[name] = 2.5
  85. end)
  86. -- Lava death messages
  87. death_messages.messages.lava = {
  88. "(player) was melted.",
  89. "(player) was incinerated.",
  90. "(player) was sacrificed to a volcano god.",
  91. "(player) jumped into a volcano.",
  92. "(player) joined the fossil record.",
  93. "(player) went for a swim in lava.",
  94. "(player) likes to play in magma.",
  95. "(player) melted into a ball of fire.",
  96. "(player) thought that lava was cool.",
  97. "(player) didn't know that lava was hot.",
  98. }
  99. -- Drowning death messages
  100. death_messages.messages.water = {
  101. "(player) forgot to breathe.",
  102. "(player) learned they aren't a fish.",
  103. "(player) didn't float.",
  104. "(player) ran out of air.",
  105. "(player) probably wasn't a witch, after all...",
  106. "(player) is sleeping with the fish.",
  107. "(player) tried to become a fish, and failed.",
  108. "(player) blew one too many bubbles.",
  109. "(player) drowned.",
  110. }
  111. -- Burning death messages
  112. death_messages.messages.fire = {
  113. "(player) couldn't put the fire out.",
  114. "(player) was burnt to a crisp.",
  115. "(player) walked into the flames.",
  116. "(player) was consumed by a blazing pyre.",
  117. "(player) got too close to the campfire.",
  118. "(player) just got roasted, literally.",
  119. "(player) must have been a witch.",
  120. "(player) became ash.",
  121. "(player) was involuntarily cremated.",
  122. "Someone should have told (player) not to play with matches.",
  123. }
  124. -- Other death messages
  125. death_messages.messages.other = {
  126. "(player) died.",
  127. "(player) was slain.",
  128. "(player) was eviscerated.",
  129. "(player) was destroyed.",
  130. "(player)'s body was mangled.",
  131. "(player)'s vital organs were ruptured.",
  132. "(player) was removed from the world.",
  133. "R.I.P (player).",
  134. "(player) expired.",
  135. "(player) is aliven't.",
  136. "(player) had a bad time.",
  137. "(player)'s lifetime ran out.",
  138. "(player) joined the black parade.",
  139. "(player) has gone to a better place.",
  140. "(player) no longer resides among the living.",
  141. "(player)'s soul is taking the ferry across Acheron.",
  142. "(player) found out whether or not there's an afterlife. They won't be telling us, though.",
  143. }
  144. -- Killed by a mob
  145. death_messages.messages.killed_mob = {
  146. "(player) was slain by (killer).",
  147. "(player) was eviscerated by (killer).",
  148. "(player) was murdered by (killer).",
  149. "(player)'s face was torn off by (killer).",
  150. "(player) entrails were ripped out by (killer).",
  151. "(player) was destroyed by (killer).",
  152. "(player)'s skull was crushed by (killer).",
  153. "(player) got massacred by (killer).",
  154. "(player) got impaled by (killer).",
  155. "(player) was torn in half by (killer).",
  156. "(player) was decapitated.",
  157. "(player) let their arms get torn off by (killer).",
  158. "(player) watched their innards become outards by (killer).",
  159. "(player) was brutally dissected by (killer).",
  160. "(player)'s extremities were detached by (killer).",
  161. "(player)'s body was mangled by (killer).",
  162. "(player)'s vital organs were ruptured by (killer).",
  163. "(player) was turned into a pile of flesh by (killer).",
  164. "(player) was removed from the world by (killer).",
  165. "(player) got snapped in half by (killer).",
  166. "(player) was cut down the middle by (killer).",
  167. "(player) was chopped up by (killer).",
  168. "(player)'s plea for death was answered by (killer).",
  169. "(player)'s meat was ripped of the bone by (killer).",
  170. "(player)'s flailing about was finally stopped by (killer).",
  171. "(player) had their head removed by (killer).",
  172. "(player) was killed by (killer).",
  173. "(player) was slaughtered by (killer).",
  174. "(player) was unceremoniously terminated by (killer).",
  175. "(player) tasted the wrath of (killer).",
  176. "(player)'s continued existence was cancelled by (killer).",
  177. "(player) tried to escape from (killer).",
  178. }
  179. -- ...killed by a player.
  180. death_messages.messages.killed_player = {
  181. "(killer) destroyed (player) with their (weapon).",
  182. "(killer)'s (weapon) became the bane of (player).",
  183. "(killer) put an end to (player)'s miserable existence.",
  184. "(killer) has removed (player) from the ranks of the living.",
  185. "(player) tasted the wrath of (killer)'s (weapon).",
  186. "(player) died by (killer)'s (weapon)",
  187. }
  188. -- Misc. node damage
  189. death_messages.messages.node = {
  190. "(player) wandered into a very uncomfortable place.",
  191. "(player) got themselves into a sticky situation.",
  192. "(player) shouldn't have touched that.",
  193. "(player) ignored the \"DANGER! KEEP OUT!\" sign.",
  194. }
  195. -- Fall
  196. death_messages.messages.fall = {
  197. "(player) became a pancake.",
  198. "(player) fell to their doom.",
  199. "(player) shattered into pieces.",
  200. "(player) can't be put back together again.",
  201. "(player) didn't bounce.",
  202. "(player) took a leap of faith, and was sorely disappointed.",
  203. "(player) was destroyed by gravity.",
  204. "(player) faceplanted the ground.",
  205. "(player) left a small crater.",
  206. "(player)'s parachute failed.",
  207. "(player) went \"splat\".",
  208. "\"Don't jump!\" they cried, but (player) jumped.",
  209. "It wasn't the fall that killed (player), it was the sudden stop at the end.",
  210. }
  211. -- Murder by fall
  212. death_messages.messages.pushed = {
  213. "(killer) pushed (player) to their doom.",
  214. "(player) fell to their death at the hands of (killer).",
  215. "(player) was pushed from a great height by (killer)",
  216. "(player) was taught the way of Spartans by (killer)",
  217. }
  218. minetest.register_globalstep(function(dtime)
  219. for _,player in pairs(minetest.get_connected_players()) do
  220. name = player:get_player_name()
  221. if player:get_player_velocity().y < -13 then
  222. death_messages.mightBeFalling[name] = 2.0
  223. elseif death_messages.mightBeFalling[name] then
  224. if death_messages.mightBeFalling[name] > 0 then
  225. death_messages.mightBeFalling[name] = death_messages.mightBeFalling[name] - dtime
  226. else
  227. death_messages.mightBeFalling[name] = nil
  228. end
  229. end
  230. if death_messages.punched_forget[name] then
  231. if death_messages.punched_forget[name] > 0 then
  232. death_messages.punched_forget[name] = death_messages.punched_forget[name] - dtime
  233. else
  234. death_messages.punched[name] = nil
  235. death_messages.punchedWith[name] = nil
  236. death_messages.punched_forget[name] = nil
  237. end
  238. end
  239. end
  240. end)
  241. function death_messages.get_message(mtype)
  242. if RANDOM_MESSAGES then
  243. return death_messages.messages[mtype][math.random(1, #(death_messages.messages[mtype]))]
  244. else
  245. return death_messages.messages[1] -- 1 is the index for the non-random message
  246. end
  247. end
  248. function death_messages.reset_watchers(player)
  249. name = player:get_player_name()
  250. death_messages.punched[name] = nil
  251. death_messages.punched_forget[name] = nil
  252. death_messages.punchedWith[name] = nil
  253. death_messages.mightBeFalling[name] = nil
  254. end
  255. minetest.register_on_leaveplayer(death_messages.reset_watchers)
  256. minetest.register_on_dieplayer(function(player)
  257. name = player:get_player_name()
  258. local node = minetest.registered_nodes[minetest.get_node(player:getpos()).name]
  259. local message
  260. --Death by entity
  261. if death_messages.punched[name] and death_messages.punched[name] ~= name then
  262. if death_messages.mightBeFalling[name] and death_messages.punched_forget[name] and (death_messages.mightBeFalling[name] > death_messages.punched_forget[name] - 0.5) then
  263. message = death_messages.get_message("pushed")
  264. elseif death_messages.punchedWith[name] and death_messages.punchedWith[name] ~= "" then
  265. message = death_messages.get_message("killed_player")
  266. message = string.gsub(message, "%(weapon%)", death_messages.punchedWith[name])
  267. else
  268. message = death_messages.get_message("killed_mob")
  269. end
  270. message = string.gsub(message, "%(player%)", name)
  271. message = string.gsub(message, "%(killer%)", death_messages.punched[name])
  272. minetest.chat_send_all(minetest.colorize("#FF0000",(message)))
  273. -- Death by drowning
  274. elseif player:get_breath() == 0 then
  275. message = death_messages.get_message("water")
  276. minetest.chat_send_all(minetest.colorize("#FF0000",(string.gsub(message, "%(player%)", name))))
  277. -- Death by lava
  278. elseif node.groups.lava then
  279. message = death_messages.get_message("lava")
  280. minetest.chat_send_all(minetest.colorize("#FF0000",(string.gsub(message, "%(player%)", name))))
  281. -- Death by fall
  282. elseif death_messages.mightBeFalling[name] then
  283. message = death_messages.get_message("fall")
  284. minetest.chat_send_all(minetest.colorize("#FF0000",(string.gsub(message, "%(player%)", name))))
  285. -- Death by fire
  286. elseif string.find(node.name, "fire") or string.find(node.name, "flame") or node.groups.igniter then
  287. message = death_messages.get_message("fire")
  288. minetest.chat_send_all(minetest.colorize("#FF0000",(string.gsub(message, "%(player%)", name))))
  289. -- Death by node
  290. elseif node.damage_per_second and node.damage_per_second > 1 then
  291. message = death_messages.get_message("node")
  292. minetest.chat_send_all(minetest.colorize("#FF0000",(string.gsub(message, "%(player%)", name))))
  293. --Death by GNU GNU
  294. else
  295. message = death_messages.get_message("other")
  296. minetest.chat_send_all(minetest.colorize("#FF0000",(string.gsub(message, "%(player%)", name))))
  297. end
  298. death_messages.reset_watchers(player)
  299. end)
  300. -----------------------------------------------------------------------------------------------
  301. print("[Mod] "..title.." ["..version.."] ["..mname.."] Loaded...")
  302. -----------------------------------------------------------------------------------------------