Space Engineers

Space Engineers

1,468 ratings
Whip's Turret AI Slaving Script
3
3
2
14
2
6
2
2
2
2
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
609.463 KB
Apr 25, 2016 @ 12:39am
Dec 12, 2022 @ 8:51am
95 Change Notes ( view )

Subscribe to download
Whip's Turret AI Slaving Script

In 1 collection by Whiplash141
Whip's Scripts
22 items
Description
(Previously titled: "Whip's AI Rotor Turret Control Script")

Note
In the documentation below, "rotor" refers to both rotors and hinges! This is because the game considers hinges to be just fancy sideways rotors.


  Features
  • Slaves targeting of AI turrets, player-made rotor turrets, and rotor gimbals to other AI turrets.
  • Designators can be manually controlled to fire slaved turrets
  • Each turret group can be individually configured
  • Accurate target leading: slaved rocket turrets will actually hit their targets.
  • Turrets will avoid shooting through their own ship & subgrids.
  • Turrets will also avoid shooting through friendly ships with Turret Based Radar or this Turret Slaving script installed.



  Description
Howdy!

This script aims player made rotor or hinge based turrets at an AI turret's target. This script also allows you to slave control of other AI turrets to other AI turrets.

Now for some terminology:
  • Designator turret: An AI turret (vanilla or modded) that will be used to give targets to our custom turrets. They must have the word Designator added to their name.
  • Rotor turret: One rotor/hinge and one (or more) secondary rotors/hinges with weapons or tools on them slaved to one (or more) designator turrets (2DOF)
  • Rotor gimbal: One rotor/hinge with weapons or tools on it slaved to one (or more) designator turrets (1DOF)
  • Slaved AI group: One (or more) AI turrets slaved to one (or more) designator turrets

Additionally, you can manually control turret groups by manually controlling the designator.

You can have multiple turret groups controlled by this script simultaneously. You do not need a script for each custom turret group you wish to create.


  Script Setup
  1. Place this script in a programmable block.
  2. Setup rotor turret, rotor gimbal, and slaved AI turret groups (See below sections for more detail).
  3. You must run the script with the argument setup to process any new blocks, groups, or custom data changes!

You can heavily customize each turret's behavior in the custom data of the programmable block tha this script runs from (See "Custom Data" section below).


  Rotor Turret Group Setup
Required Steps
Create a block group with the following constraints:
  • Rotor turret groups must be named like the following: "Turret Group <TAG>" where <TAG> is a unique tag for your turret.
    Examples:
    • Turret Group 1
    • Turret Group Tomato
    • Turret Group iLikeTurtles420
  • Each turret group must have the following required blocks:
    • One base rotor/hinge. Each rotor turret only supports one base rotor/hinge. (Name does not mater)
    • One or more secondary rotors/hinges mounted sideways on top of the base rotor/hinge. (Names do not matter)
    • At least one weapon or tool atop each secondary rotor/hinge head (Names do not matter). Accepted blocks include:
      • Any fixed weapon
      • Cameras
      • Ship tools
      • Any light block
    • One or more AI turrets with the name tag "Designator". The type of the turret does not matter, but in survival, it must have ammo to work as a designator.
Optional Steps
  • Add any desired optional blocks to the group:
    • Timers: Can be configured to trigger on shoot or on targeting in the timer's custom data
    • Lights: Can be configured to blink or change color when turret is targeting or idle in the light's custom data
  • You can set rotor/hinge rest positions in the custom data of the rotors/hinges once the code has finished registering your turrets.

Examples



  Rotor Gimbal Group Setup
Required Steps
Create a block group with the following constraints:
  • Rotor gimbal groups must be named like the following: "Gimbal Group <TAG>" where <TAG> is a unique tag for your gimbal.
  • Each gimbal group must have the following required blocks:
    • A rotor/hinge. Each gimbal group only supports one rotor/hinge. (Name does not mater)
    • At least one weapon or tool atop the rotor/hinge head(Names do not matter). Accepted blocks include:
      • Any fixed weapon
      • Cameras
      • Ship tools
      • Any light block
    • One or more AI turrets with the name tag "Designator". The type of the turret does not matter, but in survival, it must have ammo to work as a designator.
