/// <summary> /// Sends a console message to a <see cref="ReferenceHub"/> /// </summary> /// <param name="player"></param> /// <param name="message"></param> /// <param name="color"></param> public static void SendConsoleMessage(this ReferenceHub player, string message, string color) { player.characterClassManager.TargetConsolePrint(player.GetConnection(), message, color); }
/// <summary> /// Sets a player's UserID /// </summary> /// <param name="player"></param> /// <param name="newId"></param> /// <returns></returns> public static void SetUserId(this ReferenceHub player, string newId) => player.characterClassManager.NetworkSyncedUserId = newId;
/// <summary> /// Unmutes a <see cref="ReferenceHub">player</see>. /// </summary> /// <param name="player"></param> public static void Unmute(this ReferenceHub player) => player.characterClassManager.NetworkMuted = false;
/// <summary> /// Gets the <see cref="Team"/> a <see cref="ReferenceHub"/> belongs to. /// </summary> /// <param name="player">Player</param> /// <returns>Team</returns> public static Team GetTeam(this ReferenceHub player) => player.GetRole().GetTeam();
/// <summary> /// Gets the reference hub belonging to the player who's name most closely matches the string given, if any. /// </summary> /// <param name="args">Player's Name</param> /// <returns>ReferenceHub or null</returns> public static ReferenceHub GetPlayer(string args) { try { if (StrHubs.ContainsKey(args)) { return(StrHubs[args]); } ReferenceHub playerFound = null; if (short.TryParse(args, out short playerId)) { return(GetPlayer(playerId)); } if (args.EndsWith("@steam") || args.EndsWith("@discord") || args.EndsWith("@northwood") || args.EndsWith("@patreon")) { Log.Debug("Trying to find by UserID..."); foreach (ReferenceHub player in GetHubs()) { if (player.GetUserId() == args) { playerFound = player; Log.Debug("Found UserID match."); } } } else { Log.Debug($"Trying to find by name... {args}"); if (args == "WORLD" || args == "SCP-018" || args == "SCP-575" || args == "SCP-207") { return(null); } int maxNameLength = 31, lastnameDifference = 31; string str1 = args.ToLower(); foreach (ReferenceHub player in GetHubs()) { if (!player.GetNickname().ToLower().Contains(args.ToLower())) { continue; } if (str1.Length < maxNameLength) { int x = maxNameLength - str1.Length; int y = maxNameLength - player.GetNickname().Length; string str2 = player.GetNickname(); for (int i = 0; i < x; i++) { str1 += "z"; } for (int i = 0; i < y; i++) { str2 += "z"; } int nameDifference = LevenshteinDistance.Compute(str1, str2); if (nameDifference < lastnameDifference) { lastnameDifference = nameDifference; playerFound = player; Log.Debug("Found name match."); } } } } if (playerFound != null) { StrHubs.Add(args, playerFound); } return(playerFound); } catch (Exception exception) { Log.Error($"GetPlayer error: {exception}"); return(null); } }
/// <summary> /// Shows the tag of a <see cref="ReferenceHub"/>. /// </summary> /// <param name="player"></param> /// <param name="isGlobal"></param> private static void ShowTag(this ReferenceHub player, bool isGlobal = false) => player.characterClassManager.CallCmdRequestShowTag(isGlobal);
public static void Broadcast(this ReferenceHub player, uint time, string message) => Map.BroadcastComponent.TargetAddElement(player.scp079PlayerScript.connectionToClient, message, time, false);
/// <summary> /// Sets the position of a <see cref="ReferenceHub"/> using a <see cref="Vector3"/>. /// </summary> public static void SetPosition(this ReferenceHub player, Vector3 position) => player.SetPosition(position.x, position.y, position.z);
/// <summary> /// Sets the position of a <see cref="ReferenceHub"/> using the x, y, and z of the destination position. /// </summary> public static void SetPosition(this ReferenceHub player, float x, float y, float z) => player.plyMovementSync.OverridePosition(new Vector3(x, y, z), player.transform.rotation.eulerAngles.y);
/// <summary> /// Gets the rotations from a <see cref="ReferenceHub"/> /// </summary> /// <returns>A <see cref="Vector2"/>, representing the directions he's looking at</returns> public static Vector2 GetRotations(this ReferenceHub player) => player.plyMovementSync.NetworkRotations;
/// <summary> /// Gets the rotation of a <see cref="ReferenceHub"/>. /// </summary> /// <returns>The direction he's looking at, useful for Raycasts</returns> public static Vector3 GetRotationVector(this ReferenceHub player) => player.characterClassManager.Scp049.plyCam.transform.forward;
/// <summary> /// Gets the position of a <see cref="ReferenceHub"/> /// </summary> public static Vector3 GetPosition(this ReferenceHub player) => player.plyMovementSync.GetRealPosition();
public LockerInteractionEvent(ReferenceHub rh, Locker locker, int lockerId) { Player = rh; Locker = locker; LockerId = lockerId; }
/// <summary> /// Sets the players Friendly Fire value. /// Note: This only allows them to DEAL FF damage, not TAKE FF damage. /// </summary> /// <param name="player"></param> /// <param name="value"></param> public static void SetFriendlyFire(this ReferenceHub player, bool value) => player.weaponManager.NetworkfriendlyFire = value;
/// <summary> /// Sets the nickname of a <see cref="ReferenceHub"/> to <paramref name="nickname"/> /// </summary> public static void SetNickname(this ReferenceHub player, string nickname) { player.nicknameSync.Network_myNickSync = nickname; MEC.Timing.RunCoroutine(BlinkTag(player)); }
/// <summary> /// Sets the rotation of a <see cref="ReferenceHub"/> using a <see cref="Vector2"/>. /// </summary> public static void SetRotation(this ReferenceHub player, Vector2 rotations) => player.SetRotation(rotations.x, rotations.y);
/// <summary> /// Hides the tag of a <see cref="ReferenceHub"/>. /// </summary> /// <param name="player"></param> private static void HideTag(this ReferenceHub player) => player.characterClassManager.CallCmdRequestHideTag();
/// <summary> /// Sets the rotation of a <see cref="ReferenceHub"/> using the x and y values of the desired rotation. /// </summary> public static void SetRotation(this ReferenceHub player, float x, float y) => player.plyMovementSync.NetworkRotations = new Vector2(x, y);
public static void GiveItem(this ReferenceHub player, ItemType itemType, float duration = float.NegativeInfinity, int sight = 0, int barrel = 0, int other = 0) => player.inventory.AddNewItem(itemType, duration, sight, barrel, other);
/// <summary> /// Sets the rank of a <see cref="ReferenceHub"/> to a <see cref="UserGroup"/>. /// Can be null. /// </summary> public static UserGroup GetRank(this ReferenceHub player) => player.serverRoles.Group;
/// <summary> /// Clears the brodcast of a <see cref="ReferenceHub"/>. Doesn't get logged to the console. /// </summary> /// <param name="player"></param> public static void ClearBroadcasts(this ReferenceHub player) => Map.BroadcastComponent.TargetClearElements(player.scp079PlayerScript.connectionToClient);
/// <summary> /// Sets the rank color of a <see cref="ReferenceHub"/> to a given color with a <see cref="string"/>. /// </summary> public static void SetRankColor(this ReferenceHub player, string color) => player.serverRoles.SetColor(color);
/// <summary> /// Gets the Reference hub belonging to the GameObject, if any. /// </summary> /// <param name="player">object</param> /// <returns>ReferenceHub or null</returns> public static ReferenceHub GetPlayer(this GameObject player) => ReferenceHub.GetHub(player);
/// <summary> /// Sets the rank name of a <see cref="ReferenceHub"/> to a given <see cref="string"/>. /// </summary> public static void SetRankName(this ReferenceHub player, string name) => player.serverRoles.SetText(name);
/// <summary> /// Gets a player's UserID /// </summary> /// <param name="player">Player</param> /// <returns>string, can be empty.</returns> public static string GetUserId(this ReferenceHub player) => player.characterClassManager.UserId;
/// <summary> /// Sets the rank of a <see cref="ReferenceHub"/> to a <see cref="UserGroup"/>. /// </summary> public static void SetRank(this ReferenceHub player, UserGroup userGroup) => player.serverRoles.SetGroup(userGroup, false, false, false);
/// <summary> /// Gets a player's PlayerID /// </summary> /// <param name="player">Player</param> /// <returns>int PlayerID</returns> public static int GetPlayerId(this ReferenceHub player) => player.queryProcessor.PlayerId;
/// <summary> /// Gets the nickname of a <see cref="ReferenceHub"/> /// </summary> public static string GetNickname(this ReferenceHub player) => player.nicknameSync.Network_myNickSync;
/// <summary> /// Gets a <see cref="ReferenceHub">player</see> mute status. /// </summary> /// <param name="player"></param> /// <returns>True if muted, false if not</returns> public static bool IsMuted(this ReferenceHub player) => player.characterClassManager.NetworkMuted;
/// <summary> /// Sets a player's role. /// </summary> /// <param name="player"></param> /// <param name="newRole"></param> public static void SetRole(this ReferenceHub player, RoleType newRole) => player.characterClassManager.SetPlayersClass(newRole, player.gameObject);