shooting target

Place to get help with not working mods / modding interface.
Post Reply
DemonSF
Manual Inserter
Manual Inserter
Posts: 3
Joined: Wed Mar 18, 2020 5:03 pm
Contact:

shooting target

Post 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

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: shooting target

Post 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.
I have mods! I guess!
Link

DemonSF
Manual Inserter
Manual Inserter
Posts: 3
Joined: Wed Mar 18, 2020 5:03 pm
Contact:

Re: shooting target

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

Pi-C
Smart Inserter
Smart Inserter
Posts: 1639
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: shooting target

Post 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.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

DemonSF
Manual Inserter
Manual Inserter
Posts: 3
Joined: Wed Mar 18, 2020 5:03 pm
Contact:

Re: shooting target

Post 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

Post Reply

Return to “Modding help”