1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-06 00:23:49 +02:00

Bugfix: Error was triggered when splash damage happened after entity died.

This commit is contained in:
MaemiKozue 2019-06-11 01:54:44 +02:00
parent d6d73d70df
commit dddf4be3ab

View File

@ -2,8 +2,8 @@ local radius = 3
local function splash_damage(surface, position, final_damage_amount)
local damage = math.random(math.floor(final_damage_amount * 3), math.floor(final_damage_amount * 4))
for _, e in pairs(surface.find_entities_filtered({area = {{position.x - radius, position.y - radius},{position.x + radius, position.y + radius}}})) do
if e.health then
for _, e in pairs(surface.find_entities_filtered({area = {{position.x - radius, position.y - radius},{position.x + radius, position.y + radius}}})) do
if e.valid and e.health then
local distance_from_center = math.sqrt((e.position.x - position.x) ^ 2 + (e.position.y - position.y) ^ 2)
if distance_from_center <= radius then
local damage_distance_modifier = 1 - distance_from_center / radius
@ -23,9 +23,9 @@ local function explosive_bullets(event)
if player.shooting_state.state == defines.shooting.not_shooting then return false end
local selected_weapon = player.get_inventory(defines.inventory.character_guns)[player.selected_gun_index]
if selected_weapon.name ~= "submachine-gun" and selected_weapon.name ~= "pistol" then return false end
player.surface.create_entity({name = "explosion", position = event.entity.position})
splash_damage(
player.surface,
event.entity.position,
@ -34,5 +34,3 @@ local function explosive_bullets(event)
end
return explosive_bullets