Return loadmsg to normal after TP, Clean up code

This commit is contained in:
bmgjet 2021-12-28 14:20:06 +13:00 committed by GitHub
parent 5e41cf6df4
commit ed0627c23b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 49 deletions

View File

@ -7,7 +7,7 @@ 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
{
@ -19,18 +19,19 @@ namespace Oxide.Plugins
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<bool>("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)
{
if (_foundTrigger == null || _TPEntity.ContainsKey(_foundTrigger) || settings == null) { return; }
string[] ParsedSettings = settings.Split('=');
if (ParsedSettings.Count() > 1)
{
@ -39,30 +40,12 @@ namespace Oxide.Plugins
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;
}
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<BaseEntity> ScanArea = new List<BaseEntity>();
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;