Clean up code a bit and use variables

This commit is contained in:
4Evergreen4 2014-03-17 15:10:44 -04:00
parent 81e34709d6
commit eb60e2fdcf

View File

@ -5,19 +5,25 @@ local mname = "death_messages"
-----------------------------------------------------------------------------------------------
minetest.register_on_dieplayer(function(player)
local player_name = player:get_player_name()
if minetest.is_singleplayer() then
player_name = "You"
end
-- Death by lava
if minetest.get_node(player:getpos(name)).name == "default:lava_source" or minetest.get_node(player:getpos(name)).name == "default:lava_flowing" then
minetest.chat_send_all(player:get_player_name().." melted into a ball of fire.")
local nodename = minetest.get_node(player:getpos()).name
if nodename == "default:lava_source" or nodename == "default:lava_flowing" then
minetest.chat_send_all(player_name .. " melted into a ball of fire.")
-- Death by drowning
elseif minetest.get_node(player:getpos(name)).name == "default:water_source" or minetest.get_node(player:getpos(name)).name == "default:water_flowing" then
minetest.chat_send_all(player:get_player_name().." ran out of air.")
elseif nodename == "default:water_source" or nodename == "default:water_flowing" then
minetest.chat_send_all(player_name .. " ran out of air.")
--Death by fire
elseif minetest.get_node(player:getpos(name)).name == "fire:basic_flame" then
minetest.chat_send_all(player:get_player_name().." burned up.")
elseif nodename == "fire:basic_flame" then
minetest.chat_send_all(player_name .. " burned up.")
--Death by something else
else
minetest.chat_send_all(player:get_player_name().." died.")
minetest.chat_send_all(player_name .. " died.")
end
end)
-----------------------------------------------------------------------------------------------