37 lines
1.4 KiB
Lua
37 lines
1.4 KiB
Lua
script.on_event(defines.events.on_entity_damaged, function(event)
|
|
local entity = event.entity
|
|
|
|
-- Check if the damaged entity is a stone wall or a construction robot
|
|
if entity and entity.valid and (entity.name == "stone-wall" or entity.name == "construction-robot") then
|
|
-- Check if the damage would destroy the entity
|
|
if event.final_health <= 0 then
|
|
local surface = entity.surface
|
|
local position = entity.position
|
|
local force = entity.force
|
|
local direction = entity.direction
|
|
local name = entity.name
|
|
|
|
-- Remove the original entity
|
|
entity.destroy()
|
|
|
|
-- Check if the force has researched ghost placement
|
|
if force.technologies["construction-robotics"] and force.technologies["construction-robotics"].researched then
|
|
|
|
-- Don't create a ghost for construction robots (not possible)
|
|
if name == "construction-robot" then
|
|
return
|
|
end
|
|
|
|
-- Create a ghost of the entity
|
|
surface.create_entity {
|
|
name = "entity-ghost",
|
|
inner_name = name,
|
|
position = position,
|
|
force = force,
|
|
direction = direction
|
|
}
|
|
end
|
|
end
|
|
end
|
|
end)
|