Page 1 of 1

shooting_state (auto attack)

Posted: Fri Nov 10, 2017 2:02 pm
by Relik
Hi,

I'm working on a mod onboard_computer and I would like to allow a non-player entity to attack a position.

Ex:

Code: Select all

-- car is an entity type="car" (car, tank...)
-- player is the player who started the script

car.passenger = car.surface.create_entity({
	name = "player",
	force = player.force,
	position = car.position,
	source = player.character,
	fast_replace = true,
	player = player
})

-- position is a position where an enemy has been detected
car.passenger.shooting_state = {
	state = defines.shooting.shooting_selected,
	position = position
}
Despite various tests, I failed to attack (car.passenger.shooting_state always worth "{state = 0, position = {x = 0, y = 0}}")
Do I do it wrong?

(Another subject also raised the concern: viewtopic.php?f=34&t=51354)

Re: shooting_state (auto attack)

Posted: Fri Nov 10, 2017 2:20 pm
by Rseding91
"shooting selected" means the character shoots the entity it has selected and doesn't care about the position parameter. You need to use http://lua-api.factorio.com/latest/LuaC ... ted_entity to set the selected entity of the character entity.

Re: shooting_state (auto attack)

Posted: Fri Nov 10, 2017 2:47 pm
by Relik
Thank you for your return, but not work :(

I tried :

Code: Select all

car.passenger.update_selected_entity(position)
game.print(car.passenger.selected.type)
-- result: "unit-spawner"

game.print(car.passenger.shooting_state)
-- result: table:0x00... {state=0, position={y=0,x=0}}

car.passenger.shooting_state = {
   state = defines.shooting.shooting_selected,
   position = position
}

game.print(car.passenger.shooting_state)
-- result: table:0x00... {state=0, position={y=0,x=0}}

Code: Select all

car.passenger.update_selected_entity(position)
game.print(car.passenger.selected.type)
-- result: "unit-spawner"

game.print(car.passenger.shooting_state)
-- result: table:0x00... {state=0, position={y=0,x=0}}

car.passenger.shooting_state = {
   state = defines.shooting.shooting_enemies,
   position = position
}

game.print(car.passenger.shooting_state)
-- result: table:0x00... {state=0, position={y=0,x=0}}
I also tried to set "car.passenger.shooting_state" every game tick

Re: shooting_state (auto attack)

Posted: Fri Nov 10, 2017 6:29 pm
by Rseding91
Hmm, I'll look into it. Most likely this is the same problem we had before with driving state where the game keeps clearing it because it detects the key inputs aren't being pressed.

If you run that same logic on a character entity not attached to a player does it work?

Re: shooting_state (auto attack)

Posted: Fri Nov 10, 2017 7:56 pm
by Relik
Initially I was trying with this code (And to be sure, I try again):

Code: Select all

car.passenger = car.surface.create_entity({
	name = "player",
	force = player.force,
	position = car.position
})
car.passenger.shooting_state = {
   state = defines.shooting.shooting_enemies,
   position = position
}
But it does not work

I tried adding the options "source", "fast_replace" and "player" to see if it changed something (I did not understand what they served and I told myself that I would eventually understand by testing ^^)
but no change on the ability to attack

Curiously by removing the option "force", the car no longer seems to be able to move (And the turrets nearby seem to attack an "invisible" entity, so I tried while being out of reach)

Re: shooting_state (auto attack)

Posted: Sat Nov 11, 2017 9:28 pm
by Rseding91
It looks like shooting_state write was broken. I've fixed it for 0.16.

Re: shooting_state (auto attack)

Posted: Sun Nov 12, 2017 11:39 am
by Relik
Thank you, so I'm waiting for 0.16 impatiently (but it was already the case ^^)