Client-side damage dealing

This commit is contained in:
IQuant 2024-05-26 00:49:53 +03:00
parent 1691b13d29
commit ccfc65c983
5 changed files with 86 additions and 5 deletions

View file

@ -1,4 +1,4 @@
<Mod
version_built_with="1"
version_built_with="12"
>
</Mod>

View file

@ -0,0 +1,15 @@
-- 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)
-- Change our health back
local entity_id = GetUpdatedEntityID();
local damageModelComponent = EntityGetFirstComponentIncludingDisabled( entity_id, "DamageModelComponent" )
if damageModelComponent ~= nil then
local health = ComponentGetValue2( damageModelComponent, "hp" )
if health then
ComponentSetValue2( damageModelComponent, "hp", health + damage )
end
end
-- Damage the host
CrossCall("ew_ds_damaged", damage, message)
end

View file

@ -188,7 +188,7 @@
falling_damages="0"
invincibility_frames="60"
hp="-1"
materials_damage="1"
materials_damage="0"
materials_that_damage="acid,lava,blood_cold_vapour,blood_cold,poison,radioactive_gas,radioactive_gas_static,rock_static_radioactive,rock_static_poison,ice_radioactive_static,ice_radioactive_glass,ice_acid_static,ice_acid_glass,rock_static_cursed,magic_gas_hp_regeneration,gold_radioactive,gold_static_radioactive,rock_static_cursed_green,cursed_liquid,poo_gas"
materials_how_much_damage="0.005,0.003,0.0006,0.0009,0.001,0.001,0.001,0.001,0.001,0.001,0.001,0.001,0.001,0.005,-0.005,0.0002,0.0002,0.004,0.0005,0.00001"
ragdoll_filenames_file="data/ragdolls/player/filenames.txt"
@ -199,7 +199,21 @@
drop_items_on_death="0"
critical_damage_resistance="0"
><damage_multipliers
explosion="0.35" >
projectile="0"
explosion="0"
electricity="0"
fire="0"
drill="0"
slice="0"
ice="0"
healing="0"
physics_hit="0"
radioactive="0"
poison="0"
overeating="0"
curse="0"
holy="0"
>
</damage_multipliers>
</DamageModelComponent>

View file

@ -0,0 +1,50 @@
local ctx = dofile_once("mods/quant.ew/files/src/ctx.lua")
local net = dofile_once("mods/quant.ew/files/src/net.lua")
local player_fns = dofile_once("mods/quant.ew/files/src/player_fns.lua")
local np = require("noitapatcher")
local rpc = net.new_rpc_namespace()
local module = {}
module.recent_damage = 0
module.recent_message = "unknown"
np.CrossCallAdd("ew_ds_damaged", function (damage, message)
module.recent_damage = module.recent_damage + damage
module.recent_message = message
end)
function module.on_local_player_spawn(my_player)
if not ctx.is_host then
EntityAddComponent2(my_player.entity, "LuaComponent", {script_damage_received = "mods/quant.ew/files/cbs/send_damage_to_host.lua"})
end
end
function module.on_world_update_client()
if module.recent_damage ~= 0 and GameGetFrameNum() % 15 == 2 then
rpc.deal_damage(module.recent_damage, module.recent_message)
module.recent_damage = 0
module.recent_message = "unknown"
end
end
rpc.opts_reliable()
function rpc.deal_damage(damage, message)
local message = GameTextGetTranslatedOrNot(message) .. " from "..ctx.rpc_player_data.name
if ctx.is_host then
-- local entity_thats_responsible = ctx.rpc_player_data.entity
local host_entity_id = ctx.my_player.entity
local protection_component_id = GameGetGameEffect(host_entity_id, "PROTECTION_ALL")
if protection_component_id then
EntitySetComponentIsEnabled(host_entity_id, protection_component_id, false)
end
EntityInflictDamage(host_entity_id, damage, "DAMAGE_CURSE", message, "NONE", 0, 0, nil)
if protection_component_id then
EntitySetComponentIsEnabled(host_entity_id, protection_component_id, true)
end
end
GamePrint("Got ".. (damage*25) .." damage: "..message)
end
return module

View file

@ -21,6 +21,7 @@ local enemy_sync = ctx.dofile_and_add_hooks("mods/quant.ew/files/src/enemy_sync.
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/world_sync.lua")
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/item_sync.lua")
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/sync/effect_sync.lua")
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/sync/damage_sync.lua")
local version = dofile_once("mods/quant.ew/files/version.lua") or "unknown (dev build)"
@ -149,7 +150,7 @@ function OnPlayerSpawned( player_entity ) -- This runs when player entity has be
if ctx.is_host then
EntityAddTag(player_entity, "ew_host")
else
EntityAddComponent2(player_entity, "LuaComponent", {script_damage_about_to_be_received = "mods/quant.ew/files/cbs/immortal.lua"})
-- EntityAddComponent2(player_entity, "LuaComponent", {script_damage_about_to_be_received = "mods/quant.ew/files/cbs/immortal.lua"})
end
EntityAddTag(player_entity, "ew_current_player")
@ -176,10 +177,11 @@ function OnPlayerSpawned( player_entity ) -- This runs when player entity has be
EntityLoad("data/entities/items/pickup/heart.xml", x-75, y-20)
end
ctx.hook.on_local_player_spawn(my_player)
GamePrint("Noita Entangled Worlds version "..version)
OnPausedChanged(false, false)
-- GameSetCameraFree(true)
end