Page 1 of 1

If I hit it, it dies.

Posted: Sat May 23, 2020 11:28 pm
by nljr
I want a mod that will automatically mark for harvest any tree, rock or cliff that I run a vehicle into.

Re: If I hit it, it dies.

Posted: Sun Jun 14, 2020 1:16 pm
by darkfrei
nljr wrote: Sat May 23, 2020 11:28 pm I want a mod that will automatically mark for harvest any tree, rock or cliff that I run a vehicle into.
Just place this code to your mod into the control.lua:

Code: Select all

script.on_event(defines.events.on_entity_damaged, function(event)
	local entity = event.entity
	local force = event.force
	if entity.type == "tree" and force then
		entity.order_deconstruction(force)
	end
end)

Re: If I hit it, it dies.

Posted: Sun Jun 14, 2020 1:17 pm
by ichVII
This would also mark burning trees for deconstruction, which would kill a lot of robots.

Re: If I hit it, it dies.

Posted: Sun Jun 14, 2020 1:24 pm
by darkfrei
ichVII wrote: Sun Jun 14, 2020 1:17 pm This would also mark burning trees for deconstruction, which would kill a lot of robots.
You are right, it must be impact only.

Code: Select all

script.on_event(defines.events.on_entity_damaged, function(event)
	local entity = event.entity
	local force = event.force
	if entity.type == "tree" and event.damage_type.name == "impact" and force then
		entity.order_deconstruction(force)
	end
end)