Control tanks/character/cars without player

Place to get help with not working mods / modding interface.
thibf
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Jul 05, 2022 9:16 pm
Contact:

Control tanks/character/cars without player

Post 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 !
hackamod
Long Handed Inserter
Long Handed Inserter
Posts: 62
Joined: Mon Apr 25, 2022 2:39 pm
Contact:

Re: Control tanks/character/cars without player

Post 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
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3716
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Control tanks/character/cars without player

Post 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.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1726
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Control tanks/character/cars without player

Post 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").
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
thibf
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Jul 05, 2022 9:16 pm
Contact:

Re: Control tanks/character/cars without player

Post 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.
Post Reply

Return to “Modding help”