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
/
PVPAtNight.cs
164 lines (142 loc) · 5.64 KB
/
PVPAtNight.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using Oxide.Core;
using System;
using System.Collections.Generic;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Rust;
using System.Linq;
namespace Oxide.Plugins
{
[Info("PVPAtNight", "Auro", "1.0.0")]
[Description("Shows a status when PVP at night is enabled")]
public class PVPAtNight : RustPlugin
{
private bool canPvp = false;
CuiElementContainer cachedPVPUI = null;
private Dictionary<string, int> itemList = new Dictionary<string, int>
{
{"wood", 2000},
{"stones", 2000},
{"metal.refined", 20},
{"metal.fragments", 1000},
{"lowgradefuel", 250},
{"ammo.rifle", 64},
{"ammo.pistol", 64},
{"explosive.satchel", 4},
{"ammo.rifle.explosive", 12},
{"smg.2", 1},
{"smg.thompson", 1},
{"grenade.f1", 4},
};
[PluginReference]
Plugin TimeOfDay;
void Init()
{
cachedPVPUI = CreatePVPUI();
if (TimeOfDay == null)
{
Puts("TimeOfDay is not loaded");
return;
}
}
private void OnEntityDeath(BaseCombatEntity victimEntity, HitInfo hitInfo)
{
if (victimEntity is BasePlayer)
{
if (victimEntity is NPCPlayer)
{
//
}
else
{
if (victimEntity.lastDamage == DamageType.Bleeding)
return;
if (canPvp == true)
{
BaseEntity attacker = victimEntity.lastAttacker;
if (attacker == null) return;
if (attacker == victimEntity.ToPlayer()) return;
if (attacker is BasePlayer)
{
if (victimEntity.ToPlayer().Team != null && victimEntity.ToPlayer().Team.members.Contains(attacker.ToPlayer().userID))
return;
var item = itemList.ElementAt(UnityEngine.Random.Range(0, itemList.Count));
(attacker as BasePlayer).inventory.GiveItem(ItemManager.CreateByItemID(ItemManager.FindItemDefinition(item.Key).itemid, item.Value));
Server.Broadcast($"{attacker.ToPlayer().displayName} has received {item.Value}x {ItemManager.FindItemDefinition(item.Key).displayName.english} for killing {victimEntity.ToPlayer().displayName}");
}
}
}
}
else
{
//
}
}
void OnTimeSunset()
{
foreach (BasePlayer player in BasePlayer.activePlayerList)
{
CuiHelper.AddUi(player, cachedPVPUI);
Server.Command("gather.rate dispenser Stones 3");
Server.Command("gather.rate dispenser Wood 3");
Server.Command("gather.rate dispenser \"Sulfur Ore\" 3");
Server.Command("gather.rate dispenser \"Metal Ore\" 3");
}
Server.Broadcast("As the sun sets, PVP is now enabled and farming is now 3x");
canPvp = true;
Puts("PVP is enabled");
}
void OnTimeSunrise()
{
var random = UnityEngine.Random.Range(0, 100);
if (random < 10)
{
var timeUntilPurge = UnityEngine.Random.Range(5, 20);
timer.Once(timeUntilPurge * 60, () =>
{
foreach (BasePlayer player in BasePlayer.activePlayerList)
{
CuiHelper.AddUi(player, cachedPVPUI);
Server.Command("gather.rate dispenser Stones 3");
Server.Command("gather.rate dispenser Wood 3");
Server.Command("gather.rate dispenser \"Sulfur Ore\" 3");
Server.Command("gather.rate dispenser \"Metal Ore\" 3");
}
Server.Broadcast("The Purge is now on and rewards are given out for PVPing");
canPvp = true;
Puts("PVP is enabled");
});
}
foreach (BasePlayer player in BasePlayer.activePlayerList)
{
CuiHelper.DestroyUi(player, "PVPUI");
}
Server.Broadcast("As the sun rises, PVP is now disabled and farming is now 2x");
Server.Command("gather.rate dispenser Stones 2");
Server.Command("gather.rate dispenser Wood 2");
Server.Command("gather.rate dispenser \"Sulfur Ore\" 2");
Server.Command("gather.rate dispenser \"Metal Ore\" 2");
canPvp = false;
Puts("PVP is disabled");
}
private CuiElementContainer CreatePVPUI()
{
CuiElementContainer elements = new CuiElementContainer();
string panel = elements.Add(new CuiPanel
{
Image = { Color = "0.5 0.5 0.5 0.0" },
RectTransform = { AnchorMin = "0.175 0.017", AnchorMax = "0.22 0.08" }
}, "Hud.Menu", "PVPUI");
elements.Add(new CuiElement
{
Parent = panel,
Components =
{
new CuiRawImageComponent {Color = "1 1 1 0.3", Url = "https://i.mrauro.dev/pvpicon.png"},
new CuiRectTransformComponent {AnchorMin = "0 0", AnchorMax = "1 1"}
}
});
return elements;
}
}
}