Following the documentation, there is few ways to control military targets and control attacks:
- shooting_state but seems useful to know what's happening, but writing to it doesn't change anything.
- shooting_target works but only for turrets.
- set_command works but only for units.
- vehicle_automatic_targeting_parameters is to disable/enable automatic targeting for spidertron, no override of the target possible.
All of this doesn't works for tanks/cars/characters.
The two ways I see is:
- Create new units with the same sprite and attack_parameters than tanks/cars/characters and use commands to manipulate them.
- Create from spidertron with correct sprite/guns attached.
What would be the easier/more practical ? Did I miss something ?
Thanks !
Control tanks/character/cars without player
Re: Control tanks/character/cars without player
There are a few mods called "Mining Drones" or something similar that uses character like entities to mine ore by hand the way a player does. There might be some useful code in one of those mods
Re: Control tanks/character/cars without player
This works for characters, including characters in a car/tank.
A car/tank must have a character in order to shoot. You can create a dummy character if the player is not driving it.
Code: Select all
/c
character = game.player.character
target = game.player.selected
script.on_event(defines.events.on_tick, function()
if character and character.valid and target and target.valid then
character.shooting_state = {state=defines.shooting.shooting_selected, position=target.position}
end
end)
Re: Control tanks/character/cars without player
Check out Autodrive, I think I already do a lot of what you want to achieve.thibf wrote: ↑Fri May 12, 2023 10:13 pm Following the documentation, there is few ways to control military targets and control attacks:
- shooting_state but seems useful to know what's happening, but writing to it doesn't change anything.
- shooting_target works but only for turrets.
- set_command works but only for units.
- vehicle_automatic_targeting_parameters is to disable/enable automatic targeting for spidertron, no override of the target possible.
All of this doesn't works for tanks/cars/characters.
Also, just for clarification:
While you can get LuaPlayer.character, this isn't possible for LuaEntity. What you need here is LuaEntity.get_X() and LuaEntity.set_X(LuaPlayer or LuaEntity) (replace 'X' with "driver" or "passenger").
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: Control tanks/character/cars without player
Thanks for your tips ! The additional missing piece was the "selected" attribute: You need to set it to the target you are going to shoot, including for dummy character.