Whip's Turret AI Slaving Script для Space Engineers
[img=https://i.imgur.com/Vw0h1Xy.png]
Howdy!
This script allows the user to slave control of player made Rotor Turrets and AI Turrets to a specific AI turret. This script can support all the turret groups you desire with just one code!
I'll say this again: you only need ONE code to control all your rotor turrets / Slaved AI turret groups!
Unlike similar scripts, rather than pick an arbitrary point to make the guns converge upon, this turret slaver will compute a lead on the target to intercept it :D
There is lots of error handling built in to help users troubleshooting issues; this also makes is so that a broken turret doesn't break the code itself.
[img=https://i.imgur.com/A6KkMfe.png]
It is recommended that you read all the instructions before attempting
to use this code! This will make troubleshooting any issues much easier <3
Script Setup
[olist]
- Place this script in a program block
- Set up turret groups (see below sections)
- Set ownership on EVERYTHING to yourself
(Optional): You can adjust the variables in the custom data of the programmable block if the default settings are not ideal. I've found these values to be sufficient for most of my vanilla weapons; however, heavier turrets will need smaller "Proportional gain" values.
[/olist]
[img=https://i.imgur.com/uifOVGJ.png]
[img=http://i.imgur.com/oAxoa6g.png]
[img=http://i.imgur.com/7eHpY0a.png]
Rotor turret groups must be named like the following:
"Turret Group <ID Tag>"
Where <ID Tag> is the unique identification tag of the rotor turret.
Example Turret Group Names:
- Turret Group 1
- Turret Group WhiplashIsAwesome
- Turret Group SamIsACow
- Turret Group 1A
Rotor Turret Group Components
EACH turret group must have:
- One or more AI turrets with "Designator" in its name. The type does NOT matter, only the range. You can also place it wherever.
- 1 azimuth (horizontal) rotor with "Azimuth" in its name
- One or more elevation (vertical) rotors with "Elevation" in its name
- One or more weapons or tools on each elevation rotor (any name)
(rocket launchers, gatling guns, modded guns welders, grinders, cameras, and spotlights supported)
Optional Block(s):
- A timer to trigger when the turret is targeting
Setting Turret Rest Position
Turrets will return to rest position when not being controlled. To set your own rest angle for a specified rotor, simply type the desired rest angle (in degrees) inside the rotor's custom data.
Example:
30
This would set the rest angle for the rotor to be 30 degrees
Rotor Turret Timer Triggering
To have a timer be triggered when the rotor turret is targeting an enemy, simply group the timer in the Turret Group. The code will start the timer once the turret is targeting and will continue to restart this timer while a target is detected. This should allow you to make self-aiming PMW turrets!
[img=https://i.imgur.com/ucZGAei.png]
[img=http://i.imgur.com/6ejgpCf.png]
Slaved AI turret groups must be named like the following:
"Slaved Group <ID Tag>"
Where <ID Tag> is the unique identification tag of the slaved AI group.
Turrets that are not tagged with the name "Designator" will be slaved to the nearest designator to them that has a target.
Slaved Group Components
EACH slaved AI group must have:
- One or more AI turrets with "Designator" in its name. The type does NOT matter, only the range. You can also place it wherever.
- One or more AI turrets to slave to the designator(s).
[img=https://i.imgur.com/f6sDUT2.png]
Turrets can be individually configured in the Custom Data of the programmable block this code runs from. You can tune the muzzle velocity for modded weapons, change the automatic engagement range of a turret, or even fine tune the fire angle tolerance. This allows you to customize each rotor turret and slaved turret group just the way you like!
[img=https://i.imgur.com/D3RjDzj.png]
[olist]
- Open the custom data of the programmable block
- Edit the variables you desire
- Click "Ok"
[/olist]
The script will process the changes the next time the setup routine runs (It cycles every 10 seconds). If you are impatient, you can also click the "Recompile" button in the programmable block's terminal.
General Parameters
[img=https://i.imgur.com/lNuOy6C.png]
Slaved Turret and Rotor Turret Parameters
[img=https://i.imgur.com/lIT2sPc.png]
Rotor Turret Parameters
[img=https://i.imgur.com/1s42wnq.png]
[img=https://i.imgur.com/zIxUe7k.png]
Argument
Function
reset_targeting
Resets AI to turn on for any non-designator turrets
debug_toggle
Toggles debug mode on/off
[img=https://i.imgur.com/twuIaF6.png]
Post any questions, suggestions, or issues you have in the comments! <3
Also, I'd love to see what y'all make with my scripts so feel free to post your turret creations in the discussions section!
- Whiplash141