mirror of
https://github.com/appgurueu/deathlist.git
synced 2024-10-04 00:03:04 +02:00
rolling-4
This commit is contained in:
parent
5298d0df20
commit
5511e3ab7f
35
Readme.md
35
Readme.md
@ -2,9 +2,42 @@
|
||||
A mod displaying a colored list of recent kills/deaths and the causes(killer, used item).
|
||||
|
||||
## About
|
||||
|
||||
Depends on [`modlib`](https://github.com/appgurueu/modlib) and - depending on your configuration - also other mods. If you use the default configuration, it depends on `default` and `fire`.
|
||||
**If there are other mods registering `on_punchplayer` or `on_hp_change` handlers, add them to the dependency list to make sure they execute before `deathlist`.**
|
||||
**Note: If there are other mods registering `on_punchplayer` or `on_hp_change` handlers, add them to the dependency list to make sure they execute before `deathlist`.**
|
||||
Licensed under MIT.
|
||||
|
||||
## Screenshot
|
||||
|
||||
![Screenshot](https://raw.githubusercontent.com/appgurueu/deathlist/master/screenshot.png)
|
||||
|
||||
## API
|
||||
|
||||
`deathlist` provides a few internal functions, but the most common way to trigger a custom message is passing a custom type to `set_hp`:
|
||||
|
||||
```lua
|
||||
-- example, kills player
|
||||
player:set_hp(0, {
|
||||
-- killer, required
|
||||
killer = {
|
||||
-- name, required
|
||||
name = "singleplayer",
|
||||
-- color, optional integer, will be completed if valid playername
|
||||
color = 0xFFFFFF
|
||||
},
|
||||
-- method, required
|
||||
method = {
|
||||
-- image of used method, required
|
||||
image = "blank.png",
|
||||
-- name for logging, optional
|
||||
name = "blank"
|
||||
}
|
||||
-- victim, optional overrides
|
||||
victim = {
|
||||
-- name, optional
|
||||
name = "singleplayer",
|
||||
-- color, optional
|
||||
color = 0xFFFFFF
|
||||
}
|
||||
})
|
||||
```
|
101
main.lua
101
main.lua
@ -1,22 +1,36 @@
|
||||
modlib.log.create_channel("deathlist") -- Create modlib.log channel
|
||||
|
||||
local coordinate={type="table",
|
||||
local coordinate={
|
||||
type="table",
|
||||
children={
|
||||
x={type="number"},
|
||||
y={type="number"}
|
||||
}}
|
||||
local color={type="table",
|
||||
}
|
||||
}
|
||||
local color={
|
||||
type="table",
|
||||
children={
|
||||
r={type="number", interval={0,255}},
|
||||
g={type="number", interval={0,255}},
|
||||
b={type="number", interval={0,255}}
|
||||
}}
|
||||
local node_caused={children={
|
||||
}
|
||||
}
|
||||
|
||||
local node_caused={
|
||||
children={
|
||||
color=color,
|
||||
method={type="string"},
|
||||
nodes={type="table", keys={type="string"}, values={type="table", keys={possible_values={name=true, color=true, method=true}}}},
|
||||
}}
|
||||
local config=modlib.conf.import("deathlist",{
|
||||
nodes={
|
||||
type="table",
|
||||
keys={type="string"},
|
||||
values={
|
||||
type="table",
|
||||
keys={possible_values={name=true, color=true, method=true}}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
local config=modlib.conf.import("deathlist", {
|
||||
type="table",
|
||||
children={
|
||||
max_messages={type="number", interval={1}},
|
||||
@ -205,26 +219,53 @@ function add_node_kill_message(killing_node, cause, victim) --Drowning & Node Da
|
||||
if method=="generate" then
|
||||
method=modlib.minetest.get_node_inventory_image(killing_node.name)
|
||||
end
|
||||
add_kill_message({name=override.name or killing_node.description,
|
||||
color=override.color or environmental_reasons[cause].color},
|
||||
method,
|
||||
victim)
|
||||
add_kill_message({
|
||||
name=override.name or killing_node.description,color=override.color or environmental_reasons[cause].color
|
||||
}, method, victim)
|
||||
end
|
||||
|
||||
if enable_environmental then
|
||||
minetest.register_on_player_hpchange(
|
||||
function(player, hp_change, reason)
|
||||
|
||||
function on_player_hpchange(player, hp_change, reason)
|
||||
local type_type = type(reason.type)
|
||||
local type = reason.type
|
||||
if type == "punch" then
|
||||
return -- punches are handled by on_punchplayer
|
||||
end
|
||||
if player:get_hp() > 0 and player:get_hp()+hp_change <= 0 then
|
||||
local victim={name=player:get_player_name(), color=modlib.player.get_color_int(player)}
|
||||
if reason.type=="fall" then
|
||||
if type == "set_hp" and reason.killer and reason.method then
|
||||
if reason.victim then
|
||||
victim.name = reason.victim.name or victim.name
|
||||
victim.color = reason.victim.color or victim.color
|
||||
end
|
||||
local killer = {
|
||||
name = reason.killer.name,
|
||||
color = reason.killer.color
|
||||
}
|
||||
if not killer.color then
|
||||
local killer_obj = minetest.get_player_by_name(killer.name)
|
||||
if killer_obj then
|
||||
killer.color = modlib.player.get_color_int(killer_obj)
|
||||
end
|
||||
end
|
||||
add_kill_message(killer, reason.method.image, victim)
|
||||
modlib.log.write("deathlist", "Player "..killer.name.." killed "..victim.name.." using "..(reason.method.name or reason.method.image))
|
||||
return
|
||||
end
|
||||
if enable_environmental then
|
||||
if type=="fall" then
|
||||
add_environmental_kill_message("falling", victim)
|
||||
modlib.log.write("deathlist","Player "..victim.name.." died due to falling")
|
||||
elseif reason.type=="drown" then
|
||||
modlib.log.write("deathlist", "Player "..victim.name.." died due to falling")
|
||||
return
|
||||
end
|
||||
if type=="drown" then
|
||||
local eye_pos=vector.add(player:get_pos(), {x=0, z=0, y=player:get_properties().eye_height})
|
||||
local drowning_node=minetest.registered_nodes[minetest.get_node(eye_pos).name]
|
||||
add_node_kill_message(drowning_node, "drowning", victim)
|
||||
modlib.log.write("deathlist","Player "..victim.name.." died due to drowning in "..drowning_node.name)
|
||||
elseif reason.type=="node_damage" then
|
||||
modlib.log.write("deathlist", "Player "..victim.name.." died due to drowning in "..drowning_node.name)
|
||||
return
|
||||
end
|
||||
if type=="node_damage" then
|
||||
local killing_node_feet=minetest.registered_nodes[minetest.get_node(player:get_pos()).name]
|
||||
local eye_pos=vector.add(player:get_pos(), {x=0, z=0, y=player:get_properties().eye_height})
|
||||
local killing_node_head=minetest.registered_nodes[minetest.get_node(eye_pos).name]
|
||||
@ -234,16 +275,17 @@ if enable_environmental then
|
||||
end
|
||||
add_node_kill_message(killing_node, "node_damage", victim)
|
||||
modlib.log.write("deathlist","Player "..victim.name.." died due to node damage of "..killing_node.name)
|
||||
elseif reason.type ~= "punch" and enable_unknown then
|
||||
return
|
||||
end
|
||||
end
|
||||
if enable_unknown then
|
||||
add_environmental_kill_message("unknown", victim)
|
||||
modlib.log.write("deathlist","Player "..victim.name.." died for unknown reasons.")
|
||||
modlib.log.write("deathlist", "Player "..victim.name.." died for unknown reasons.")
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
|
||||
function on_punchplayer(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
|
||||
if player:get_hp() > 0 and player:get_hp()-damage <= 0 and hitter then
|
||||
local wielded_item_name=hitter:get_wielded_item():get_name()
|
||||
local tool
|
||||
@ -255,6 +297,11 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch,
|
||||
local killer={name=hitter:get_player_name(), color=modlib.player.get_color_int(hitter)}
|
||||
local victim={name=player:get_player_name(), color=modlib.player.get_color_int(player)}
|
||||
add_kill_message(killer,tool,victim)
|
||||
modlib.log.write("deathlist","Player "..killer.name.." killed "..victim.name.." using "..wielded_item_name)
|
||||
modlib.log.write("deathlist", "Player "..killer.name.." killed "..victim.name.." using "..wielded_item_name)
|
||||
end
|
||||
end )
|
||||
end
|
||||
|
||||
minetest.register_on_mods_loaded(function()
|
||||
minetest.register_on_player_hpchange(on_player_hpchange)
|
||||
minetest.register_on_punchplayer(on_punchplayer)
|
||||
end)
|
3
mod.conf
3
mod.conf
@ -1,3 +1,4 @@
|
||||
name=deathlist
|
||||
description=Adds a kill history.
|
||||
description=Adds a kill history
|
||||
depends=modlib, default, fire
|
||||
optional_depends=3d_armor
|
Loading…
Reference in New Issue
Block a user