-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoBackpacks.cs
51 lines (43 loc) · 1.38 KB
/
NoBackpacks.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
using System;
using System.Linq;
namespace Oxide.Plugins
{
[Info("No Backpacks", "hoppel", "1.0.4")]
[Description("Removes backpacks after the configured amount of time")]
public class NoBackpacks : RustPlugin
{
#region Hooks
private void OnEntitySpawned(BaseNetworkable entity)
{
if (entity != null && entity.name.Contains("item_drop_backpack"))
{
timer.Once(despawnTimer, () =>
{
if(!entity.IsDestroyed)
entity?.Kill();
});
}
}
#endregion
#region Config
private int despawnTimer;
private new void LoadConfig()
{
GetConfig(ref despawnTimer, "Settings", "Despawn timer (seconds)");
SaveConfig();
}
private void Init() => LoadConfig();
private void GetConfig<T>(ref T variable, params string[] path)
{
if (path.Length == 0)
return;
if (Config.Get(path) == null)
{
Config.Set(path.Concat(new object[] { variable }).ToArray());
}
variable = (T)Convert.ChangeType(Config.Get(path), typeof(T));
}
protected override void LoadDefaultConfig() => PrintWarning("Generating new configuration file...");
#endregion
}
}