Problem with create_entity

Place to get help with not working mods / modding interface.
leosangue
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sat Mar 14, 2026 11:55 pm
Contact:

Problem with create_entity

Post 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)
User avatar
Osmo
Filter Inserter
Filter Inserter
Posts: 257
Joined: Wed Oct 23, 2024 12:08 pm
Contact:

Re: Problem with create_entity

Post 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
Post Reply

Return to “Modding help”