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
/
Copy pathCheckForHeli.cs
133 lines (112 loc) · 4.6 KB
/
CheckForHeli.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using Oxide.Core;
using System;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System.Linq;
using Newtonsoft.Json;
using UnityEngine;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace Oxide.Plugins
{
[Info("CheckForHeli", "Auro", "1.0.0")]
[Description("Checks if you have a minicopter on the helipad when calling heavies")]
public class CheckForHeli : RustPlugin
{
[PluginReference]
Plugin MonumentFinder;
void OnCardSwipe(CardReader cardReader, Keycard card, BasePlayer player)
{
var monumentResult = MonumentFinder.Call("API_GetClosest", player.transform.position) as Dictionary<string, object>;
var monument = monumentResult["ShortName"] as string;
Puts(monument);
if (monument == "OilrigAI" || monument == "OilrigAI2")
{
Puts(cardReader.accessLevel.ToString());
if (cardReader.accessLevel == 3)
{
if (monument == "OilrigAI")
{
var minicopter = UnityEngine.Object.FindObjectsOfType<MiniCopter>().FirstOrDefault();
if (!minicopter) return;
Puts($"{Convert.ToInt32(config.smoil_x) + 1} - {Convert.ToInt32(config.smoil_z) + 1}");
var distance = Math.Sqrt(Math.Pow(minicopter.transform.position.x - Convert.ToInt32(config.smoil_x), 2) + Math.Pow(minicopter.transform.position.z - Convert.ToInt32(config.smoil_z), 2));
Puts($"{distance}");
if (distance <= 11)
{
player.ChatMessage("You have a minicopter on the helipad, you should get it off before calling heavies or else it will explode!");
}
}
else if (monument == "OilrigAI2")
{
var minicopter = UnityEngine.Object.FindObjectsOfType<MiniCopter>().FirstOrDefault();
if (!minicopter) return;
var distance = Math.Sqrt(Math.Pow(minicopter.transform.position.x - Convert.ToInt32(config.large_x), 2) + Math.Pow(minicopter.transform.position.z - Convert.ToInt32(config.large_z), 2));
if (distance <= 11)
{
player.ChatMessage("You have a minicopter on the helipad, you should get it off before calling heavies or else it will explode!");
}
}
else
{
throw new Exception("Monument not OilrigAI or OilrigAI2");
}
}
}
return;
}
private static ConfigData config;
private class ConfigData
{
[JsonProperty(PropertyName = "Small Oil Rig Helipad X Position")]
public string smoil_x;
[JsonProperty(PropertyName = "Small Oil Rig Helipad Z Position")]
public string smoil_z;
[JsonProperty(PropertyName = "Large Oil Rig Helipad X Position")]
public string large_x;
[JsonProperty(PropertyName = "Large Oil Rig Helipad Z Position")]
public string large_z;
}
private ConfigData GetDefaultConfig()
{
return new ConfigData
{
smoil_x = "Use printpos to get this value",
smoil_z = "Use printpos to get this value",
large_x = "Use printpos to get this value",
large_z = "Use printpos to get this value"
};
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<ConfigData>();
if (config == null)
{
LoadDefaultConfig();
}
}
catch
{
PrintError("Configuration file is corrupt! Check your config file at https://jsonlint.com/");
timer.Every(10f, () =>
{
PrintError("Configuration file is corrupt! Check your config file at https://jsonlint.com/");
});
LoadDefaultConfig();
return;
}
SaveConfig();
}
protected override void LoadDefaultConfig()
{
config = GetDefaultConfig();
}
protected override void SaveConfig()
{
Config.WriteObject(config);
}
}
}