C#:
using System.Collections.Generic;
using Physics = UnityEngine.Physics;
using System;
using Newtonsoft.Json;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("SleeperThrowHome", "rustmods.ru", "1.0.0")]
[Description("Выбрасывает спящих из вашей билды")]
public class SleeperThrowHome : RustPlugin
{
void OnPlayerDisconnected(BasePlayer player, string reason) => MoveSleeper(player);
private static Configuration config = new Configuration();
private static Single GetGroundPosition(Vector3 pos)
{
Single y = TerrainMeta.HeightMap.GetHeight(pos);
RaycastHit hit;
if (Physics.Raycast(new Vector3(pos.x, pos.y + 200f, pos.z), Vector3.down, out hit, Mathf.Infinity,
LayerMask.GetMask("Terrain", "World", "Default", "Construction", "Deployed")) &&
!hit.collider.name.Contains("rock_cliff")) return Mathf.Max(hit.point.y, y);
return y;
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<Configuration>();
if (config == null) LoadDefaultConfig();
}
catch
{
PrintWarning("Ошибка #564632423" + $"чтения конфигурации 'oxide/config/{Name}', создаём новую конфигурацию!!");
LoadDefaultConfig();
}
NextTick(SaveConfig);
}
private Boolean GetCheckPosition(Vector3 Position) => !Physics.CheckSphere(Position, 15f, LayerMask.GetMask("Construction", "Default", "Deployed", "Trigger"));
protected override void SaveConfig() => Config.WriteObject(config);
private void MoveSleeper(BasePlayer player)
{
if (player == null) return;
if (player.IsBuildingAuthed()) return;
if (!player.IsBuildingBlocked()) return;
List<Vector3> PosList = Facepunch.Pool.GetList<Vector3>();
for (Int32 i = 0; i < config.PointCounts; i++)
{
Vector3 targetPosition = RandomCircle(player.transform.position, config.Distantion);
if (!GetCheckPosition(targetPosition)) continue;
targetPosition.y = GetGroundPosition(targetPosition);
PosList.Add(targetPosition);
}
Vector3 pPosition = PosList.GetRandom();
Facepunch.Pool.FreeList<Vector3>(ref PosList);
player.Teleport(pPosition);
}
protected override void LoadDefaultConfig() => config = Configuration.GetNewConfiguration();
static Vector3 RandomCircle(Vector3 center, Single radius = 2)
{
Vector3 pos;
pos.x = center.x + UnityEngine.Random.Range(-radius, radius);
pos.z = center.z + UnityEngine.Random.Range(-radius, radius);
pos.y = center.y;
pos.y = GetGroundPosition(pos);
return pos;
}
private class Configuration
{
[JsonProperty("Дистанция для поиска позиций возле дома")]
public Single Distantion;
[JsonProperty("Сколько вариаций позиций искать для игрока")]
public Int32 PointCounts;
public static Configuration GetNewConfiguration()
{
return new Configuration
{
Distantion = 50f,
PointCounts = 20,
};
}
}
}
}