public override bool Invoke(ulong steamId, long playerId, string messageText) { MatrixD worldMatrix; if (MyAPIGateway.Session.CameraController is MySpectator) { worldMatrix = MyAPIGateway.Session.Camera.WorldMatrix; } else if (MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.Parent == null) { worldMatrix = MyAPIGateway.Session.Player.Controller.ControlledEntity.GetHeadMatrix(true, true, false); // dead center of player cross hairs. worldMatrix.Translation = worldMatrix.Translation + worldMatrix.Forward * 2.5f; // Spawn item 1.5m in front of player for safety. } else { worldMatrix = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.WorldMatrix; worldMatrix.Translation = worldMatrix.Translation + worldMatrix.Forward * 2.5f + worldMatrix.Up * 0.5f; // Spawn item 1.5m in front of player in cockpit for safety. } MessageSyncAres.SpawnBot(steamId, "SpaceSpider", new SerializableMatrix(worldMatrix)); return(true); }
public override bool Invoke(ulong steamId, long playerId, string messageText) { var match = Regex.Match(messageText, @"/smite\s+(?:(?:""(?<name>[^""]|.*?)"")|(?<name>.*))", RegexOptions.IgnoreCase); if (match.Success) { var playerName = match.Groups["name"].Value; var players = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(players, p => p != null); IMyPlayer selectedPlayer = null; var findPlayer = players.FirstOrDefault(p => p.DisplayName.Equals(playerName, StringComparison.InvariantCultureIgnoreCase)); if (findPlayer != null) { selectedPlayer = findPlayer; } int index; List <IMyIdentity> cacheList = CommandPlayerStatus.GetIdentityCache(steamId); if (playerName.Substring(0, 1) == "#" && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count) { var listplayers = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(listplayers, p => p.IdentityId == cacheList[index - 1].IdentityId); selectedPlayer = listplayers.FirstOrDefault(); } if (selectedPlayer == null) { MyAPIGateway.Utilities.SendMessage(steamId, "Smite", "No player named '{0}' found.", playerName); return(true); } MyAPIGateway.Utilities.SendMessage(steamId, "smiting", selectedPlayer.DisplayName); MessageSyncAres.Smite(selectedPlayer.SteamUserId, _defaultOreName); return(true); } return(false); }
public override bool Invoke(ulong steamId, long playerId, string messageText) { var match = Regex.Match(messageText, @"/eject\s+(?:(?:""(?<name>[^""]|.*?)"")|(?<name>.*))", RegexOptions.IgnoreCase); if (match.Success) { var playerName = match.Groups["name"].Value; var players = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(players, p => p != null); IMyPlayer selectedPlayer = null; var findPlayer = players.FirstOrDefault(p => p.DisplayName.Equals(playerName, StringComparison.InvariantCultureIgnoreCase)); if (findPlayer != null) { selectedPlayer = findPlayer; } int index; List <IMyIdentity> cacheList = CommandPlayerStatus.GetIdentityCache(steamId); if (playerName.Substring(0, 1) == "#" && int.TryParse(playerName.Substring(1), out index) && index > 0 && index <= cacheList.Count) { var listplayers = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(listplayers, p => p.PlayerID == cacheList[index - 1].PlayerId); selectedPlayer = listplayers.FirstOrDefault(); } if (selectedPlayer == null) { MyAPIGateway.Utilities.SendMessage(steamId, "Eject", "No player named '{0}' found.", playerName); return(true); } MessageSyncAres.Eject(selectedPlayer.SteamUserId); return(true); // NPC's do not appears as Players, but Identities. // There could be multiple Identities with the same name, for active, inactive and dead. //if (playerName.Substring(0, 1) == "B" && Int32.TryParse(playerName.Substring(1), out index) && index > 0 && index <= CommandListBots.BotCache.Count) //{ // selectedPlayer = CommandListBots.BotCache[index - 1]; //} // TODO: figure out how to eject Autopilot. //var entities = new HashSet<IMyEntity>(); //MyAPIGateway.Entities.GetEntities(entities, e => e is IMyCubeGrid); //foreach (var entity in entities) //{ // var cockpits = entity.FindWorkingCockpits(); // foreach (var cockpit in cockpits) // { // var block = (IMyCubeBlock)cockpit; // if (block.OwnerId == selectedPlayer.PlayerId) // { // MyAPIGateway.Utilities.SendMessage(steamId, "ejecting", selectedPlayer.DisplayName); // // Does not appear to eject Autopilot. // cockpit.Use(); // } // } //} } return(false); }