Page 1 of 1

Problem with create_entity

Posted: Sun Mar 15, 2026 12:00 am
by leosangue
Hello, i have a problem. When i mine, as a player, a transport belt, or a stone wall, the "create_entity" function, is apparently not executed, since the transport belt or stone wall is not replaced. However the fucntion works well with any other building. Do you have any idea what could be happening?

Code: Select all

--control.lua
function check_plot(x, y)
	local plot_x = math.floor(x / settings.global["plot-size"].value)
	local plot_y = math.floor(y / settings.global["plot-size"].value)
	if (plot_x % settings.global["grid-size"].value == 0 or plot_y % settings.global["grid-size"].value == 0) then
		return true
	else
		return false
	end
end
function on_player_mined_entity(event)
	local entity = event.entity
	local player = game.get_player(event.player_index)
	local inv = player.get_inventory(defines.inventory.character_main)
	if check_plot(entity.position.x,entity.position.y) then		
		player.physical_surface.create_entity{name=entity.name, position=entity.position, force=entity.force, direction=entity.direction}
		player.print("You can not destroy that",{color={r=1, g=0.5, b=0.5}})
		event.buffer.remove{name=entity.name, count=1}
	end
end
script.on_event(defines.events.on_player_mined_entity, on_player_mined_entity)

Re: Problem with create_entity

Posted: Sun Mar 15, 2026 2:58 am
by Osmo
Didn't look much into your code, but if you just need an entity to not be minable, use this https://lua-api.factorio.com/latest/cla ... nable_flag
There is a lot of data entities have and copying all of it is just not viable