-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUltraDeathKit.cs
More file actions
76 lines (67 loc) · 3.21 KB
/
UltraDeathKit.cs
File metadata and controls
76 lines (67 loc) · 3.21 KB
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
using Oxide.Core.Plugins;
using System.Collections.Generic;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("UltraDeathKit", "YourName", "1.6.2")]
[Description("Стартовый набор с удалением при смерти и индивидуальными пермишенами")]
public class UltraDeathKit : RustPlugin
{
const string PERM_KIT = "ultradeathkit.kit";
const string PERM_CLEAN = "ultradeathkit.clean";
const float CLEAN_RADIUS = 3f;
readonly HashSet<string> _clothes = new HashSet<string> { "burlap.headwrap", "burlap.shirt", "burlap.gloves.new", "burlap.trousers", "burlap.shoes" };
readonly HashSet<string> _tools = new HashSet<string> { "concretehatchet", "concretepickaxe" };
HashSet<string> _itemsToRemove => new HashSet<string>(_clothes) { "concretehatchet", "concretepickaxe" };
void Init() {
permission.RegisterPermission(PERM_KIT, this);
permission.RegisterPermission(PERM_CLEAN, this);
}
#region Выдача набора
void OnPlayerInit(BasePlayer p) {
if (permission.UserHasPermission(p.UserIDString, PERM_KIT)) GiveKit(p);
}
void OnPlayerRespawned(BasePlayer p) {
if (permission.UserHasPermission(p.UserIDString, PERM_KIT)) GiveKit(p);
}
void GiveKit(BasePlayer p) {
if (p?.IsConnected != true) return;
p.inventory.Strip();
foreach (var item in _clothes) ItemManager.CreateByName(item, 1)?.MoveToContainer(p.inventory.containerWear);
foreach (var tool in _tools) {
var item = ItemManager.CreateByName(tool, 1);
if (item != null) { item.condition = item.maxCondition; item.MoveToContainer(p.inventory.containerBelt); }
}
p.SendNetworkUpdateImmediate();
p.ChatMessage("Стартовый набор получен!");
}
#endregion
#region Удаление при смерти
void OnEntityDeath(BaseCombatEntity e, HitInfo i) {
var p = e as BasePlayer;
if (p == null || !permission.UserHasPermission(p.UserIDString, PERM_CLEAN)) return;
CleanPlayerInventory(p.inventory);
CleanNearbyItems(p.transform.position);
}
void CleanPlayerInventory(PlayerInventory i) {
CleanContainer(i.containerWear);
CleanContainer(i.containerBelt);
CleanContainer(i.containerMain);
}
void CleanContainer(ItemContainer c) {
if (c == null) return;
foreach (var item in c.itemList.ToArray()) {
if (item?.info == null) continue;
if (_itemsToRemove.Contains(item.info.shortname)) { item.RemoveFromContainer(); item.Remove(); }
}
}
void CleanNearbyItems(Vector3 pos) {
var entities = new List<BaseEntity>();
Vis.Entities(pos, CLEAN_RADIUS, entities);
foreach (var e in entities) {
if (e is DroppedItem di && di.item?.info != null && _itemsToRemove.Contains(di.item.info.shortname)) di.Kill();
}
}
#endregion
}
}