-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bloodtrail.cs
130 lines (108 loc) · 3.86 KB
/
Bloodtrail.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
using Newtonsoft.Json;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Bloodtrail", "hoppel", "1.0.3")]
[Description("Leaves a Bloodtrail behind players while bleeding")]
public class Bloodtrail : RustPlugin
{
private const string permAllow = "bloodtrail.allow";
private const string permBypass = "bloodtrail.bypass";
private static Bloodtrail ins;
private void Init()
{
permission.RegisterPermission(permAllow, this);
permission.RegisterPermission(permBypass, this);
}
private void OnServerInitialized()
{
foreach (var player in BasePlayer.activePlayerList)
OnPlayerInit(player);
ins = this;
}
private void OnPlayerInit(BasePlayer player)
{
if (HasPerm(player) && !player.gameObject.GetComponent<Blood>())
player.gameObject.AddComponent<Blood>();
}
private void OnPlayerDisconnected(BasePlayer player, string reason)
{
if (player.gameObject.GetComponent<Blood>())
UnityEngine.Object.Destroy(player.gameObject.GetComponent<Blood>());
}
private void Unload()
{
var objects = UnityEngine.Object.FindObjectsOfType(typeof(Blood));
if (objects != null)
foreach (var gameObj in objects)
UnityEngine.Object.Destroy(gameObj);
}
private bool HasPerm(BasePlayer player)
{
return permission.UserHasPermission(player.UserIDString, "bloodtrail.allow") && !permission.UserHasPermission(player.UserIDString, "bloodtrail.bypass");
}
public class Blood : MonoBehaviour
{
private BasePlayer _player;
private Vector3 _position;
private void Awake()
{
_player = GetComponent<BasePlayer>();
_position = _player.transform.position;
InvokeRepeating("Track", 0.2f, config.refreshtime);
}
private void Track()
{
if (!_player || !ins.HasPerm(_player))
return;
{
if (_position == _player.transform.position)
return;
_position = _player.transform.position;
if (!_player || !_player.IsConnected)
{
Destroy(this);
return;
}
if (_player.metabolism.bleeding.value > 0)
Effect.server.Run("assets/bundled/prefabs/fx/player/beartrap_blood.prefab", _player.transform.position, Vector3.up, null, true);
}
}
private void OnDestroy()
{
CancelInvoke("Track");
Destroy(this);
}
}
private static Configuration config;
public class Configuration
{
[JsonProperty(PropertyName = "Refresh Time")]
public float refreshtime = 0.2f;
public static Configuration DefaultConfig()
{
return new Configuration();
}
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<Configuration>();
if (config == null)
{
LoadDefaultConfig();
}
}
catch
{
PrintWarning("Creating new config file.");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void LoadDefaultConfig() => config = Configuration.DefaultConfig();
protected override void SaveConfig() => Config.WriteObject(config);
}
}