forked from Calytic/oxideplugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuicideBomber.cs
More file actions
261 lines (220 loc) · 9.82 KB
/
SuicideBomber.cs
File metadata and controls
261 lines (220 loc) · 9.82 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("SuicideBomber", "Calytic @ cyclone.network", "0.0.2", ResourceId = 1425)]
class SuicideBomber : RustPlugin
{
private float damage;
private float radius;
private int explosives;
private int c4;
private bool flare;
private bool scream;
private Dictionary<string, string> messages = new Dictionary<string, string>();
private List<string> texts = new List<string>() {
"You lack the required {0} timed explosives",
"You lack the required {0} explosives",
"You lack the required flare",
"You will explode shortly..",
};
void OnServerInitialized()
{
damage = this.GetConfig<float>("damage", 1200f);
radius = this.GetConfig<float>("radius", 12f);
c4 = this.GetConfig<int>("c4", 1);
explosives = this.GetConfig<int>("explosives", 10);
scream = this.GetConfig<bool>("scream", true);
flare = this.GetConfig<bool>("flare", true);
Dictionary<string, object> customMessages = GetConfig<Dictionary<string, object>>("messages", null);
if (customMessages != null)
{
foreach (KeyValuePair<string, object> kvp in customMessages)
{
messages[kvp.Key] = kvp.Value.ToString();
}
}
LoadData();
}
void LoadData()
{
if (this.Config["VERSION"] == null)
{
// FOR COMPATIBILITY WITH INITIAL VERSIONS WITHOUT VERSIONED CONFIG
this.ReloadConfig();
}
else if (this.GetConfig<string>("VERSION", this.Version.ToString()) != this.Version.ToString())
{
// ADDS NEW, IF ANY, CONFIGURATION OPTIONS
this.ReloadConfig();
}
}
protected void ReloadConfig()
{
Dictionary<string, object> messages = new Dictionary<string, object>();
foreach (string text in texts)
{
if (!messages.ContainsKey(text))
{
messages.Add(text, text);
}
}
Config["messages"] = messages;
Config["VERSION"] = this.Version.ToString();
// NEW CONFIGURATION OPTIONS HERE
Config["c4"] = 1;
Config["flare"] = true;
// END NEW CONFIGURATION OPTIONS
PrintWarning("Upgrading Configuration File");
this.SaveConfig();
}
protected override void LoadDefaultConfig()
{
PrintWarning("Creating new configuration");
Config.Clear();
Dictionary<string, object> messages = new Dictionary<string, object>();
foreach (string text in texts)
{
if (messages.ContainsKey(text))
{
PrintWarning("Duplicate translation string: " + text);
}
else
{
messages.Add(text, text);
}
}
Config["messages"] = messages;
Config["damage"] = 1200f;
Config["radius"] = 12f;
Config["explosives"] = 10;
Config["c4"] = 1;
Config["scream"] = true;
Config["flare"] = true;
Config["VERSION"] = this.Version.ToString();
}
private T GetConfig<T>(string name, T defaultValue)
{
if (Config[name] == null)
{
return defaultValue;
}
return (T)Convert.ChangeType(Config[name], typeof(T));
}
void OnPlayerInput(BasePlayer player, InputState input)
{
Item activeItem = player.GetActiveItem();
if (activeItem != null && activeItem.info.shortname == "targeting.computer" && input.WasJustPressed(BUTTON.USE))
{
bool fail = false;
if (c4 > 0)
{
int c4_amount = player.inventory.GetAmount(498591726);
if (c4_amount < c4)
{
Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.denied.prefab", player.transform.position);
SendReply(player, messages["You lack the required {0} timed explosives"], c4);
fail = true;
}
}
if (explosives > 0)
{
int explosives_amount = player.inventory.GetAmount(1755466030);
if (explosives_amount < explosives)
{
Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.denied.prefab", player.transform.position);
SendReply(player, messages["You lack the required {0} explosives"], explosives);
fail = true;
}
}
if (flare)
{
int flare_amount = player.inventory.GetAmount(97513422);
if (flare_amount < 1)
{
Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.denied.prefab", player.transform.position);
SendReply(player, messages["You lack the required flare"]);
fail = true;
}
}
if (fail)
{
return;
}
else
{
player.inventory.Take(null, 498591726, c4);
player.inventory.Take(null, 1755466030, explosives);
player.inventory.Take(null, 97513422, 1);
}
SendReply(player, messages["You will explode shortly.."]);
activeItem.Remove(0f);
activeItem.RemoveFromContainer();
Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.updated.prefab", player.transform.position);
timer.Once(2f, delegate()
{
Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.lock.prefab", player.transform.position);
});
if (scream)
{
timer.Once(3f, delegate()
{
Effect.server.Run("assets/bundled/prefabs/fx/player/beartrap_scream.prefab", player.transform.position);
});
}
timer.Once(4f, delegate()
{
Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.lock.prefab", player.transform.position);
});
timer.Once(6f, delegate()
{
Effect.server.Run("assets/bundled/prefabs/fx/firebomb.prefab", player.transform.position);
Effect.server.Run("assets/bundled/prefabs/fx/gas_explosion_small.prefab", player.transform.position);
Effect.server.Run("assets/prefabs/npc/patrol helicopter/effects/rocket_explosion.prefab", player.transform.position);
Effect.server.Run("assets/prefabs/npc/patrol helicopter/effects/rocket_explosion.prefab", player.transform.position);
Effect.server.Run("assets/prefabs/npc/patrol helicopter/effects/rocket_explosion.prefab", player.transform.position);
});
timer.Once(6.2f, delegate() {
Effect.server.Run("assets/prefabs/tools/c4/effects/c4_explosion.prefab", player.transform.position);
List<BaseCombatEntity> entities = new List<BaseCombatEntity>();
Vis.Entities<BaseCombatEntity>(player.transform.position, radius/3, entities);
foreach (BaseCombatEntity e in entities)
{
e.Hurt(damage, global::Rust.DamageType.Explosion, player, true);
}
List<BaseCombatEntity> entities2 = new List<BaseCombatEntity>();
Vis.Entities<BaseCombatEntity>(player.transform.position, radius/2, entities2);
foreach (BaseCombatEntity e in entities2)
{
if (entities.Contains(e))
{
continue;
}
e.Hurt(damage/2, global::Rust.DamageType.Explosion, player, true);
}
List<BaseCombatEntity> entities3 = new List<BaseCombatEntity>();
Vis.Entities<BaseCombatEntity>(player.transform.position, radius, entities3);
foreach (BaseCombatEntity e in entities3)
{
if (entities.Contains(e) || entities2.Contains(e))
{
continue;
}
e.Hurt(damage/4, global::Rust.DamageType.Explosion, player, true);
}
if (player.net.connection.authLevel == 0)
{
player.Die();
}
});
timer.Once(6.4f, delegate()
{
Effect.server.Run("assets/prefabs/tools/c4/effects/c4_explosion.prefab", player.transform.position);
});
}
}
}
}