Optional Steps
  • Add any desired optional blocks to the group:
    • Timers: Can be configured to trigger on shoot or on targeting in the timer's custom data
    • Lights: Can be configured to blink or change color when turret is targeting or idle in the light's custom data
  • You can set rotor/hinge rest positions in the custom data of the rotors/hinges once the code has finished registering your turrets.

Examples



  Slaved AI Turret Group Setup
Required Steps
Create a block group with the following constraints:
  • Slaved AI groups groups must be named like the following: "Slaved Group <TAG>" where <TAG> is a unique identifier for your slaved AI group.
  • Each slaved AI group must have the following required blocks:
    • One or more AI turrets with the name tag "Designator". The type of the turret does not matter, but in survival, it must have ammo to work as a designator.
    • One or more AI turrets without the name tag "Designator".
Optional Steps
  • Add any desired optional blocks to the group:
    • Timers: Can be configured to trigger on shoot or on targeting in the timer's custom data
    • Lights: Can be configured to blink or change color when turret is targeting or idle in the light's custom data

Example



  Custom Data Config
After your turret groups are all setup, you can customize the behavior of each one in the custom data of the programmable block.
  1. Open the custom data of the programmable block
  2. Edit the variables you desire
  3. Click "Ok"
The script will process the changes once you run the argument "setup".




  Author's Notes
I went through great pains to simplify the setup of this script to reduce confusion. The script is smarter now and will try to auto detect your turrets.

Also, Weapon Core guns/turrets do not appear as weapons to the in-game API, and I have no plans to write mod specific code to support them. You can use timers to fire them.

(Do not reupload without permission, not even to mod.io)

- Whiplash141
Popular Discussions View All (3)
359
Jun 7, 2023 @ 7:45pm
PINNED: Bug Reports
Whiplash141
94
Feb 28 @ 4:13am
PINNED: Feature Suggestions
Whiplash141
37
Jun 6, 2021 @ 7:13pm
PINNED: Player Made Turrets!
Whiplash141
2,445 Comments
Whiplash141  [author] May 9 @ 11:54am 
It does still work, yes :)
Cthulhu May 9 @ 11:30am 
Hello there,
quick Question, does die AI turret slaving Part still work? I need it so the turrets stop blasting my plane wings. Thx
Whiplash141  [author] May 4 @ 8:30pm 
No, I kind of retired this script with the advent of the custom turret controller and my subsequent script TCES
Layzanya May 4 @ 6:27am 
Since I haven't seen any posts or comments about it, is there a way to make this communicate with MART?
Whiplash141  [author] Apr 25 @ 11:11pm 
That indicates that the script does not see a rotor base on the same grid as the rotor head of another.

Have a screenshot or blueprint of your turret? Your turret should look like one of the example turrets as pictured in "Rotor Turret Group Setup"
25iceking20020 Apr 25 @ 10:42pm 
So im building a ship that has some guns underneath. the guns are connected by conveyor to a hinge then rotor but it says no guns are available and no secondary rotor. Any idea why?
Whiplash141  [author] Apr 16 @ 8:17am 
no
Manshima Apr 16 @ 5:05am 
This is the behavior I would like: Reaver spawns in at 5km away and moves toward my station. I take control of a search light to find it and 'paint' the target. All of my station turrets (vanilla turrets, not custom) aim at the reaver that I have in my sights and fire as soon as the ship gets into range.

Currently my turrets won't fire until they have turned towards the ship, and they won't start moving until the ship gets into range. Will this script allow them to be slaved to my searchlight?
Whiplash141  [author] Mar 7 @ 11:20am 
This script has an collision detection algorithm that attempts to check if there is any grid based occlusion. It is not perfect, but it should be a bit more conservative than the CTC checks.
BlaCkShad0w Mar 7 @ 6:09am 
How does this script prevent firing at own building.
I have multiple weapons platforms using your script and it works flawlessly but I have my horizontal rotor setup with limits so the guns cannot traverse to far to prevent them tracking a target and accidently firing on the edge of some buildings.
I had this problem with the build-in turret controller that uses a single gun as reference point but the other guns mounted left and right would hit a friendly/own because they are mounted off-center and the reference gun had a unobstructed line of sight to the target.

Setting the limits helps but creates a massive weakspot directly above my base where the turrets cannot reach, any ideas how to overcome this problem?
Or does your script handle this and can I safely remove the rotor limits?