Page 1 of 1

shooting target

Posted: Wed Mar 18, 2020 5:07 pm
by DemonSF
what is shooting_target?
and what does he do?
how to target a specific type or object?
https://lua-api.factorio.com/latest/Lua ... ing_target

Re: shooting target

Posted: Wed Mar 18, 2020 5:59 pm
by Honktown
It looks like it should return at what the turret is currently shooting (if called with nothing), but can be called with a different LuaEntity to make it change target.

Re: shooting target

Posted: Thu Mar 19, 2020 4:22 pm
by DemonSF
Honktown wrote:
Wed Mar 18, 2020 5:59 pm
It looks like it should return at what the turret is currently shooting (if called with nothing), but can be called with a different LuaEntity to make it change target.
well he turns to LuaEntity. But how can I ask him to shoot at the target I want, and ignore everything else? I give him food shooting_target = "tank" and he ignores the recipe, shoots everything that is the enemy

P.S.Sorry, I'm using Google translator)

Re: shooting target

Posted: Thu Mar 19, 2020 5:12 pm
by Pi-C
DemonSF wrote:
Thu Mar 19, 2020 4:22 pm
Honktown wrote:
Wed Mar 18, 2020 5:59 pm
It looks like it should return at what the turret is currently shooting (if called with nothing), but can be called with a different LuaEntity to make it change target.
well he turns to LuaEntity. But how can I ask him to shoot at the target I want, and ignore everything else? I give him food shooting_target = "tank" and he ignores the recipe, shoots everything that is the enemy
The target has to be a specific entity that has to be in range of the turret. Something like this would work:

Code: Select all

local targets = turret.surface.find_entities_filtered{
                type = "car",
                name = "tank",
                position = turret.position,
                radius = turret.prototype.turret_range
            }
for _, t in pairs(targets) do
	if t.valid and t.force ~= turret.force then
		turret.shooting_target = t 
		break
	end
end
I think it's not possible to order a turret to shoot only at certain entity types, so after the turret has killed the target, it will automatically look for a new target, which may be any entity belonging to an enemy force.

Re: shooting target

Posted: Sat Mar 21, 2020 1:00 am
by DemonSF
Pi-C wrote:
Thu Mar 19, 2020 5:12 pm
DemonSF wrote:
Thu Mar 19, 2020 4:22 pm
Honktown wrote:
Wed Mar 18, 2020 5:59 pm
It looks like it should return at what the turret is currently shooting (if called with nothing), but can be called with a different LuaEntity to make it change target.
well he turns to LuaEntity. But how can I ask him to shoot at the target I want, and ignore everything else? I give him food shooting_target = "tank" and he ignores the recipe, shoots everything that is the enemy
The target has to be a specific entity that has to be in range of the turret. Something like this would work:

Code: Select all

local targets = turret.surface.find_entities_filtered{
                type = "car",
                name = "tank",
                position = turret.position,
                radius = turret.prototype.turret_range
            }
for _, t in pairs(targets) do
	if t.valid and t.force ~= turret.force then
		turret.shooting_target = t 
		break
	end
end
I think it's not possible to order a turret to shoot only at certain entity types, so after the turret has killed the target, it will automatically look for a new target, which may be any entity belonging to an enemy force.
Thank you very much, the code itself does not work. I had to change it and a miracle started. I couldn’t check the current function itself (since I need an enemy on the tank) I will be able to check it) thanks