/// <summary> /// Gets a code to uniquely identify a given player. These are synced to the server in multiplayer. /// </summary> /// <param name="player"></param> /// <returns></returns> public static string GetUniqueId(Player player) { var plrIdLibs = ModContent.GetInstance <PlayerIdentityLibraries>(); string id; if (!plrIdLibs.PlayerIds.TryGetValue(player.whoAmI, out id)) { if (Main.netMode != NetmodeID.Server && player.whoAmI == Main.myPlayer) { id = PlayerIdentityLibraries.GetUniqueId(); plrIdLibs.PlayerIds[player.whoAmI] = id; } else { //throw new ModLibsException( "!ModLibsGeneral.PlayerIdentityLibraries.GetProperUniqueId - Could not find player " + player.name + "'s id." ); return(null); } } return(id); }
/// <summary> /// Gets an active player by a given unique id (if present). /// </summary> /// <param name="uid"></param> /// <returns></returns> public static Player GetPlayerByUniqueId(string uid) { int len = Main.player.Length; for (int i = 0; i < len; i++) { Player plr = Main.player[i]; //LogLibraries.Log( "GetPlayerByProperId: "+PlayerIdentityLibraries.GetProperUniqueId( plr )+" == "+uid+": "+plr.name+" ("+plr.whoAmI+")" ); if (plr == null /*|| !plr.active*/) { continue; } // <- This is WEIRD! if (PlayerIdentityLibraries.GetUniqueId(plr) == uid) { return(plr); } } return(null); }