/** * Generate the prefab */ private void SpawnPrefab(MySpawnGroupDefinition.SpawnGroupPrefab prefab, Vector3D spawnCoords, Vector3D despawnCoords, EncounterType encounterType) { Util.Log("Spawning Prefab ::" + prefab.SubtypeId + ":: for faction " + m_empireData.m_faction.Tag); Vector3D spawnFacing = Vector3D.Normalize(despawnCoords - spawnCoords); List <IMyCubeGrid> tempSpawningList = new List <IMyCubeGrid>(); var spawnOptions = SpawningOptions.SetNeutralOwner | SpawningOptions.RotateFirstCockpitTowardsDirection | SpawningOptions.SpawnRandomCargo; if (encounterType == EncounterType.TransientCargoship) { spawnOptions = spawnOptions | SpawningOptions.DisableDampeners; } MyAPIGateway.PrefabManager.SpawnPrefab( resultList: tempSpawningList, prefabName: prefab.SubtypeId, position: spawnCoords, forward: spawnFacing, up: new Vector3D(0, 1, 0), spawningOptions: spawnOptions, beaconName: prefab.BeaconText, ownerId: m_empireData.m_faction.FounderId, updateSync: false, callback: () => SpawnerCallback(encounterType, prefab, spawnCoords, despawnCoords, m_empireData.m_faction)); }
public void SpawnerCallback(EncounterType encounterType, MySpawnGroupDefinition.SpawnGroupPrefab prefab, Vector3D spawnCoord, Vector3D despawnCoords, IMyFaction ownerFaction) { Util.Log("Searching for spawned Prefab..."); IMyCubeGrid spawnedShip = null; double minDist = double.MaxValue; BoundingSphereD searchSphere = new BoundingSphereD(spawnCoord, SPAWNER_SEARCH_RADIUS); List <IMyEntity> entityList = MyAPIGateway.Entities.GetEntitiesInSphere(ref searchSphere); foreach (IMyEntity entity in entityList) { IMyCubeGrid targetGrid = entity as IMyCubeGrid; if (targetGrid == null) { continue; } //if (targetGrid.CustomName != prefab.SubtypeId) { //continue; //} if ((targetGrid.GetPosition() - spawnCoord).LengthSquared() < minDist) { spawnedShip = targetGrid; } } if (spawnedShip == null) { Util.Error("Error: Could not find ship " + prefab.SubtypeId + " after spawning."); return; } spawnedShip.ChangeGridOwnership(m_empireData.m_faction.FounderId, MyOwnershipShareModeEnum.None); IMyGridTerminalSystem gts = spawnedShip.GetTerminalSystem(); List <IMyRemoteControl> blocks = new List <IMyRemoteControl>(); gts.GetBlocksOfType(blocks); IMyRemoteControl firstRemote = blocks.Find(b => b.IsFunctional); LaunchDrone(encounterType, firstRemote, spawnedShip, despawnCoords); }