C#:
using UnityEngine;
using Oxide.Core;
using Oxide.Core.Plugins;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Oxide.Plugins
{
[Info("ElectricTeleportation", "TopPlugins", "0.0.1")]
public class ElectricTeleportation : RustPlugin
{
[PluginReference]
private Plugin NoteUI;
#region Classes
public class DataConfig
{
[JsonProperty("Отменять телепортацию когда игроку плавает?")]
public bool canswim;
[JsonProperty("Отменять телепортцию если игроку холодно?")]
public bool coldteleport;
[JsonProperty("Отменять телепортцию если у игрока кровотечение?")]
public bool bleedteleport;
[JsonProperty("Отменять телепорт если игрок умирает (wounded)")]
public bool woundedteleport;
[JsonProperty("Отменять телепорт если игрок находится в зоне чужого шкафа?")]
public bool buildingblock;
[JsonProperty("Задержка перед телепортацией")]
public int timetotp;
[JsonProperty("Использовать плагин NoteUI для вывода уведомлений? (заменит все сообщения в чат)")]
public bool usenoteui;
}
#endregion
#region Config
public DataConfig cfg;
protected override void LoadConfig()
{
base.LoadConfig();
cfg = Config.ReadObject<DataConfig>();
}
protected override void SaveConfig()
{
Config.WriteObject(cfg);
}
protected override void LoadDefaultConfig()
{
cfg = new DataConfig()
{
canswim = true,
coldteleport = true,
bleedteleport = true,
woundedteleport = true,
buildingblock = true,
timetotp = 10,
usenoteui = true,
};
}
private Dictionary<ulong, uint> Broadcasters = new Dictionary<ulong, uint>();
#endregion
#region HooksAndMethods
bool NewWipe = false;
void WipeData()
{
if (NewWipe)
{
Broadcasters.Clear();
SaveData();
Interface.Oxide.ReloadPlugin("ElectricTeleportation");
}
}
void OnNewSave(string filename)
{
NewWipe = true;
}
private void SaveData()
{
Interface.Oxide.DataFileSystem.WriteObject("ElectricTeleportation/Broadcasters", Broadcasters);
}
private void LoadData()
{
if (Interface.Oxide.DataFileSystem.ExistsDatafile("ElectricTeleportation/Broadcasters"))
{
Broadcasters = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, uint>>("ElectricTeleportation/Broadcasters");
}
}
private void OnServerInitialized()
{
LoadData();
if (cfg.usenoteui && !plugins.Exists("NoteUI"))
{
PrintWarning("Плагин 'NoteUI' не загружен, дальнейшая работа плагина невозможна!");
return;
}
}
void Unload()
{
SaveData();
}
void OnPlayerInput(BasePlayer player, InputState input, Item item)
{
if (input.WasJustPressed(BUTTON.FIRE_PRIMARY))
{
if (player == null) return;
if (!Broadcasters.ContainsKey(player.userID)) return;
Item activeItem = new Item();
if (item != null) activeItem = item;
else activeItem = player.GetActiveItem();
if (activeItem != null && activeItem.info.shortname == "rf.detonator")
{
var entity = BaseNetworkable.serverEntities.Find(Broadcasters[player.userID]) as RFBroadcaster;
if (entity.ShortPrefabName == "rfbroadcaster" && entity.IsPowered())
{
var detonator = activeItem.GetWorldEntity() as Detonator;
if (!cfg.usenoteui)
{
SendReply(player, $"Вы были добавлены в очередь на телепортацию \nПримерное время ожидания: {cfg.timetotp} сек.");
}
NoteUI?.Call("DrawExplosionNote", player, "ТЕЛЕПОРТАЦИЯ", $"Примерное время ожидания: {cfg.timetotp} сек.");
timer.Once(cfg.timetotp, () =>
{
if (!entity.IsPowered())
{
if (!cfg.usenoteui)
{
SendReply(player, "Телепортация была прервана! \nПричина: отключено питание");
}
NoteUI?.Call("DrawLockNote", player, "ТЕЛЕПОРТАЦИЯ ПРЕРВАНА", $"Причина: отключено питание");
return;
}
if (cfg.buildingblock)
{
if(player.IsBuildingBlocked())
{
if (!cfg.usenoteui)
{
SendReply(player, "Телепортация была прервана! \nПричина: телепортация в зоне чужого шкафа запрещена!");
}
NoteUI?.Call("DrawLockNote", player, "ТЕЛЕПОРТАЦИЯ ПРЕРВАНА", $"Причина: телепортация в зоне чужого шкафа запрещена");
return;
}
}
if (cfg.canswim)
{
if (player.IsSwimming())
{
if (!cfg.usenoteui)
{
SendReply(player, "Телепортация была прервана! \nПричина: вы плаваете!");
}
NoteUI?.Call("DrawLockNote", player, "ТЕЛЕПОРТАЦИЯ ПРЕРВАНА", $"Причина: вы плаваете");
return;
}
}
if (cfg.coldteleport)
{
if (player.metabolism.temperature.value < 0)
{
if (!cfg.usenoteui)
{
SendReply(player, "Телепортация была прервана! \nПричина: вам холодно!");
}
NoteUI?.Call("DrawLockNote", player, "ТЕЛЕПОРТАЦИЯ ПРЕРВАНА", $"Причина: вам холодно");
return;
}
}
if (cfg.bleedteleport)
{
if (player.metabolism.bleeding.value > 0)
{
if (!cfg.usenoteui)
{
SendReply(player, "Телепортация была прервана! \nПричина: вы ранены!");
}
NoteUI?.Call("DrawLockNote", player, "ТЕЛЕПОРТАЦИЯ ПРЕРВАНА", $"Причина: вы ранены!");
return;
}
}
if (cfg.woundedteleport)
{
if (player.IsWounded())
{
if (!cfg.usenoteui)
{
SendReply(player, "Телепортация была прервана! \nПричина: вы ранены!");
}
NoteUI?.Call("DrawLockNote", player, "ТЕЛЕПОРТАЦИЯ ПРЕРВАНА", $"Причина: вы ранены!");
return;
}
}
var position = entity.transform.position;
if (player.IsDead() && player.IsConnected)
{
player.RespawnAt(position, Quaternion.identity);
return;
}
if (player.net?.connection != null)
{
player.ClientRPCPlayer(null, player, "StartLoading");
}
player.StartSleeping();
player.MovePosition(position);
if (player.net?.connection != null)
player.ClientRPCPlayer(null, player, "ForcePositionTo", position);
if (player.net?.connection != null)
player.SetPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot, true);
player.UpdateNetworkGroup();
player.SendNetworkUpdateImmediate(false);
if (player.net?.connection == null) return;
try { player.ClearEntityQueue(null); } catch { }
player.SendFullSnapshot();
});
}
else return;
}
else return;
}
else return;
}
void OnEntityBuilt(Planner planner, GameObject gameobject)
{
BaseEntity entity = gameobject.ToBaseEntity();
BasePlayer player = planner.GetOwnerPlayer();
if (player == null || entity == null) return;
if (entity.ShortPrefabName == "rfbroadcaster")
{
if (Broadcasters.ContainsKey(player.userID))
{
if (!cfg.usenoteui)
{
SendReply(player, "Ваша прежняя точка телепортации домой была удалена");
}
NoteUI?.Call("DrawInfoNote", player, "Ваша прежняя точка телепортаций удалена");
Broadcasters.Remove(player.userID);
Broadcasters.Add(player.userID, entity.net.ID);
SaveData();
return;
}
else
{
Broadcasters.Add(player.userID, entity.net.ID);
SaveData();
}
}
}
void OnEntityDeath(BaseCombatEntity entity, HitInfo info, BasePlayer player)
{
if (entity == null || player == null) return;
if (entity.ShortPrefabName != "rfbroadcaster") return;
if (!Broadcasters.ContainsKey(player.userID)) return;
Broadcasters.Remove(player.userID);
SaveData();
}
void OnEntityKill(BaseNetworkable entity, BasePlayer player)
{
if (entity == null || player == null) return;
if (entity.ShortPrefabName != "rfbroadcaster") return;
if (!Broadcasters.ContainsKey(player.userID)) return;
Broadcasters.Remove(player.userID);
SaveData();
}
void CanPickupEntity(BasePlayer player, BaseCombatEntity entity)
{
if (entity == null || player == null) return;
if (entity.ShortPrefabName != "rfbroadcaster") return;
if (!Broadcasters.ContainsKey(player.userID)) return;
Broadcasters.Remove(player.userID);
SaveData();
}
#endregion
}
}