This repository has been archived by the owner on May 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapTeleport.cs
118 lines (100 loc) · 3.47 KB
/
MapTeleport.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using Newtonsoft.Json;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core;
using ProtoBuf;
using System.Collections.Generic;
using UnityEngine;
using System;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System.Linq;
namespace Oxide.Plugins
{
[Info("Map Teleport", "Auro", "1.0.0")]
[Description("Teleports player to marker on map when placed")]
public class MapTeleport : RustPlugin
{
private const string PermissionUse = "mapteleport.use";
private List<string> pendingPlayers = new List<string>();
private void Init()
{
permission.RegisterPermission(PermissionUse, this);
}
private void OnMapMarkerAdded(BasePlayer player, MapNote note)
{
if (player == null || note == null)
{
return;
}
if (!permission.UserHasPermission(player.UserIDString, PermissionUse))
{
return;
}
if (player.isMounted)
{
player.ChatMessage("You cannot teleport while mounted");
return;
}
if (!player.IsAlive())
{
player.ChatMessage("You cannot teleport while dead");
return;
}
if (!pendingPlayers.Contains(player.UserIDString))
{
return;
}
ulong userID = player.userID;
player.flyhackPauseTime = 15f;
var pos = note.worldPosition;
pos.y = GetGroundPosition(pos);
player.Teleport(pos);
player.RemoveFromTriggers();
player.ForceUpdateTriggers();
pendingPlayers.Remove(player.UserIDString);
player.ChatMessage($"Teleported to <color=#FFA500>{pos}</color>");
}
static float GetGroundPosition(Vector3 pos)
{
float y = TerrainMeta.HeightMap.GetHeight(pos);
RaycastHit hitInfo;
if (Physics.Raycast(
new Vector3(pos.x, pos.y + 200f, pos.z),
Vector3.down,
out hitInfo,
float.MaxValue,
(Rust.Layers.Mask.Vehicle_Large | Rust.Layers.Solid | Rust.Layers.Mask.Water)))
{
var cargoShip = hitInfo.GetEntity() as CargoShip;
if (cargoShip != null)
{
return hitInfo.point.y;
}
return Mathf.Max(hitInfo.point.y, y);
}
return y;
}
[ChatCommand("mtp")]
void MapTeleportCommand(BasePlayer player, string command, string[] args)
{
if (!permission.UserHasPermission(player.UserIDString, PermissionUse))
{
player.ChatMessage("NOIDONTTHINKSO");
return;
}
if (pendingPlayers.Contains(player.UserIDString))
{
player.ChatMessage("You already have a pending map teleportation");
} else {
pendingPlayers.Add(player.UserIDString);
player.ChatMessage("Place a marker on the map to teleport to it");
timer.Once(30.0f, () => {
if (pendingPlayers.Contains(player.UserIDString)) {
pendingPlayers.Remove(player.UserIDString);
player.ChatMessage("Map teleporting cancelled");
}
});
}
}
}
}