public static void WaypointMessage(WaypointItem item) { string messageString = MyAPIGateway.Utilities.SerializeToXML(item); byte[] data = Encoding.Unicode.GetBytes(messageString); SendDataMessage(item.SteamId, DataMessageType.Waypoint, data); }
public void Add(WaypointItem item) { lock (Instance) { waypointItems.Add(item); Save(); } }
private static void ToggleItem(ulong steamId, WaypointItem item) { if (item.Toggle.Contains(steamId)) { item.Toggle.Remove(steamId); } else { item.Toggle.Add(steamId); } }
public static void WaypointMessage(ServerWaypointItem serverItem) { WaypointItem item = new WaypointItem( ); item.Name = serverItem.Name; item.Position = new Vector3D(serverItem.X, serverItem.Y, serverItem.Z); item.Remove = serverItem.Enabled; item.SteamId = 0; item.Text = serverItem.Name; string messageString = MyAPIGateway.Utilities.SerializeToXML(item); byte[] data = Encoding.Unicode.GetBytes(messageString); BroadcastDataMessage(DataMessageType.Waypoint, data); }
public bool GroupRemove(ulong steamId, string name) { lock (Instance) { WaypointItem item = waypointItems.FirstOrDefault(x => x.SteamId == steamId && x.Name.ToLower() == name.ToLower()); if (item == null) { return(false); } item.Group = ""; Save(); return(true); } }
public bool GroupExists(ulong steamId, string group) { lock (Instance) { WaypointItem item = waypointItems.FirstOrDefault(x => x.SteamId == steamId && x.Group.ToLower() == group.ToLower()); if (item != null) { return(true); } long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(steamId); IMyFaction faction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerId); if (faction != null) { item = waypointItems.FirstOrDefault(x => x.SteamId == (ulong)faction.FactionId && x.Group.ToLower() == group.ToLower()); if (item != null) { return(true); } } return(false); } }
public override bool HandleCommand(ulong userId, string[] words) { if (!PluginSettings.Instance.WaypointsEnabled) return false; if (words.Length != 1 && words.Length != 5 && words.Length != 6 && words.Length != 7) { Communication.SendPrivateInformation(userId, GetHelp()); return true; } List<WaypointItem> items = Waypoints.Instance.Get(userId); if (PluginSettings.Instance.WaypointsMaxPerPlayer > 0 && items.Count >= PluginSettings.Instance.WaypointsMaxPerPlayer) { Communication.SendPrivateInformation(userId, string.Format("Waypoint limit has been reached. You may only have {0} waypoints at a time on this server. Please remove some waypoints in order to add new ones.", PluginSettings.Instance.WaypointsMaxPerPlayer)); return true; } if (words.Length == 1) { long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId); IMyEntity playerEntity = Player.FindControlledEntity(playerId); if(playerEntity == null) { Communication.SendPrivateInformation(userId, string.Format("Can't find your position")); return true; } Vector3D pos = playerEntity.GetPosition(); string name = words[0]; Communication.SendClientMessage(userId, string.Format("/waypoint add '{0}' '{0}' Neutral {1} {2} {3}", name, Math.Floor(pos.X), Math.Floor(pos.Y), Math.Floor(pos.Z))); WaypointItem item = new WaypointItem(); item.SteamId = userId; item.Name = name; item.Text = name; item.Position = pos; item.WaypointType = WaypointTypes.Neutral; Waypoints.Instance.Add(item); Communication.SendPrivateInformation(userId, string.Format("Waypoint added: '{0}' at {1}", item.Name, General.Vector3DToString(item.Position))); } else { int len = 5; if (words.Length > 5) len = 6; for (int r = len - 3; r < len; r++) { double test = 0d; if (!double.TryParse(words[r], out test)) { Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", words[r])); return true; } } string add = ""; foreach (string word in words) { if (add == "") add += word.ToLower(); else add += " " + word; } Communication.SendClientMessage(userId, string.Format("/waypoint add {0}", add)); string group = ""; if (words.Length == 7) group = words[7]; WaypointItem item = new WaypointItem(); item.SteamId = userId; item.Name = words[0]; int diff = words.Length > 5 ? 1 : 0; item.Text = words[diff]; WaypointTypes type = WaypointTypes.Neutral; Enum.TryParse<WaypointTypes>(words[diff + 1], true, out type); item.WaypointType = type; item.Position = new Vector3D(double.Parse(words[diff + 2]), double.Parse(words[diff + 3]), double.Parse(words[diff + 4])); item.Group = group; Waypoints.Instance.Add(item); Communication.SendPrivateInformation(userId, string.Format("Waypoint added: '{0}' at {1}", item.Name, General.Vector3DToString(item.Position))); } return true; }
public override void Handle() { lock (m_waypointAdd) { if(m_waypointAdd.Count < 1) return; } if (MyAPIGateway.Players == null) return; List<IMyPlayer> players = new List<IMyPlayer>(); bool result = false; Wrapper.GameAction(() => { try { MyAPIGateway.Players.GetPlayers(players, null); result = true; } catch (Exception ex) { Logging.WriteLineAndConsole(string.Format("Waypoints(): Unable to get player list: {0}", ex.ToString())); } }); if (!result) return; lock (m_waypointAdd) { for (int r = m_waypointAdd.Count - 1; r >= 0; r--) { ulong steamId = m_waypointAdd[r]; IMyPlayer player = players.FirstOrDefault(x => x.SteamUserId == steamId && x.Controller != null && x.Controller.ControlledEntity != null); if (player != null) { Logging.WriteLineAndConsole("Player in game, creating waypoints"); m_waypointAdd.Remove(steamId); // Add defaults if (Waypoints.Instance.Get(steamId).Count < 1) { foreach (ServerWaypointItem item in PluginSettings.Instance.WaypointDefaultItems) { WaypointItem newItem = new WaypointItem(); newItem.Name = item.Name; newItem.Text = item.Name; newItem.WaypointType = WaypointTypes.Neutral; newItem.Position = new Vector3D(item.X, item.Y, item.Z); newItem.SteamId = steamId; Waypoints.Instance.Add(newItem); } } Waypoints.SendClientWaypoints(steamId); } } } base.Handle(); }
public static void WaypointMessage( ServerWaypointItem serverItem ) { WaypointItem item = new WaypointItem( ); item.Name = serverItem.Name; item.Position = new Vector3D( serverItem.X, serverItem.Y, serverItem.Z ); item.Remove = serverItem.Enabled; item.SteamId = 0; item.Text = serverItem.Name; string messageString = MyAPIGateway.Utilities.SerializeToXML( item ); byte[ ] data = Encoding.Unicode.GetBytes( messageString ); BroadcastDataMessage( DataMessageType.Waypoint, data ); }
public static void WaypointMessage( WaypointItem item ) { string messageString = MyAPIGateway.Utilities.SerializeToXML( item ); byte[ ] data = Encoding.Unicode.GetBytes( messageString ); SendDataMessage( item.SteamId, DataMessageType.Waypoint, data ); }
public override bool HandleCommand(ulong userId, string[] words) { if (!PluginSettings.Instance.WaypointsEnabled) return false; if (words.Length != 6 && words.Length != 7 && words.Length != 1) { Communication.SendPrivateInformation(userId, GetHelp()); return true; } string playerName = PlayerMap.Instance.GetPlayerNameFromSteamId(userId); long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId); IMyFaction faction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerId); if (faction == null) { Communication.SendPrivateInformation(userId, string.Format("Unable to find your faction information. You must be in a faction to use this.")); return true; } List<WaypointItem> items = Waypoints.Instance.Get((ulong)faction.FactionId); if (PluginSettings.Instance.WaypointsMaxPerFaction > 0 && items.Count >= PluginSettings.Instance.WaypointsMaxPerFaction) { Communication.SendPrivateInformation(userId, string.Format("Waypoint limit has been reached. You may only have {0} faction waypoints at a time on this server. Please remove some waypoints in order to add new ones.", PluginSettings.Instance.WaypointsMaxPerPlayer)); return true; } if (words.Length == 1) { IMyEntity playerEntity = Player.FindControlledEntity(playerId); if(playerEntity == null) { Communication.SendPrivateInformation(userId, string.Format("Can't find your position")); return true; } Vector3D pos = playerEntity.GetPosition(); string name = words[0]; foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers) { if (Player.CheckPlayerSameFaction(userId, steamId)) { Communication.WaypointMessage(steamId, string.Format("add '{0}' '{0}' Neutral {1} {2} {3}", name, Math.Floor(pos.X), Math.Floor(pos.Y), Math.Floor(pos.Z))); } } WaypointItem item = new WaypointItem { SteamId = (ulong) faction.FactionId, Name = name, Text = name, Position = pos, WaypointType = WaypointTypes.Neutral, Leader = faction.IsLeader( playerId ) }; Waypoints.Instance.Add(item); Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: '{0}' at {1} by '{2}'", item.Name, General.Vector3DToString(item.Position), playerName)); } else { for (int r = 3; r < 6; r++) { double test; if (!double.TryParse(words[r], out test)) { Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", words[r])); return true; } } string add = string.Join(" ", words.Select(s => s.ToLowerInvariant())); foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers) { if (Player.CheckPlayerSameFaction(userId, steamId)) { Communication.WaypointMessage(steamId, string.Format("add {0}", add)); } } string group = ""; if (words.Length == 7) group = words[7]; WaypointItem item = new WaypointItem { SteamId = (ulong) faction.FactionId, Name = words[0], Text = words[1] }; WaypointTypes type; Enum.TryParse(words[2], true, out type); item.WaypointType = type; item.Position = new Vector3D(double.Parse(words[3]), double.Parse(words[4]), double.Parse(words[5])); item.Group = group; item.Leader = faction.IsLeader(playerId); Waypoints.Instance.Add(item); Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: '{0}' at {1} by '{2}'", item.Name, General.Vector3DToString(item.Position), playerName)); } return true; }
private static void ToggleItem(ulong steamId, WaypointItem item) { if (item.Toggle.Contains(steamId)) item.Toggle.Remove(steamId); else item.Toggle.Add(steamId); }