Page 1 of 1

Control tanks/character/cars without player

Posted: Fri May 12, 2023 10:13 pm
by thibf
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 !

Re: Control tanks/character/cars without player

Posted: Sat May 13, 2023 1:03 am
by hackamod
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

Posted: Sat May 13, 2023 1:57 am
by DaveMcW
This works for characters, including characters in a car/tank.

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)
A car/tank must have a character in order to shoot. You can create a dummy character if the player is not driving it.

Re: Control tanks/character/cars without player

Posted: Sat May 13, 2023 4:50 am
by Pi-C
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.
Check out Autodrive, I think I already do a lot of what you want to achieve.

Also, just for clarification:
DaveMcW wrote: Sat May 13, 2023 1:57 am A car/tank must have a character in order to shoot. You can create a dummy character if the player is not driving it.
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").

Re: Control tanks/character/cars without player

Posted: Sat May 13, 2023 2:03 pm
by thibf
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.