Fix: damage sync not causing death

Newline

Gameprint
This commit is contained in:
Furior 2024-05-24 16:48:55 +07:00
parent c08db2bad2
commit 72c6e15f9f

View file

@ -1,23 +1,26 @@
-- Called on host when clients get damage and redirects it straight to the host's hp, ignoring any resists.
function damage_received(damage, message, entity_thats_responsible, is_fatal, projectile_thats_responsible)
local host_entity_id = EntityGetWithTag("ew_host")[1]
local host_damageModelComponent = EntityGetFirstComponentIncludingDisabled(host_entity_id, "DamageModelComponent")
if not host_damageModelComponent then
function inflict_direct_damage(entity_id, damage)
local damageModelComponent = EntityGetFirstComponentIncludingDisabled(entity_id, "DamageModelComponent")
if not damageModelComponent then
return
end
local health = ComponentGetValue2(host_damageModelComponent, "hp")
local health = ComponentGetValue2(damageModelComponent, "hp")
if not health then
return
end
ComponentSetValue2(host_damageModelComponent, "hp", health - damage)
-- 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
new_health = health - damage
ComponentSetValue2(damageModelComponent, "hp", new_health)
if new_health <= 0 then
EntityKill(entity_id)
end
end
-- Called on host when clients get damage and redirects it straight to the host's hp, ignoring any resists.
function damage_received(damage, message, entity_thats_responsible, is_fatal, projectile_thats_responsible)
-- Damage the host
local host_entity_id = EntityGetWithTag("ew_host")[1]
inflict_direct_damage(host_entity_id, damage)
-- Return the health to the client
local client_entity_id = GetUpdatedEntityID(client_entity_id, -damage)
inflict_direct_damage(client_entity_id, -damage)
end