Shooting state is not writeable

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
Valansch
Inserter
Inserter
Posts: 23
Joined: Fri Jun 23, 2017 12:00 pm
Contact:

Shooting state is not writeable

Post by Valansch »

The API states:
shooting_state [Read-Write]
http://lua-api.factorio.com/latest/LuaC ... ting_state


yet

Code: Select all

        game.players[1].shooting_state.state = defines.shooting.shooting_enemies
        game.print(game.players[1].shooting_state.state)
Will always return the shooting state before running the code. Even if enemies are in range.


I don't know if this is a bug, or i'm misunderstanding something or if the API documentation is wrong.
Admin and Developer for RedMew

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Shooting state is not writeable

Post by Choumiko »

It is writeable. You just have to assign the whole state, not just a field of it

Code: Select all

game.players[1].shooting_state = {state = defines.shooting.shooting_enemies, position = game.players[1].shooting_state.position}
game.print(game.players[1].shooting_state.state)
For most (if not all) tables you get back from the api, writing works only if you reassign the complete table.

Valansch
Inserter
Inserter
Posts: 23
Joined: Fri Jun 23, 2017 12:00 pm
Contact:

Re: Shooting state is not writeable

Post by Valansch »

I thought someone might say that. Sry I didn't clarify, but this was the first thing I tried. I does not work.
Admin and Developer for RedMew

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Shooting state is not writeable

Post by Choumiko »

You might have to do it every tick, that's how i do it here: https://github.com/Choumiko/UnminableVe ... l.lua#L156

I assume since the shooting state is controlled via player input normaly it gets reset every tick if the configured key isn't pressed

Valansch
Inserter
Inserter
Posts: 23
Joined: Fri Jun 23, 2017 12:00 pm
Contact:

Re: Shooting state is not writeable

Post by Valansch »

The code you are linking works. You can stop a player from attacking something.

But i didn't have any luck setting the shooting state to anything else than 0.

So the shooting state is writable. But only 0 is a legal value?
Admin and Developer for RedMew

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

Re: Shooting state is not writeable

Post by Relik »

Hi,
I have the same problem : I'm trying to create a mod that allows to automate vehicles (car, tank) and I can't get them to attack :/

Did you find a solution ?

I tried :

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_selected,
    position = { x = car.position.x + 1, y = car.position.y }
}

Post Reply

Return to “Modding discussion”