C#:
using System.Collections.Generic;
using Mono.Cecil;
using ProtoBuf;
using UnityEngine;
namespace Oxide.Plugins {
[Info("TPOnMap", "TopPlugin.ru", "1.0.1")]
public class TPOnMap : RustPlugin {
private List<ulong> TPList = new List<ulong>();
[ChatCommand("tmap")]
private void cmdChatAdminTP(BasePlayer player, string command, string[] arg) {
if (!player.IsAdmin) return;
if (arg.Length != 1) {
player.ChatMessage($"Не правильное использование команды\nПример: /tmap on/off");
return;
}
switch (arg[0].ToLower()) {
case "on" : if (TPList.Contains(player.userID)) {
player.ChatMessage("У вас уже включен режим телепорта\n Выключить: /tmap off");
return;
}
TPList.Add(player.userID);
player.ChatMessage($"Вы включили телепорт по карте");
break;
case "off" : if (TPList.Contains(player.userID)) {
TPList.Remove(player.userID);
player.ChatMessage($"Вы выключили телепорт по карте");
return;
}
player.ChatMessage("У вас выключен режим телепорта\n Включить: /tmap on");
break;
}
}
private void OnMapMarkerAdd(BasePlayer player, MapNote note) {
if (player == null || note == null) return;
if (player.IsAdmin) {
if (TPList.Contains(player.userID)) {
var pos = note.worldPosition;
pos.y = GetGroundPosition(pos);
player.Teleport(pos);
player.ChatMessage($"Если хотите выключить телепорт по карте, введите команду /tmap off");
}
else {
player.ChatMessage($"Если хотите включить телепорт по карте, введите команду /tmap on");
}
}
}
static float GetGroundPosition(Vector3 pos) {
float 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(new[] {
"Terrain", "World", "Default", "Construction", "Deployed"
}
)) && !hit.collider.name.Contains("rock_cliff"))return Mathf.Max(hit.point.y, y);
return y;
}
}
}