private void Message(byte[] obj) { if (!MyAPIGateway.Session.IsServer) { return; } try { ShowMessageInGameAndLog("Message", "start."); short messageType = BitConverter.ToInt16(obj, 0); long entityId = BitConverter.ToInt64(obj, 2); if (Entity.EntityId != entityId) { return; } if (messageType == MSG_CHANGEOWNERREQ) { m_block = (IMyAdvancedDoor)Entity; m_mycubegrid = m_block.CubeGrid as MyCubeGrid; long playerId = BitConverter.ToInt64(obj, 10); ShowMessageInGameAndLog("Message", "got message from " + playerId.ToString()); bool add = BitConverter.ToBoolean(obj, 18); string shipname = Encoding.ASCII.GetString(obj, 19, obj.Length - 19); //ShowMessageInGameAndLog("Message", " 1"); IMyPlayer player = GetPlayerById(playerId); List <IMySlimBlock> blocks = new List <IMySlimBlock>(); (m_mycubegrid as IMyCubeGrid).GetBlocks(blocks); if (blocks.Count < 40) { return; } Vector3 forvarddirection = new Vector3(0f, 0f, 0f); IMyCockpit FoundCockpit = null; IMyShipMergeBlock FoundMerge = null; IMyShipMergeBlock FoundBaseMergeBlock = null; IMyProjector FoundBaseProjector = null; IMyCargoContainer FoundCargoCont = null; IMyCargoContainer FoundBaseCargoCont = null; IMyCargoContainer FoundBaseCargoCont2 = null; IMyParachute FoundParachute = null; IMyParachute FoundParachute2 = null; IMyParachute FoundParachute3 = null; IMyParachute FoundParachute4 = null; ShowMessageInGameAndLog("Message", " blocks.Count: " + blocks.Count); foreach (IMySlimBlock blok in blocks) { if (blok.FatBlock == null) { continue; } ShowMessageInGameAndLog("Message", " Block: " + blok.FatBlock.Name + "display nametext: " + blok.FatBlock.DisplayNameText); if (blok.FatBlock.DisplayNameText == "MyMergeBlock") { FoundMerge = (IMyShipMergeBlock)blok.FatBlock; ShowMessageInGameAndLog("Message", " found MyMergeBlock"); continue; } if (blok.FatBlock.DisplayNameText == "MyParachute") { FoundParachute = (IMyParachute)blok.FatBlock; ShowMessageInGameAndLog("Message", " found FoundParachute"); continue; } if (blok.FatBlock.DisplayNameText == "MyParachute2") { FoundParachute2 = (IMyParachute)blok.FatBlock; ShowMessageInGameAndLog("Message", " found FoundParachute"); continue; } if (blok.FatBlock.DisplayNameText == "MyParachute3") { FoundParachute3 = (IMyParachute)blok.FatBlock; ShowMessageInGameAndLog("Message", " found FoundParachute3"); continue; } if (blok.FatBlock.DisplayNameText == "MyParachute4") { FoundParachute4 = (IMyParachute)blok.FatBlock; ShowMessageInGameAndLog("Message", " found FoundParachute4"); continue; } if (blok.FatBlock.DisplayNameText == "MyCockpit") { FoundCockpit = (IMyCockpit)blok.FatBlock; ShowMessageInGameAndLog("Message", " found MyCockpit"); continue; } if (blok.FatBlock.DisplayNameText == "BaseMergeBlock") { FoundBaseMergeBlock = (IMyShipMergeBlock)blok.FatBlock; ShowMessageInGameAndLog("Message", " found BaseMergeBlock"); continue; } if (blok.FatBlock.DisplayNameText == "BaseProjector") { FoundBaseProjector = (IMyProjector)blok.FatBlock; ShowMessageInGameAndLog("Message", " found BaseProjector"); continue; } if (blok.FatBlock.DisplayNameText == "MyCargo") { FoundCargoCont = (IMyCargoContainer)blok.FatBlock; ShowMessageInGameAndLog("Message", " found MyCargo"); continue; } } ShowMessageInGameAndLog("Message", " fFoundCockpit" + (FoundCockpit != null) + (FoundMerge != null) + (FoundCargoCont != null) + (m_block.CubeGrid.CustomName == shipname)); if (FoundCargoCont != null && FoundCockpit != null && FoundMerge != null && FoundParachute != null && FoundParachute2 != null && FoundParachute3 != null && FoundParachute4 != null && m_block.CubeGrid.CustomName == shipname) { (m_block as IMyAdvancedDoor).OpenDoor(); (m_block as IMyAdvancedDoor).CustomData = ""; // (m_block as IMyAdvancedDoor).CustomName = "Use me."; // (m_block as IMyAdvancedDoor).ShowOnHUD = true; forvarddirection = FoundMerge.WorldMatrix.Backward; //ShowMessageInGameAndLog("Message", " findedthrust vector"); List <IMySlimBlock> blocks2 = new List <IMySlimBlock>(); BoundingSphereD boundingSphere = new BoundingSphereD(FoundMerge.GetPosition(), 300); var entity = MyAPIGateway.Entities.GetEntitiesInSphere(ref boundingSphere); foreach (IMyEntity ent in entity) { if (ent.DisplayName != "GNR_Spawn") { continue; } (ent as IMyCubeGrid).GetBlocks(blocks2); foreach (IMySlimBlock blok in blocks2) { if (blok.FatBlock == null) { continue; } if (blok.FatBlock as IMyCargoContainer == null) { continue; } if (blok.FatBlock.DisplayNameText == "BaseCargo") { FoundBaseCargoCont = (IMyCargoContainer)blok.FatBlock; ShowMessageInGameAndLog("Message", " found BaseCargo"); continue; } if (blok.FatBlock.DisplayNameText == "BaseCargo2") { FoundBaseCargoCont2 = (IMyCargoContainer)blok.FatBlock; ShowMessageInGameAndLog("Message", " found BaseCargo2"); continue; } } } //res for welders start addtoContainer(FoundBaseCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "SteelPlate"), 752); addtoContainer(FoundBaseCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "Construction"), 286); addtoContainer(FoundBaseCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "InteriorPlate"), 113); addtoContainer(FoundBaseCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "MetalGrid"), 8); addtoContainer(FoundBaseCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "Computer"), 144); addtoContainer(FoundBaseCargoCont2, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "LargeTube"), 6); addtoContainer(FoundBaseCargoCont2, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "Motor"), 31); addtoContainer(FoundBaseCargoCont2, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "Display"), 15); addtoContainer(FoundBaseCargoCont2, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "SmallTube"), 84); addtoContainer(FoundBaseCargoCont2, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "PowerCell"), 120); //res for welders end ////Started resourses SerializableDefinitionId Item_Hatch = new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "Canvas"); ShowMessageInGameAndLog("Message", " before add to conteiner"); addtoContainer2(FoundCargoCont, new MyObjectBuilder_AmmoMagazine { SubtypeName = "NATO_5p56x45mm", ProjectilesCount = 50 }, 2); addtoContainer2(FoundCargoCont, this.CreateGunContent("AutomaticRifleItem"), 1); addtoContainer2(FoundCargoCont, this.CreateGunContent("WelderItem"), 2); addtoContainer2(FoundCargoCont, this.CreateGunContent("AngleGrinderItem"), 1); addtoContainer2(FoundCargoCont, this.CreateGunContent("HandDrillItem"), 1); //00 addtoContainer2(FoundCargoCont, this.CreateGunContent("HydrogenBottle"), 1); addtoContainer(FoundCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Ore), "Ice"), 1000); addtoContainer(FoundCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "SteelPlate"), 1339); addtoContainer(FoundCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "Construction"), 150); addtoContainer(FoundCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "InteriorPlate"), 240); addtoContainer(FoundCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "MetalGrid"), 73); addtoContainer(FoundCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "RadioCommunication"), 2); addtoContainer(FoundCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "Computer"), 25); addtoContainer(FoundCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "LargeTube"), 35); addtoContainer(FoundCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "Motor"), 28); addtoContainer(FoundCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "Display"), 15); addtoContainer(FoundCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "Medical"), 15); addtoContainer(FoundCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "SmallTube"), 100); addtoContainer(FoundCargoCont, new SerializableDefinitionId(typeof(MyObjectBuilder_Component), "PowerCell"), 150); addtoContainer2(FoundCargoCont, new MyObjectBuilder_GasContainerObject { SubtypeName = "HydrogenBottle", GasLevel = 1 }, 1); addtoContainer2(FoundCargoCont, new MyObjectBuilder_GasContainerObject { SubtypeName = "HydrogenBottle", GasLevel = 1 }, 1); for (int g = 0; g <= 10; g++) { addtoParachute(FoundParachute, Item_Hatch, 1); addtoParachute(FoundParachute2, Item_Hatch, 1); addtoParachute(FoundParachute3, Item_Hatch, 1); addtoParachute(FoundParachute4, Item_Hatch, 1); } // //FoundBaseMergeBlock.CubeGrid.Physics.Deactivate(); ReplaceOwner(playerId); (FoundBaseMergeBlock as MyCubeBlock)?.ChangeOwner(144115188075855876, MyOwnershipShareModeEnum.None); //TODO: change it to nps ID (FoundBaseProjector as MyCubeBlock)?.ChangeOwner(144115188075855876, MyOwnershipShareModeEnum.None); // not working player.Character.SetPosition(FoundCockpit.GetPosition()); FoundCockpit.AttachPilot(player.Character); ShowMessageInGameAndLog("Message", " before impulse"); (m_mycubegrid as IMyEntity).Physics.LinearVelocity = forvarddirection * 25; var timer = new Timer(1000); timer.AutoReset = false; timer.Elapsed += (a, b) => MyAPIGateway.Utilities.InvokeOnGameThread(() => { ShowMessageInGameAndLog("Message", " timer"); FoundMerge.Enabled = false; FoundMerge.Physics.Deactivate(); var timer2 = new Timer(5000); timer2.AutoReset = false; timer2.Elapsed += (a1, b1) => MyAPIGateway.Utilities.InvokeOnGameThread(() => { // (m_mycubegrid as IMyEntity).Physics.Activate(); FoundMerge.Physics.Activate(); (m_mycubegrid as IMyEntity).Physics.LinearVelocity = (m_mycubegrid as IMyEntity).Physics.LinearVelocity + (forvarddirection * 200); ShowMessageInGameAndLog("Message", " timer2"); busy = false; Destuctscript(); }); timer2.Start(); }); timer.Start(); } ShowMessageInGameAndLog("Message", " end"); // NeedsUpdate = MyEntityUpdateEnum.NONE; //ShowMessageInGameAndLog("Message", "end."); //Destuctscript(); } } catch { ShowMessageInGameAndLog("Message", "EXEPTION! "); } }