void HideSleeper(BasePlayer player) { List <Connection> connections = new List <Connection>(); foreach (BasePlayer target in BasePlayer.activePlayerList) { if (player == target || !target.IsConnected) { continue; } connections.Add(target.net.connection); } HeldEntity heldEntity = player.GetHeldEntity(); if (heldEntity != null) { heldEntity.SetHeld(false); heldEntity.UpdateVisiblity_Invis(); heldEntity.SendNetworkUpdate(); } if (Net.sv.write.Start()) { Net.sv.write.PacketID(Message.Type.EntityDestroy); Net.sv.write.EntityID(player.net.ID); Net.sv.write.UInt8((byte)BaseNetworkable.DestroyMode.None); Net.sv.write.Send(new SendInfo(connections)); } player.UpdatePlayerCollider(false); }
private void Repeater() { if (basePlayer == null || !basePlayer.IsConnected) { GameObject.Destroy(this); return; } var activeItem = basePlayer.svActiveItemID; if (activeItem == svActiveItemID) { return; } svActiveItemID = activeItem; if (ins.IsInvisible(basePlayer)) { HeldEntity heldEntity = basePlayer.GetHeldEntity(); if (heldEntity != null) { heldEntity.SetHeld(false); } } }
private void OnPlayerTick(BasePlayer basePlayer) { if (onlinePlayers[basePlayer] != null && onlinePlayers[basePlayer].IsInvisible) { HeldEntity heldEntity = basePlayer.GetHeldEntity(); if (heldEntity != null && basePlayer.IPlayer.HasPermission(permAbilitiesWeapons)) { heldEntity.SetHeld(false); } } }
private void StartTeleportTimer(BasePlayer player, string town) { TeleportTimers[player] = timer.Once(teleportCountdown, () => { HeldEntity heldEntity = player.GetHeldEntity(); if (heldEntity != null) { heldEntity.SetHeld(false); } var canTeleport = CanTownTeleport(player, town, false); if (canTeleport is string) { player.ChatMessage(canTeleport as string); return; } if (town == "outpost") { Teleport(player, OutpostSpawns[new System.Random().Next(OutpostSpawns.Count)]); } else if (town == "bandit") { Teleport(player, BanditSpawns[new System.Random().Next(BanditSpawns.Count)]); } int currentTime = GetUnix(); if (!storedData.Cooldowns.ContainsKey(player.userID)) { storedData.Cooldowns.Add(player.userID, currentTime); } else { storedData.Cooldowns[player.userID] = currentTime; } SaveData(); TeleportTimers[player]?.Destroy(); if (TeleportTimers.ContainsKey(player)) { TeleportTimers.Remove(player); } player.ChatMessage(Lang("TeleportSuccessMessage", player.UserIDString)); }); }
private void Repeater() { var activeItem = basePlayer.GetActiveItem(); if (activeItem == lastActiveItem) { return; } lastActiveItem = activeItem; if (ins.onlinePlayers[basePlayer] != null && ins.onlinePlayers[basePlayer].IsInvisible) { HeldEntity heldEntity = basePlayer.GetHeldEntity(); if (heldEntity != null) { heldEntity.SetHeld(false); } } }
public static void Disappear(BasePlayer ply) { if (!ply.IsConnected || ply.IsInvisible || ply.HasPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot)) { return; } List <Connection> list = new List <Connection>(); foreach (BasePlayer basePlayer in BasePlayer.activePlayerList) { if (!(ply == basePlayer) && basePlayer.IsConnected && !basePlayer.IsAdmin) { list.Add(basePlayer.net.connection); } } HeldEntity heldEntity = ply.GetHeldEntity(); if (heldEntity != null) { heldEntity.SetHeld(false); heldEntity.UpdateVisiblity_Invis(); heldEntity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } var sv = Network.Net.sv; if (sv.write.Start()) { sv.write.PacketID(Message.Type.EntityDestroy); sv.write.EntityID(ply.net.ID); sv.write.UInt8(0); sv.write.Send(new SendInfo(list)); } ply.UpdatePlayerCollider(false); CommunityEntity.ServerInstance.ClientRPCEx <string>(new SendInfo { connection = ply.net.connection }, null, "AddUI", "[{\"name\":\"InvisibleIndicator\",\"parent\":\"Hud\",\"components\":[{\"type\":\"UnityEngine.UI.RawImage\",\"url\":\"https://rustasia.com/fa-eye.png\",\"color\":\"1 1 1 0.5\"},{\"type\":\"RectTransform\",\"anchormin\":\"0.175 0.017\",\"anchormax\":\"0.22 0.08\"}]}]"); ply.IsInvisible = true; }
private void Disappear(BasePlayer basePlayer, bool showNotification = true) { if (Interface.CallHook("OnVanishDisappear", basePlayer) != null) { return; } OnlinePlayer player; if (!onlinePlayers.TryGetValue(basePlayer, out player)) { player = new OnlinePlayer(); onlinePlayers[basePlayer] = player; } List <Connection> connections = new List <Connection>(); foreach (BasePlayer target in BasePlayer.activePlayerList) { if (basePlayer == target || !target.IsConnected || config.VisibleToAdmin && target.IPlayer.IsAdmin) { continue; } connections.Add(target.net.connection); } if (config.PerformanceMode) { basePlayer.limitNetworking = true; } basePlayer.syncPosition = false; HeldEntity heldEntity = basePlayer.GetHeldEntity(); if (heldEntity != null) { heldEntity.SetHeld(false); heldEntity.UpdateVisiblity_Invis(); heldEntity.SendNetworkUpdate(); } if (Net.sv.write.Start()) { Net.sv.write.PacketID(Network.Message.Type.EntityDestroy); Net.sv.write.EntityID(basePlayer.net.ID); Net.sv.write.UInt8((byte)BaseNetworkable.DestroyMode.None); Net.sv.write.Send(new SendInfo(connections)); } basePlayer.UpdatePlayerCollider(false); player.IsInvisible = true; if (player.groupSwitchTimer != null) { player.groupSwitchTimer.Destroy(); } player.groupSwitchTimer = timer.Every(5f, () => { if (basePlayer != null) { basePlayer.UpdateNetworkGroup(); } }); if (basePlayer.GetComponent <WeaponBlock>() == null && basePlayer.IPlayer.HasPermission(permAbilitiesHideWeapons)) { basePlayer.gameObject.AddComponent <WeaponBlock>(); } if (config.AppearWhileRunning && basePlayer.GetComponent <Runner>() == null) { basePlayer.gameObject.AddComponent <Runner>(); } if (config.VanishTimeout > 0f) { ulong userId = basePlayer.userID; if (timers.ContainsKey(userId)) { timers[userId].Reset(); } else { timers.Add(userId, timer.Once(config.VanishTimeout, () => { if (basePlayer != null && basePlayer.IsConnected && IsInvisible(basePlayer)) { Reappear(basePlayer); Message(basePlayer.IPlayer, "VanishTimedOut"); } timers.Remove(userId); })); } } if (!storedData.Invisible.Contains(basePlayer.userID)) { storedData.Invisible.Add(basePlayer.userID); } Subscribe(); if (config.ShowGuiIcon) { VanishGui(basePlayer); } if (showNotification) { Message(basePlayer.IPlayer, "VanishEnabled"); } }
private void Disappear(BasePlayer basePlayer) { List <Connection> connections = new List <Connection>(); foreach (BasePlayer target in BasePlayer.activePlayerList) { if (basePlayer == target || !target.IsConnected || config.VisibleToAdmin && target.IPlayer.IsAdmin) { continue; } connections.Add(target.net.connection); } if (config.PerformanceMode) { basePlayer.limitNetworking = true; } HeldEntity heldEntity = basePlayer.GetHeldEntity(); if (heldEntity != null) { heldEntity.SetHeld(false); heldEntity.UpdateVisiblity_Invis(); heldEntity.SendNetworkUpdate(); } if (Net.sv.write.Start()) { Net.sv.write.PacketID(Network.Message.Type.EntityDestroy); Net.sv.write.EntityID(basePlayer.net.ID); Net.sv.write.UInt8((byte)BaseNetworkable.DestroyMode.None); Net.sv.write.Send(new SendInfo(connections)); } basePlayer.UpdatePlayerCollider(false); if (config.ShowGuiIcon) { VanishGui(basePlayer); } if (onlinePlayers[basePlayer] != null) { onlinePlayers[basePlayer].IsInvisible = true; } Message(basePlayer.IPlayer, "VanishEnabled"); if (config.VanishTimeout > 0f) { timer.Once(config.VanishTimeout, () => { if (onlinePlayers[basePlayer] != null && onlinePlayers[basePlayer].IsInvisible) { Reappear(basePlayer); Message(basePlayer.IPlayer, "VanishTimedOut"); } }); } Subscribe(); }
private void SpectateCommand(IPlayer player, string command, string[] args) { if (player.IsServer) { Message(player, "PlayersOnly", command); return; } if (!player.HasPermission(permUse)) { Message(player, "NotAllowed", command); return; } BasePlayer basePlayer = player.Object as BasePlayer; if (basePlayer == null) { return; } if (!basePlayer.IsSpectating()) { BasePlayer target = BasePlayer.Find(string.Join(" ", args.Select(v => v.ToString()).ToArray())); if (target == null || target.IsDead()) { Message(player, "NoValidTargets"); return; } if (ReferenceEquals(target, basePlayer)) { Message(player, "SpectateSelf"); return; } if (target.IsSpectating()) { Message(player, "TargetIsSpectating", target.displayName); return; } // Store current location before spectating if (!lastPositions.ContainsKey(player.Id)) { lastPositions.Add(player.Id, basePlayer.transform.position); } else { lastPositions[player.Id] = basePlayer.transform.position; } // Prep player for spectate mode HeldEntity heldEntity = basePlayer.GetActiveItem()?.GetHeldEntity() as HeldEntity; heldEntity?.SetHeld(false); // Put player in spectate mode basePlayer.SetPlayerFlag(BasePlayer.PlayerFlags.Spectating, true); basePlayer.gameObject.SetLayerRecursive(10); basePlayer.CancelInvoke("MetabolismUpdate"); basePlayer.CancelInvoke("InventoryUpdate"); basePlayer.ClearEntityQueue(); basePlayer.SendEntitySnapshot(target); basePlayer.gameObject.Identity(); basePlayer.SetParent(target); basePlayer.SetPlayerFlag(BasePlayer.PlayerFlags.ThirdPersonViewmode, true); player.Command("camoffset 0,1.3,0"); // Notify player and store target name Message(player, "SpectateStart", target.displayName); if (!spectating.ContainsKey(player.Id)) { spectating.Add(player.Id, target.displayName); } else { spectating[player.Id] = target.displayName; } } else { // Restore player to normal mode player.Command("camoffset", "0,1,0"); basePlayer.SetParent(null); basePlayer.SetPlayerFlag(BasePlayer.PlayerFlags.Spectating, false); basePlayer.SetPlayerFlag(BasePlayer.PlayerFlags.ThirdPersonViewmode, false); basePlayer.gameObject.SetLayerRecursive(17); basePlayer.metabolism.Reset(); basePlayer.InvokeRepeating("InventoryUpdate", 1f, 0.1f * UnityEngine.Random.Range(0.99f, 1.01f)); // Restore player to previous state basePlayer.StartSleeping(); HeldEntity heldEntity = basePlayer.GetActiveItem()?.GetHeldEntity() as HeldEntity; heldEntity?.SetHeld(true); // Teleport to original location after spectating if (lastPositions.ContainsKey(player.Id)) { Vector3 lastPosition = lastPositions[player.Id]; player.Teleport(lastPosition.x, lastPosition.y + 0.3f, lastPosition.z); lastPositions.Remove(player.Id); } // Notify player and clear target name if (spectating.ContainsKey(player.Id)) { Message(player, "SpectateStop", spectating[player.Id]); spectating.Remove(player.Id); } else { Message(player, "SpectateStop", "?"); } } }