diff --git a/TeleportDoors.cs b/TeleportDoors.cs index 37b0f18..6625643 100644 --- a/TeleportDoors.cs +++ b/TeleportDoors.cs @@ -7,62 +7,45 @@ using System.Linq; using UnityEngine; namespace Oxide.Plugins { - [Info("TeleportDoors", "bmgjet", "1.0.1")] + [Info("TeleportDoors", "bmgjet", "1.0.2")] [Description("Using this door/button will take you to its teleport location")] public class TeleportDoors : RustPlugin { [PluginReference] private Plugin Vanish; - public const string permUse = "TeleportDoors.use"; + public const string permUse = "TeleportDoors.use"; private class TPEntity { public Vector3 TPLocation; public string Name = "Going To New Zone"; public string CMD = ""; public string SFX = ""; } Dictionary _TPEntity = new Dictionary(); - private void Init(){permission.RegisterPermission(permUse, this);} + private void Init() { permission.RegisterPermission(permUse, this); } private void OnServerInitialized(bool initial) { if (initial) { Fstartup(); return; } Startup(); } private bool IsInvisible(BasePlayer player) { return Vanish != null && Vanish.Call("IsInvisible", player); } + private void AdjustConnectionScreen(BasePlayer player, string msg) { if (Net.sv.write.Start()) { Net.sv.write.PacketID(Message.Type.Message); Net.sv.write.String(msg); Net.sv.write.Send(new SendInfo(player.Connection)); } } + private void OnDoorOpened(Door thisdoor, BasePlayer player) { if (thisdoor == null || player == null || thisdoor.OwnerID != 0 || !permission.UserHasPermission(player.UserIDString, permUse)) { thisdoor.CloseRequest(); return; } if (_TPEntity.ContainsKey(thisdoor)) { Teleport(player, _TPEntity[thisdoor]); thisdoor.Invoke(thisdoor.CloseRequest, 0.5f); } } + private void OnButtonPress(PressButton thisbutton, BasePlayer player) { if (thisbutton == null || player == null || thisbutton.OwnerID != 0 || !permission.UserHasPermission(player.UserIDString, permUse)) return; if (_TPEntity.ContainsKey(thisbutton)) { Teleport(player, _TPEntity[thisbutton]); thisbutton.pressDuration = 0.1f; } } private void Fstartup() { timer.Once(10f, () => { try { if (Rust.Application.isLoading) { Fstartup(); return; } } catch { } Startup(); }); } private void Startup() { _TPEntity.Clear(); foreach (PrefabData prefabdata in World.Serialization.world.prefabs) { - if (prefabdata.category.Contains("TELEPORT=")) + if (!prefabdata.category.Contains("TELEPORT=")) { continue; } + string settings = prefabdata.category.Split(':')[1].Replace("\\", ""); + BaseEntity _foundTrigger = FindDoor(prefabdata.position, 1.2f); + if (_foundTrigger == null || _TPEntity.ContainsKey(_foundTrigger) || settings == null) { return; } + string[] ParsedSettings = settings.Split('='); + if (ParsedSettings.Count() > 1) { - string settings = prefabdata.category.Split(':')[1].Replace("\\", ""); - BaseEntity _foundTrigger = FindDoor(prefabdata.position, 1.2f); - if (_foundTrigger != null && !_TPEntity.ContainsKey(_foundTrigger) && settings != null) - { - string[] ParsedSettings = settings.Split('='); - if (ParsedSettings.Count() > 1) - { - TPEntity DoorSettings = new TPEntity(); - string[] Vec = ParsedSettings[1].Split(','); - try { DoorSettings.Name = ParsedSettings[2]; } catch { } - try { DoorSettings.SFX = StringPool.toString[uint.Parse(ParsedSettings[3])]; } catch { } - try { DoorSettings.CMD = ParsedSettings[4]; } catch { } - if (Vec.Count() == 3) - { - DoorSettings.TPLocation = new Vector3(float.Parse(Vec[0]), float.Parse(Vec[1]), float.Parse(Vec[2])); - _TPEntity.Add(_foundTrigger, DoorSettings); - continue; - } - Puts("Error parsing teleporter @ " + _foundTrigger.transform.position.ToString()); - } - } + TPEntity DoorSettings = new TPEntity(); + string[] Vec = ParsedSettings[1].Split(','); + try { DoorSettings.Name = ParsedSettings[2]; } catch { } + try { DoorSettings.SFX = StringPool.toString[uint.Parse(ParsedSettings[3])]; } catch { } + try { DoorSettings.CMD = ParsedSettings[4]; } catch { } + if (Vec.Count() == 3) { DoorSettings.TPLocation = new Vector3(float.Parse(Vec[0]), float.Parse(Vec[1]), float.Parse(Vec[2])); _TPEntity.Add(_foundTrigger, DoorSettings); continue; } + Puts("Error parsing teleporter @ " + _foundTrigger.transform.position.ToString()); } } Puts("Found " + _TPEntity.Count.ToString() + " Teleporters"); } - private void OnDoorOpened(Door thisdoor, BasePlayer player) - { - if (thisdoor == null || player == null || thisdoor.OwnerID != 0 || !permission.UserHasPermission(player.UserIDString, permUse)){ thisdoor.CloseRequest(); return; } - if (_TPEntity.ContainsKey(thisdoor)) { Teleport(player, _TPEntity[thisdoor]); thisdoor.Invoke(thisdoor.CloseRequest, 0.5f); } - } - - private void OnButtonPress(PressButton thisbutton, BasePlayer player) - { - if (thisbutton == null || player == null || thisbutton.OwnerID != 0 || !permission.UserHasPermission(player.UserIDString, permUse)) return; - if (_TPEntity.ContainsKey(thisbutton)) { Teleport(player, _TPEntity[thisbutton]); thisbutton.pressDuration = 0.1f; } - } private void Teleport(BasePlayer player, TPEntity tpdoor) { @@ -76,15 +59,9 @@ namespace Oxide.Plugins if (player.IsConnected) { player.EndLooting(); StartSleeping(player); } player.RemoveFromTriggers(); player.SetServerFall(true); + AdjustConnectionScreen(player, tpdoor.Name); player.SetPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot, true); player.ClientRPCPlayer(null, player, "StartLoading"); - if (Net.sv.write.Start()) - { - Net.sv.write.PacketID(Message.Type.Message); - Net.sv.write.String(tpdoor.Name); - Net.sv.write.String(""); - Net.sv.write.Send(new SendInfo(player.Connection)); - } player.Teleport(tpdoor.TPLocation); player.SendEntityUpdate(); if (!IsInvisible(player)) { player.UpdateNetworkGroup(); player.SendNetworkUpdateImmediate(false); } @@ -117,17 +94,15 @@ namespace Oxide.Plugins if (player.IsConnected == false) return; if (player.IsReceivingSnapshot == true) { timer.Once(1f, () => Wakeup(player, tpdoor)); return; } if (tpdoor.CMD != "") { string CMD = tpdoor.CMD.Replace("$player", player.displayName).Replace("$steamid", player.OwnerID.ToString()); covalence.Server.Command(CMD); } - player.EndSleeping(); + AdjustConnectionScreen(player, "Loading"); + NextTick(() => { player.EndSleeping(); }); } + BaseEntity FindDoor(Vector3 pos, float radius) { List ScanArea = new List(); Vis.Entities(pos, radius, ScanArea); - foreach(BaseEntity be in ScanArea) - { - if (be is Door || be is PressButton) - return be; - } + foreach (BaseEntity be in ScanArea){if (be is Door || be is PressButton)return be;} Vis.Entities(pos + new Vector3(0, 3, 0), radius, ScanArea); if (ScanArea.Count != 0 && ScanArea[0] is Door) { return ScanArea[0]; } return null;