mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Track death messages
This commit is contained in:
parent
4a135d00f6
commit
fd4a79c252
3 changed files with 56 additions and 0 deletions
|
@ -476,6 +476,9 @@ function player_fns.nickname_of_peer(peer_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
function player_fns.get_player_data_by_local_entity_id(entity)
|
function player_fns.get_player_data_by_local_entity_id(entity)
|
||||||
|
if entity == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
return ctx.player_data_by_local_entity[entity]
|
return ctx.player_data_by_local_entity[entity]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
local adjust_damage = dofile_once("mods/quant.ew/files/system/damage/cbs/adjust_damage.lua").adjust_damage
|
||||||
|
|
||||||
|
-- Called on clients when they get damage and redirects it to the host's hp over the network, ignoring any resists.
|
||||||
|
function damage_received(damage, message, entity_thats_responsible, is_fatal, projectile_thats_responsible)
|
||||||
|
-- Damage the host
|
||||||
|
CrossCall("ew_damage_message", message, entity_thats_responsible)
|
||||||
|
end
|
|
@ -18,6 +18,12 @@ local status_effects = status_effects
|
||||||
|
|
||||||
local module = {}
|
local module = {}
|
||||||
|
|
||||||
|
local last_damage_info = {0, "unknown", 1}
|
||||||
|
|
||||||
|
np.CrossCallAdd("ew_damage_message", function(message, entity_thats_responsible)
|
||||||
|
last_damage_info = {GameGetFrameNum(), message, entity_thats_responsible}
|
||||||
|
end)
|
||||||
|
|
||||||
function module.on_player_died(player_entity)
|
function module.on_player_died(player_entity)
|
||||||
-- This would be a good place to put on death logic
|
-- This would be a good place to put on death logic
|
||||||
-- BUT... player entity is already dead at this point, so it's a bit problematic to do stuff.
|
-- BUT... player entity is already dead at this point, so it's a bit problematic to do stuff.
|
||||||
|
@ -163,6 +169,39 @@ local function allow_notplayer_perk(perk_id)
|
||||||
return not ignored_perks[perk_id]
|
return not ignored_perks[perk_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rpc.opts_everywhere()
|
||||||
|
rpc.opts_reliable()
|
||||||
|
function rpc.show_death_message(untranslated_message, source_player)
|
||||||
|
local message = "unknown"
|
||||||
|
if untranslated_message ~= nil then
|
||||||
|
message = GameTextGetTranslatedOrNot(untranslated_message)
|
||||||
|
end
|
||||||
|
if source_player ~= nil then
|
||||||
|
message = message .. " from "..source_player
|
||||||
|
end
|
||||||
|
|
||||||
|
local dead_nickname = ctx.rpc_player_data.name
|
||||||
|
local full_msg = dead_nickname .. " died: " .. message
|
||||||
|
GamePrint(full_msg)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function show_death_message()
|
||||||
|
local current_frame = GameGetFrameNum()
|
||||||
|
-- Check if message is recent enough
|
||||||
|
if current_frame - last_damage_info[1] < 60 then
|
||||||
|
local message = last_damage_info[2]
|
||||||
|
local source = nil
|
||||||
|
local source_ent = last_damage_info[3]
|
||||||
|
local maybe_player = player_fns.get_player_data_by_local_entity_id(source_ent)
|
||||||
|
if maybe_player ~= nil then
|
||||||
|
source = maybe_player.name
|
||||||
|
end
|
||||||
|
rpc.show_death_message(message, source)
|
||||||
|
else
|
||||||
|
rpc.show_death_message(nil, nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function player_died()
|
local function player_died()
|
||||||
if ctx.my_player.entity == nil then
|
if ctx.my_player.entity == nil then
|
||||||
return
|
return
|
||||||
|
@ -171,6 +210,9 @@ local function player_died()
|
||||||
util.log("Err: Current player is world state like.")
|
util.log("Err: Current player is world state like.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
show_death_message()
|
||||||
|
|
||||||
rpc.remove_homing(false)
|
rpc.remove_homing(false)
|
||||||
-- Serialize inventory, perks, and max_hp, we'll need to copy it over to notplayer.
|
-- Serialize inventory, perks, and max_hp, we'll need to copy it over to notplayer.
|
||||||
local item_data = inventory_helper.get_item_data(ctx.my_player)
|
local item_data = inventory_helper.get_item_data(ctx.my_player)
|
||||||
|
@ -251,6 +293,10 @@ function module.on_local_player_spawn(my_player)
|
||||||
local damage_model = EntityGetFirstComponentIncludingDisabled(my_player.entity, "DamageModelComponent")
|
local damage_model = EntityGetFirstComponentIncludingDisabled(my_player.entity, "DamageModelComponent")
|
||||||
ComponentSetValue2(damage_model, "wait_for_kill_flag_on_death", true)
|
ComponentSetValue2(damage_model, "wait_for_kill_flag_on_death", true)
|
||||||
ctx.my_player.status = { is_alive = true }
|
ctx.my_player.status = { is_alive = true }
|
||||||
|
|
||||||
|
util.ensure_component_present(my_player.entity, "LuaComponent", "ew_player_damage", {
|
||||||
|
script_damage_received = "mods/quant.ew/files/system/local_health/grab_damage_message.lua"
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function module.on_world_update()
|
function module.on_world_update()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue