private bool HealTarget(IMyPlayer player) { if (player == null) { return(false); } float health = MyVisualScriptLogicProvider.GetPlayersHealth(player.IdentityId); if (health <= 0) { return(true); } if (health + m_healthRefillPerTick <= 100f) { MyVisualScriptLogicProvider.SetPlayersHealth(player.IdentityId, health + m_healthRefillPerTick); } else { MyVisualScriptLogicProvider.SetPlayersHealth(player.IdentityId, 100f); return(true); } return(false); }
private static void KillCharacter(ulong steamId) { Log.Info("killing character, steamid: " + steamId); var player = MySession.Static.Players.TryGetPlayerBySteamId(steamId); if (player != null) { var playerIdentity = player.Identity; playerIdentity.Character.EnableBag(false); MyVisualScriptLogicProvider.SetPlayersHealth(playerIdentity.IdentityId, 0); playerIdentity.Character.Close(); } }
public void Kill(string playerName) { /* * First we try killing the player when hes online. This is easy and fast * and can also kill the player while being seated. */ var player = Utilities.GetPlayerByNameOrId(playerName); if (player != null) { MyVisualScriptLogicProvider.SetPlayersHealth(player.IdentityId, 0); Context.Torch.CurrentSession?.Managers?.GetManager <IChatManagerServer>()?.SendMessageAsSelf ($"{player.DisplayName} was killed by an admin"); return; } /* * If we could not find the player there is a chance he is offline, in that case we try inflicting * damage to the character as the VST will not help us with offline characters. */ if (!Utilities.TryGetEntityByNameOrId(playerName, out IMyEntity entity)) { Context.Respond($"Entity '{playerName}' not found."); return; } if (entity is IMyCharacter) { var destroyable = entity as IMyDestroyableObject; destroyable.DoDamage(1000f, MyDamageType.Radioactivity, true); Context.Torch.CurrentSession?.Managers?.GetManager <IChatManagerServer>()?.SendMessageAsSelf ($"{entity.DisplayName} was killed by an admin"); } }
public void Wormholetransferout(string sendto, double xgate, double ygate, double zgate) { Vector3D gatepoint = new Vector3D(xgate, ygate, zgate); BoundingSphereD gate = new BoundingSphereD(gatepoint, Config.RadiusGate); foreach (var grid in MyAPIGateway.Entities.GetTopMostEntitiesInSphere(ref gate).OfType <IMyCubeGrid>()) { var WormholeDrives = new List <IMyJumpDrive>(); var gts = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid); if (gts == null) { continue; } gts.GetBlocksOfType(WormholeDrives); if (WormholeDrives.Count <= 0) { continue; } foreach (var WormholeDrive in WormholeDrives) { if (!Config.JumpDriveSubid.Split(',').Any(s => s.Trim() == WormholeDrive.BlockDefinition.SubtypeId) && !Config.WorkWithAllJD) { continue; } Request request = default; try { request = MyAPIGateway.Utilities.SerializeFromXML <Request>(WormholeDrive.CustomData); } catch { } string pickeddestination = default; if (request != null) { if (request.PluginRequest) { if (request.Destination != null) { if (sendto.Split(',').Any(s => s.Trim() == request.Destination.Trim())) { pickeddestination = request.Destination.Trim(); } } Request reply = new Request { PluginRequest = false, Destination = null, Destinations = sendto.Split(',').Select(s => s.Trim()).ToArray() }; WormholeDrive.CustomData = MyAPIGateway.Utilities.SerializeToXML <Request>(reply); } } else { Request reply = new Request { PluginRequest = false, Destination = null, Destinations = sendto.Split(',').Select(s => s.Trim()).ToArray() }; WormholeDrive.CustomData = MyAPIGateway.Utilities.SerializeToXML <Request>(reply); } if (Config.AutoSend && sendto.Split(',').Length == 1) { pickeddestination = sendto.Split(',')[0].Trim(); } if (pickeddestination == null) { continue; } if (!WormholeDrive.IsWorking || WormholeDrive.CurrentStoredPower != WormholeDrive.MaxStoredPower) { continue; } var playerInCharge = MyAPIGateway.Players.GetPlayerControllingEntity(grid); if (playerInCharge == null || !Utilities.HasRightToMove(playerInCharge, grid as MyCubeGrid)) { continue; } WormholeDrive.CurrentStoredPower = 0; foreach (var DisablingWormholeDrive in WormholeDrives) { if (Config.JumpDriveSubid.Split(',').Any(s => s.Trim() == DisablingWormholeDrive.BlockDefinition.SubtypeId) || Config.WorkWithAllJD) { DisablingWormholeDrive.Enabled = false; } } List <MyCubeGrid> grids = Utilities.FindGridList(grid.EntityId.ToString(), playerInCharge as MyCharacter, Config.IncludeConnectedGrids); if (grids == null) { return; } if (grids.Count == 0) { return; } MyVisualScriptLogicProvider.CreateLightning(gatepoint); //NEED TO DROP ENEMY GRIDS if (Config.WormholeGates.Any(s => s.Name.Trim() == pickeddestination.Split(':')[0])) { foreach (WormholeGate internalwormhole in Config.WormholeGates) { if (internalwormhole.Name.Trim() == pickeddestination.Split(':')[0].Trim()) { var box = WormholeDrive.GetTopMostParent().WorldAABB; var togatepoint = new Vector3D(internalwormhole.X, internalwormhole.Y, internalwormhole.Z); var togate = new BoundingSphereD(togatepoint, Config.RadiusGate); Utilities.UpdateGridsPositionAndStopLive(WormholeDrive.GetTopMostParent(), Utilities.FindFreePos(togate, (float)(Vector3D.Distance(box.Center, box.Max) + 50))); MyVisualScriptLogicProvider.CreateLightning(togatepoint); } } } else { var destination = pickeddestination.Split(':'); var filename = $"{destination[0]}_{playerInCharge.SteamUserId}_{Utilities.LegalCharOnly(playerInCharge.DisplayName)}_{Utilities.LegalCharOnly(grid.DisplayName)}_{DateTime.Now:yyyy_MM_dd_HH_mm_ss}"; List <MyObjectBuilder_CubeGrid> objectBuilders = new List <MyObjectBuilder_CubeGrid>(); foreach (MyCubeGrid mygrid in grids) { if (!(mygrid.GetObjectBuilder(true) is MyObjectBuilder_CubeGrid objectBuilder)) { throw new ArgumentException(mygrid + " has a ObjectBuilder thats not for a CubeGrid"); } objectBuilders.Add(objectBuilder); } MyObjectBuilder_ShipBlueprintDefinition definition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>(); definition.Id = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)), filename); definition.CubeGrids = objectBuilders.Select(x => (MyObjectBuilder_CubeGrid)x.Clone()).ToArray(); List <ulong> playerIds = new List <ulong>(); foreach (MyObjectBuilder_CubeGrid cubeGrid in definition.CubeGrids) { foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.CubeBlocks) { cubeBlock.Owner = 0L; cubeBlock.BuiltBy = 0L; if (!Config.ExportProjectorBlueprints) { if (cubeBlock is MyObjectBuilder_ProjectorBase projector) { projector.ProjectedGrids = null; } } if (cubeBlock is MyObjectBuilder_Cockpit cockpit) { if (cockpit.Pilot != null) { var playersteam = cockpit.Pilot.PlayerSteamId; var player = Utilities.GetIdentityByNameOrId(playersteam.ToString()); playerIds.Add(playersteam); ModCommunication.SendMessageTo(new JoinServerMessage(destination[1] + ":" + destination[2]), playersteam); } } } } MyObjectBuilder_Definitions builderDefinition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>(); builderDefinition.ShipBlueprints = new[] { definition }; foreach (var playerId in playerIds) { var player = Utilities.GetIdentityByNameOrId(playerId.ToString()); player.Character.EnableBag(false); MyVisualScriptLogicProvider.SetPlayersHealth(player.IdentityId, 0); player.Character.Close(); } if (MyObjectBuilderSerializer.SerializeXML(Utilities.CreateBlueprintPath(Path.Combine(Config.Folder, admingatesfolder), filename), false, builderDefinition)) { grids.ForEach(b => b.Close()); } } } } }
public void Wormholetransferin(string name, double xgate, double ygate, double zgate) { Vector3D gatepoint = new Vector3D(xgate, ygate, zgate); BoundingSphereD gate = new BoundingSphereD(gatepoint, Config.RadiusGate); DirectoryInfo gridDir = new DirectoryInfo(Config.Folder + "/" + admingatesfolder); if (!gridDir.Exists) { return; } if (!gridDir.GetFiles().Any(s => s.Name.Split('_')[0] == name)) { return; } foreach (var file in gridDir.GetFiles()) { if (file == null) { continue; } var filedataarray = file.Name.Split('_'); if (filedataarray[0] != name) { continue; } Log.Info("yay we are going to load file: " + file.Name); var player = Utilities.GetIdentityByNameOrId(filedataarray[1]); if (player == null) { continue; } var playerid = 0L; playerid = player.IdentityId; if (!File.Exists(file.FullName)) { continue; } if (!MyObjectBuilderSerializer.DeserializeXML(file.FullName, out MyObjectBuilder_Definitions myObjectBuilder_Definitions)) { continue; } var shipBlueprints = myObjectBuilder_Definitions.ShipBlueprints; if (shipBlueprints == null) { continue; } foreach (var shipBlueprint in shipBlueprints) { var grids = shipBlueprint.CubeGrids; if (grids == null || grids.Length == 0) { continue; } var pos = Utilities.FindFreePos(gate, Utilities.FindGridsRadius(grids)); if (pos == null) { Log.Warn("Unable to load grid no free space found at Wormhole: " + name); continue; } if (Utilities.UpdateGridsPositionAndStop(grids, pos)) { foreach (var mygrid in grids) { foreach (MyObjectBuilder_CubeBlock block in mygrid.CubeBlocks) { block.BuiltBy = playerid; block.Owner = playerid; if (!(block is MyObjectBuilder_Cockpit cockpit) || cockpit.Pilot == null) { continue; } var seatedplayerid = MyAPIGateway.Multiplayer.Players.TryGetIdentityId(cockpit.Pilot.PlayerSteamId); if (seatedplayerid == -1) { cockpit.Pilot = null; continue; } var myplayer = MySession.Static.Players.TryGetIdentity(seatedplayerid); if (seatedplayerid == -1 || !Config.PlayerRespawn) { cockpit.Pilot = null; continue; } cockpit.Pilot.OwningPlayerIdentityId = seatedplayerid; if (myplayer.Character != null) { if (Config.ThisIp != null && Config.ThisIp != "") { ModCommunication.SendMessageTo(new JoinServerMessage(Config.ThisIp), cockpit.Pilot.PlayerSteamId); } myplayer.Character.EnableBag(false); MyVisualScriptLogicProvider.SetPlayersHealth(seatedplayerid, 0); myplayer.Character.Close(); } myplayer.PerformFirstSpawn(); myplayer.SavedCharacters.Clear(); myplayer.SavedCharacters.Add(cockpit.Pilot.EntityId); MyAPIGateway.Multiplayer.Players.SetControlledEntity(cockpit.Pilot.PlayerSteamId, cockpit.Pilot as VRage.ModAPI.IMyEntity); } } } List <MyObjectBuilder_EntityBase> objectBuilderList = new List <MyObjectBuilder_EntityBase>(grids.ToList()); MyEntities.RemapObjectBuilderCollection(objectBuilderList); if (objectBuilderList.Count > 1) { if (MyEntities.Load(objectBuilderList, out _)) { file.Delete(); } else { foreach (var ob in objectBuilderList) { if (MyEntities.CreateFromObjectBuilderParallel(ob, true) != null) { file.Delete(); } } } } MyVisualScriptLogicProvider.CreateLightning(gatepoint); } } }
public override void UpdateBeforeSimulation() { if (MyAPIGateway.Multiplayer.IsServer == false) { return; } if (scriptInit == false) { scriptInit = true; var definitionId = new MyDefinitionId(typeof(MyObjectBuilder_Component), "Nadium_Radioactive"); radioactive_nadium = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId); definitionId = new MyDefinitionId(typeof(MyObjectBuilder_Ore), "Unknown_Element"); electromagnetic_element = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId); definitionId = new MyDefinitionId(typeof(MyObjectBuilder_Component), "composite_plate"); composite_plate = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId); } tickTimer++; if (tickTimer < 180) { return; } tickTimer = 0; var playerList = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(playerList); if (playerList.Count == 0) { return; } foreach (var player in playerList) { if (player.IsBot == true) { continue; } if (player.Character == null) { continue; } float health = MyVisualScriptLogicProvider.GetPlayersHealth(player.IdentityId); float energy = MyVisualScriptLogicProvider.GetPlayersEnergyLevel(player.IdentityId); if (health <= 0) { continue; } var playerInv = player.Character.GetInventory(); MyFixedPoint amount = playerInv.GetItemAmount(electromagnetic_element); MyFixedPoint composite_plate_amount = playerInv.GetItemAmount(composite_plate); if (playerInv.ContainItems(1, radioactive_nadium) == true) { MyVisualScriptLogicProvider.SetPlayersHealth(player.IdentityId, health - 5); health = MyVisualScriptLogicProvider.GetPlayersHealth(player.IdentityId); MyVisualScriptLogicProvider.ShowNotification(">>> WARNING RADIATION ALERT <<<\n\nToxic Nadium radiation detected\nIntensity: 2,5 Rad/s", 2000, "Red", player.IdentityId); //MyVisualScriptLogicProvider.ShowNotificationToAll("WARNING RADIATION ALERT\n\nDetected toxic substance\n\nTriNadiumTaloxid-438", 2000, "White"); } if (playerInv.ContainItems(1, composite_plate) == true) { playerInv.RemoveItemsOfType(composite_plate_amount, composite_plate); MyVisualScriptLogicProvider.SetPlayersHealth(player.IdentityId, health - 50); health = MyVisualScriptLogicProvider.GetPlayersHealth(player.IdentityId); MyVisualScriptLogicProvider.ShowNotification(">>> WARNING RADIATION ALERT <<<\n\nUnknown radiation detected\nIntensity: 50 Rad/s", 2000, "Red", player.IdentityId); } if (playerInv.ContainItems(1, electromagnetic_element) == true) { if (energy <= 0) { MyVisualScriptLogicProvider.SetPlayersEnergyLevel(player.IdentityId, 0); } else { MyVisualScriptLogicProvider.SetPlayersEnergyLevel(player.IdentityId, energy - .04f); playerInv.RemoveItemsOfType(amount, electromagnetic_element); energy = MyVisualScriptLogicProvider.GetPlayersEnergyLevel(player.IdentityId); MyVisualScriptLogicProvider.ShowNotification(">>> INTERNAL ENERGY LOSS DETECTED <<<", 2000, "White", player.IdentityId); } } } }