Overview
This guide shows how to setup drone spawning areas, and how to make your custom drones.
1/2
New ModAPI Function
remote.GetNearestPlayer(); – this function returns coordinates of a nearest player. It will fail if both remote control and programmable block don’t belong to a hostile NPC. Range is unlimited.
Drones:
Drone functions by using existing autopilot, programmable block and timer, which keeps switching on the programmable block in a loop.
Steps by step to create a drone:
- Create your drone design
- Add programmable block, timer and a remote control
- Insert the script from this document in a programmable block, compile and save (ships will work with your custom scripts as well)
- Set timer actions to work in a loop, where timer switches on the script in programmable block and then switches itself again every second (shown on picture):
a. One slot set to Run programmable block with the script (“Run” in the action table)
b. Second to start the timer again (put “Start” in the action table) - Transfer ownership of entire drone to a hostile NPC (or straight to SpacePirates NPC) Note: transfering ownership works only in creative
Scripts:
Basic script drone follows player:
List<IMyTerminalBlock> list = new List<IMyTerminalBlock>(); void Main(string argument) { Vector3D origin = new Vector3D(0, 0, 0); if (this.Storage == null || this.Storage == “”) { origin = Me.GetPosition(); this.Storage = origin.ToString(); } else { Vector3D.TryParse(this.Storage, out origin); } GridTerminalSystem.GetBlocksOfType<IMyRemoteControl>(list); if (list.Count > 0) { var remote = list[0] as IMyRemoteControl; remote.ClearWaypoints(); Vector3D player = new Vector3D(0, 0, 0); bool success = remote.GetNearestPlayer(out player); if (success) { bool gotoOrigin = false; GridTerminalSystem.GetBlocksOfType<IMyUserControllableGun>(list); if (list.Count == 0) { gotoOrigin = true; } else { bool hasUsableGun = false; for (int i = 0; i < list.Count; ++i) { var weapon = list[i]; if (!weapon.IsFunctional) continue; if (weapon.HasInventory() && !weapon.GetInventory(0).IsItemAt(0)) continue; hasUsableGun = true; } if (!hasUsableGun) { gotoOrigin = true; } } if (Vector3D.DistanceSquared(player, origin) > 20000 * 20000) { gotoOrigin = true; } if (gotoOrigin) { remote.AddWaypoint(origin, “Origin”); } else { remote.AddWaypoint(player, “Player”); } remote.SetAutoPilotEnabled(true); } } }
Bot flees from the nearest player:
void Main(string argument) { var list = new List<IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType<IMyRemoteControl>(list); if (list.Count > 0) { var remote = list[0] as IMyRemoteControl; remote.ClearWaypoints(); Vector3D player = new Vector3D(0, 0, 0); Vector3D oppositedirection = new Vector3D(0, 0, 0); bool success = remote.GetNearestPlayer(out player); if (success) { oppositedirection = remote.GetPosition (); oppositedirection = oppositedirection + oppositedirection – player; remote.AddWaypoint(oppositedirection, “FleeDirection”); remote.SetAutoPilotEnabled(true); } } }
Antenna spawning
Spawning antennas spawn ships if player is nearby. They only work they belong to hostile NPC’s
Description:
- You can create your own pirate antennas that will spawn ships you define for the new antenna
- In order to make antenna work as a spawning antenna it needs to meet following conditions
- It belongs to a hostile NPC faction
- It has specific name that is defined in PirateAntennas.sbc (Data folder in your game file)
- Pirate antenna settings:
- <SpawnDistance> says how far from antenna are drones supposed to spawn (spawning checks on its own if the space is free, there will be no collisions)
- <SpawnTimeMs> this setting says how often drones spawn in miliseconds (one second has 1000 miliseconds)
- <SpawnGroups> here you can put list of ships that you want this specific antenna to spawn. These ships must be present in prefab folder.
- Each spawn group is defined in SpawnGroups.sbc
- You can put multiple ship groups there and antenna will spawn different groups based on their frequency (w)
- Our basic pirate antenna is called “NO TRESPASSERS”, you can always use that antenna name for ship spawning
Step by step guide how to add your own pirate base into the game:
- Create your station design
- Add an antenna and name it (example: DreadfulPirate)
- Adjust range of the antenna – range defines how far antenna detects threats
- Go to C:UsersYOURUSERNAMEAppDataRoamingSpaceEngineersMods
a. Create mod folder there and name it. Example: DreadfulPirate
b. Open folder and place a Data folder there - Go to your game folder, by default here: C:SteamLibrarysteamappscommonSpaceEngineersContentData
- Find PirateAntennas.sbc
- Copy the file and paste it in Data folder of your mod
- Now delete all antenna definitions and add only those you want to add.
Example:<?xml version=”1.0″?> <Definitions xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema”> <PirateAntennas> <Antenna> <Id> <TypeId>MyObjectBuilder_PirateAntennaDefinition</TypeId> <SubtypeId> DreadfulPirate </SubtypeId> </Id> <Name> DreadfulPirate </Name> <SpawnDistance>80</SpawnDistance> <SpawnTimeMs>300000</SpawnTimeMs> <FirstSpawnTimeMs>30000</FirstSpawnTimeMs> <!–Spawn time of the first drone–> <MaxDrones>2</MaxDrones> <!– Max Active drones spawned by one antenna–> <SpawnGroups> <Group>Informant_mk.1</Group> <Group>Incisor_mk.1</Group> </SpawnGroups> </Antenna> </PirateAntennas> </Definitions> - Write an exact name of the antenna on your station between these brackets: <Name>DreadfulPirate</Name>
- SubtypeID can be set to any name, but must be different than other antenna definitions
- Save it
- Now place your station in a world, where your spawn antenna mod is active
- Transfer its ownership to hostile NPC (only possible in creative)
- The station should spawn ships as defined in SpawnGroups section of your Antenna definition.
2/2
How to put the station between random encounters:
- Create a prefab from your station (guide is down in the article)
- Put the prefab file (Yourshipname.sbc) in prefab folder
- Create definition for a new spawn group in a SpawnGroups.sbc folder
- Example:
<SpawnGroup> <Id> <TypeId>SpawnGroupDefinition</TypeId> <SubtypeId>Raiding_Station_-_Scourge</SubtypeId> </Id> <Icon>TexturesGUIIconsFake.dds</Icon> <IsEncounter>true</IsEncounter> <IsPirate>true</IsPirate> <Frequency>1000.0</Frequency> <Prefabs> <Prefab SubtypeId=”Raiding_Station_-_Scourge”> <Position> <X>0.0</X> <Y>0.0</Y> <Z>0.0</Z> </Position> <Speed>10.0</Speed> </Prefab> </Prefabs> </SpawnGroup>
- Frequency determines how often you find this station
- This setting has to be set to true: <IsEncounter>true</IsEncounter>
- This setting must be set to true, otherwise your station’s ownership will be set to NOBODY <IsPirate>true</IsPirate>
- Here replace with your Prefab’s SubtypeId<Prefab SubtypeId=”Raiding_Station_-_Scourge”>
- Now make a mod that adds your SpawnGroup definition.
How to make your own ship designs spawned by the antenna
First you need to make your ship design into prefab
- Open the world with the ship present in it
- Place block on the drone as if you wanted to copy it
- Press ctrl+alt+e
- This places the ship in a folder on your desktop
- Open .rar located in the folder and find file in format YourShipsName.sbc
- This file is prefab, made from your ship blueprint
Now you need to make a SpawnGroup, that will contain your ship
- Go to your game folder, by default C:SteamLibrarysteamappscommonSpaceEngineersContentData
- Find SpawnGroups.sbc
- Open it in notebook
- Create a new spawn group by copy pasting an old one and by changing its name
- In this line write name your ships SubtypeId: <Prefab SubtypeId=”YellowDrone”>
- SubtypeID of your ship can be found in your ships prefab, in YourShipName.sbc
- Make sure you added this line <IsPirate>true</IsPirate>
- Without it your drone will never despawn
Assign the group to the spawning antenna of your choice as shown
- Edit your PirateAntennas.sbc
- Add this spawn group to the antenna of your choice
a. <SpawnGroups>
b. <Group>YellowDrone</Group>
c. </SpawnGroups>
Example of a spawn group:
<SpawnGroup> <Id> <TypeId>SpawnGroupDefinition</TypeId> <SubtypeId>YellowDrone</SubtypeId> </Id> <IsPirate>true</IsPirate> <Icon>TexturesGUIIconsFake.dds</Icon> <Frequency>1.0</Frequency> <Prefabs> <Prefab SubtypeId=”YellowDrone”> <Position> <X>0.0</X> <Y>0.0</Y> <Z>0.0</Z> </Position> <BeaconText>Pirate drone</BeaconText> <Speed>10.0</Speed> </Prefab> </Prefabs> </SpawnGroup>