-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.lua
140 lines (119 loc) · 4.06 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
-- Fall damage
fall = {
'1 hit the ground too hard',
'1 jumped off a cliff',
'1 forgot about fall damage',
"1 fell and couldn't get back up"
}
-- Burning in fire
burn = {
'1 burned to a crisp',
'1 got a little too warm',
'1 got too close to the camp fire',
'1 got nuked'
}
-- Drowning
drown = {
'1 drowned',
'1 ran out of air',
'1 tried to impersonate an anchor',
"1 forgot they weren't a fish"
}
-- Burning in lava
lava = {
'1 thought lava was cool',
'1 tried to swim in lava',
'1 melted in lava',
'1 fell whilst trying to reach that last diamond'
}
-- Killed by other player
pvp = {
'1 was slain by 2',
'1 was killed by 2',
'1 was put to the sword by 2',
'1 lost a PVP battle to 2'
}
-- Killed by mob
mob = {
'1 was slain by 2',
'1 was killed by 2',
"1 got on 2's last nerve",
'1 forgot to feed 2'
}
-- Everything else
other = {
'1 died',
'1 gave up on life',
'1 passed out - permanantly',
'1 did something fatal'
}
function send_death_message(cause, victim, killer)
meta = victim:get_meta()
show_death_messages = meta:get_string('show_death_messages')
if show_death_messages == '' or show_death_messages == 'yes' then
random_selection = cause[math.random(4)]
death_message = string.gsub(random_selection, '1', victim:get_player_name())
if killer then
if killer:is_player() then
death_message = string.gsub(death_message, '2', killer:get_player_name())
else
-- Get entity name, excluding mod name ("mymod:enemy" -> "enemy")
entity_name = killer:get_luaentity().name
index, _ = string.find(entity_name, ':')
entity_name = string.sub(entity_name, index + 1)
death_message = string.gsub(death_message, '2', entity_name)
end
end
minetest.chat_send_all(death_message)
end
end
minetest.register_on_dieplayer(function(player, reason)
if reason.object then
if reason.object:is_player() then
-- Player was killed by player
send_death_message(pvp, player, reason.object)
else
-- Player was killed by mob
send_death_message(mob, player, reason.object)
end
else
if reason.type == 'fall' then
-- Player was killed by fall damage
send_death_message(fall, player)
elseif reason.type == 'drown' then
-- Player drowned
send_death_message(drown, player)
elseif reason.type == 'node_damage' then
if string.match(reason.node, 'lava') then
-- Player burned in lava
send_death_message(lava, player)
elseif string.match(reason.node, 'fire') then
-- Player burned in fire
send_death_message(burn, player)
else
-- Reason not detected, send general death message
send_death_message(other, player)
end
else
send_death_message(other, player)
end
end
end)
minetest.register_chatcommand('toggle_death_messages', {
description = 'Toggles death messages appearing in chat when you die',
func = function(name)
meta = minetest.get_player_by_name(name):get_meta()
show_death_messages = meta:get_string('show_death_messages')
if show_death_messages == '' or show_death_messages == 'yes' then
-- Turn death messages off
meta:set_string('show_death_messages', 'no')
minetest.chat_send_player(name, minetest.colorize('green', 'You will no longer send death messages'))
minetest.log('action', name .. ' disabled their death messages')
else
-- Turn death messages on
meta:set_string('show_death_messages', 'yes')
minetest.chat_send_player(name, minetest.colorize('green', 'You will now send death messages'))
minetest.log('action', name .. ' enabled their death messages')
end
end
})