[0.17.66] LuaControl:shooting_state bugged interface

Place to get help with not working mods / modding interface.
Post Reply
cogito123
Inserter
Inserter
Posts: 23
Joined: Thu Feb 28, 2019 7:05 pm
Contact:

[0.17.66] LuaControl:shooting_state bugged interface

Post by cogito123 »

Hi,

I'm writing a complex scenario where LuaEntity with a "character" type tracks enemies on their own and tries to kills them. The scenario also assumes that "character" type can also destroy building such as walls.

The problem is that after I search for enemies using LuaSurface:find_entities_filtered I feed the position of found entities, that are of opposite hostile force, to my "character" NPC.
  • If the found entity is some kind of biter or character and NPC doesn't have a weapon defines.shooting.shooting_enemies and defines.shooting.shooting_selected, will work. The NPC will start attack them with an axe, assuming they're in close distance.
  • If NPC has a weapon, only defines.shooting.shooting_enemies will work and fail always for defines.shooting.shooting_selected in both cases.
  • If NPC doesn't have a weapon and it tries to attack enemy structure, nothing will happen. The NPC will just stand there, but no attack will happen with an axe. No defines.shooting state works.
  • If NPC has a weapon and it tries to attack enemy structure, nothing will happen. The NPC will just stand there, but no attack will happen with an weapon. No defines.shooting state works.
By "weapon" I mean some kind of pistol in NPC's defines.inventory.character_guns and ammo in defines.inventory.character_ammo

Questions and expectations:
  • I would expect for "character" type LuaEntity to attack enemy structures with an axe. Currently that's not possible despite the fact that shooting_state is set.
  • I would expect for "character" type LuaEntity to attack enemy structures with an weapon, if present in inventory. Currently that's not possible despite the fact that shooting_state is set.
  • Why do we need shooting_enemies and shooting_selected? Why cannot it be done with only single state? Both states only require position parameter anyway.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5148
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.17.66] LuaControl:shooting_state bugged interface

Post by Klonan »

fail always for defines.shooting.shooting_selected in both cases
Are you updating the selected entity?
https://lua-api.factorio.com/latest/Lua ... ted_entity
If NPC doesn't have a weapon and it tries to attack enemy structure, nothing will happen. The NPC will just stand there, but no attack will happen with an axe.
That is just how it works, the axe attack only work on `entity with force`, so biters, worms, spawners. Attacking things like pipes or assembling machines won't work.
If NPC has a weapon and it tries to attack enemy structure, nothing will happen.
Same as above, defines.shooting_enemy only works on `entity with force`,
Setting the selected entity and shooting the selected should work

For instance I can make this guy shoot trees using the available API:


User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5148
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.17.66] LuaControl:shooting_state bugged interface

Post by Klonan »

I will move this to modding help unless there is something more specific we can work with

Post Reply

Return to “Modding help”