public static void UpdateNamesTask() { Log.Info("Updating names"); foreach (MyPlayer player in MySession.Static.Players.GetOnlinePlayers()) { string name = MyMultiplayer.Static.GetMemberName(player.Id.SteamId); MyIdentity identity = GetIdentityByNameOrId(player.Id.SteamId.ToString()); if (!player.DisplayName.Equals(name)) { Log.Info("Updating name of : " + name + " from : " + player.DisplayName); player.Identity.SetDisplayName(MyMultiplayer.Static.GetMemberName(player.Id.SteamId)); identity.SetDisplayName(MyMultiplayer.Static.GetMemberName(player.Id.SteamId)); } } }
public override void Update() { //try //{ // if (DateTime.Now >= PlayerAlertNext && file != null && file.PlayerAlertEnabled) // { // PlayerAlertNext = DateTime.Now.AddSeconds(file.SecondsBetweenPlayerAlert); // foreach (MyPlayer player in MySession.Static.Players.GetOnlinePlayers()) // { // int count = 0; // foreach (MyPlayer player2 in MySession.Static.Players.GetOnlinePlayers()) // { // if (player2.GetPosition() == null || player.GetPosition() == null) // continue; // if (Vector3.Distance(player.GetPosition(), player2.GetPosition()) <= MyMultiplayer.Static.SyncDistance) // { // count++; // } // if (count > 1) // { // NotificationMessage message = new NotificationMessage(count + " Life Signs within " + String.Format("{0:n0}", MyMultiplayer.Static.SyncDistance), 5000, "Red"); // //this is annoying, need to figure out how to check the exact world time so a duplicate message isnt possible // ModCommunication.SendMessageTo(message, player.Id.SteamId); // } // } // } // } //} //catch (Exception ex) //{ // Log.Error(ex); //} ticks++; if (ticks % 524 == 0) { List <long> idsToRemove = new List <long>(); foreach (KeyValuePair <long, DateTime> pair in blockCooldowns) { if (DateTime.Now >= pair.Value) { idsToRemove.Add(pair.Key); } } foreach (long id in idsToRemove) { blockCooldowns.Remove(id); } List <long> expiredOffers = new List <long>(); foreach (KeyValuePair <long, ShipOffer> offers in Commands.saleOffers) { if (DateTime.Now >= offers.Value.TimeOfOffer) { expiredOffers.Add(offers.Key); } } foreach (long id in expiredOffers) { Commands.saleOffers.Remove(id); } } if (ticks % 10000 == 0 && file != null && file.IdentityUpdate) { try { if (derp == TorchSessionState.Loaded && MySession.Static.Players.GetOnlinePlayers().Count > 0) { foreach (MyPlayer player in MySession.Static.Players.GetOnlinePlayers()) { if (player == null || player.Id == null) { continue; } string name = MyMultiplayer.Static.GetMemberName(player.Id.SteamId); if (name == null || string.IsNullOrEmpty(name)) { continue; } MyIdentity identity = player.Identity; if (identity == null) { continue; } if (player.Character != null && player.Character.DisplayName != null && !player.DisplayName.Equals(name)) { identity.SetDisplayName(name); } // } } } } catch (Exception ex) { Log.Info("Error on updating names"); Log.Error(ex.ToString()); return; } } }