shooting_state (auto attack)

Post Reply
Relik
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Sep 19, 2017 3:49 pm
Contact:

shooting_state (auto attack)

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

Rseding91
Factorio Staff
Factorio Staff
Posts: 13246
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: shooting_state (auto attack)

Post 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.
If you want to get ahold of me I'm almost always on Discord.

Relik
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Sep 19, 2017 3:49 pm
Contact:

Re: shooting_state (auto attack)

Post 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

Rseding91
Factorio Staff
Factorio Staff
Posts: 13246
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: shooting_state (auto attack)

Post 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?
If you want to get ahold of me I'm almost always on Discord.

Relik
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Sep 19, 2017 3:49 pm
Contact:

Re: shooting_state (auto attack)

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

Rseding91
Factorio Staff
Factorio Staff
Posts: 13246
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: shooting_state (auto attack)

Post by Rseding91 »

It looks like shooting_state write was broken. I've fixed it for 0.16.
If you want to get ahold of me I'm almost always on Discord.

Relik
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Sep 19, 2017 3:49 pm
Contact:

Re: shooting_state (auto attack)

Post by Relik »

Thank you, so I'm waiting for 0.16 impatiently (but it was already the case ^^)

Post Reply

Return to “Implemented mod requests”