forked from PenisBlistashiq/Rust-plugins-236-240-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBroPanel.cs
More file actions
483 lines (427 loc) · 19.3 KB
/
Copy pathBroPanel.cs
File metadata and controls
483 lines (427 loc) · 19.3 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("BroPanel", "OxideBro", "0.1.0")]
public class BroPanel : RustPlugin
{
public Dictionary<BasePlayer, Coroutine> PlayersTime = new Dictionary<BasePlayer, Coroutine>();
private PluginConfig config;
private Coroutine UpdateActionValues;
public bool CargoPlane;
public bool BaseHelicopter;
public bool CargoShip;
public bool CH47Helicopter;
public bool Init;
private IEnumerator UpdateValues()
{
while (Init)
{
CargoPlane = false;
BaseHelicopter = false;
CargoShip = false;
CH47Helicopter = false;
foreach (var entity in BaseNetworkable.serverEntities.Where(p => p is CargoPlane
|| p is BaseHelicopter || p is CargoShip || p is CH47Helicopter))
{
if (entity is CargoPlane)
CargoPlane = true;
if (entity is BaseHelicopter)
BaseHelicopter = true;
if (entity is CargoShip)
CargoShip = true;
if (entity is CH47Helicopter)
CH47Helicopter = true;
}
CurrentMessages = getRandomBroadcast();
yield return new WaitForSeconds(10);
}
yield return 0;
}
protected override void LoadDefaultConfig()
{
PrintWarning("Благодарим за скачивание плагина на сайте RustPlugin.ru. <3 OxideBro!");
config = PluginConfig.DefaultConfig();
}
protected override void LoadConfig()
{
base.LoadConfig();
config = Config.ReadObject<PluginConfig>();
if (config.PluginVersion < Version)
UpdateConfigValues();
Config.WriteObject(config, true);
}
private void UpdateConfigValues()
{
PluginConfig baseConfig = PluginConfig.DefaultConfig();
if (config.PluginVersion < new VersionNumber(1, 0, 0))
{
PrintWarning("Config update detected! Updating config values...");
PrintWarning("Config update completed!");
}
config.PluginVersion = Version;
}
protected override void SaveConfig()
{
Config.WriteObject(config);
}
void OnPlayerConnected(BasePlayer player)
{
if (player.IsReceivingSnapshot)
{
timer.In(1f, () => OnPlayerConnected(player));
return;
}
PlayersTime[player] = ServerMgr.Instance.StartCoroutine(StartUpdate(player));
}
void Unload()
{
Init = false;
if (UpdateActionValues != null)
ServerMgr.Instance.StopCoroutine(UpdateValues());
foreach (var player in PlayersTime)
{
ServerMgr.Instance.StopCoroutine(player.Value);
CuiHelper.DestroyUi(player.Key, "OnlinePanel_Main");
}
}
private IEnumerator StartUpdate(BasePlayer player)
{
while (player.IsConnected)
{
CreateMenu(player);
yield return new WaitForSeconds(config.UpdateTime);
}
PlayersTime.Remove(player);
yield return 0;
}
class PluginConfig
{
[JsonProperty("Версия конфигурации")]
public VersionNumber PluginVersion = new VersionNumber();
[JsonProperty("Автоматические сообщения для панели")]
public List<string> AutomatedMEssages = new List<string>();
[JsonProperty("Активный цвет ивентов (#hex или Rust color)")]
public string ActiveColor = "0.00 1.00 0.50 1.00";
[JsonProperty("Название корбля")]
public string ShipName = "CARGOSHIP";
[JsonProperty("Название самолета")]
public string AirName = "CARHOPLANE";
[JsonProperty("Название вертолета")]
public string HeliName = "HELICOPTER";
[JsonProperty("Название чинука")]
public string ChinookName = "CHINOOK";
[JsonProperty("Частота обновления игрового времени")]
public float UpdateTime = 5.0f;
public static PluginConfig DefaultConfig()
{
return new PluginConfig()
{
PluginVersion = new VersionNumber(),
AutomatedMEssages = new List<string>()
{
"ОФИЦИАЛЬНЫЙ МАГАЗИН ПРОЕКТА <color=#80FC73>site.ru</color>",
"ПРЕДЛОЖИТЬ ОБМЕН ИГРОКУ <color=#80FC73>КОМАНДА /TRADE</color>",
"ПЛАНОВЫЙ РЕСТАРТ СЕРВЕРА <color=#80FC73>08:00</color>",
"ИНФОРМАЦИЯ О СЕРВЕРЕ <color=#80FC73>/INFO</color>",
}
};
}
}
int CurrentNum = -1;
public string CurrentMessages = "";
string getRandomBroadcast()
{
CurrentNum++;
if (CurrentNum >= config.AutomatedMEssages.Count)
CurrentNum = 0;
return (string)config.AutomatedMEssages[CurrentNum];
}
void OnServerInitialized()
{
Init = true;
CurrentMessages = getRandomBroadcast();
UpdateActionValues = ServerMgr.Instance.StartCoroutine(UpdateValues());
BasePlayer.activePlayerList.ToList().ForEach(OnPlayerConnected);
}
void CreateMenu(BasePlayer player)
{
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiElement
{
Parent = "Hud",
Name = "OnlinePanel_Main",
Components =
{
new CuiImageComponent { Color = "0 0 0 0"},
new CuiRectTransformComponent{ AnchorMin = "1 1", AnchorMax = $"1 1"},
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_Main",
Name = "OnlinePanel_TIME",
Components =
{
new CuiImageComponent { Color = "1 1 1 0.3",Sprite = "assets/content/ui/ui.background.tile.psd", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = $"0 0", OffsetMin = "-60 -35", OffsetMax = "-5 -5"},
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_TIME",
Components =
{
new CuiTextComponent
{
Color = "1 1 1 1",
FontSize = 18,
Align = TextAnchor.MiddleCenter,
Text = TOD_Sky.Instance.Cycle.DateTime.ToString("HH:mm")
},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = $"1 1" },
new CuiOutlineComponent{ Color = "0 0 0 1", Distance = "-0.2 0.2"}
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_TIME",
Components =
{
new CuiTextComponent
{
Color = "1 1 1 1",
FontSize = 18,
Font = "robotocondensed-regular.ttf",
Align = TextAnchor.MiddleCenter,
Text = BasePlayer.activePlayerList.Count.ToString()
},
new CuiRectTransformComponent{AnchorMin = "0 0", AnchorMax = $"0 0", OffsetMin = "-35 0", OffsetMax = "-3 30" },
new CuiOutlineComponent{ Color = "0 0 0 1", Distance = "-0.2 0.2"}
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_TIME",
Components =
{
new CuiTextComponent
{
Color = "1 1 1 0.7",
FontSize = 8,
Align = TextAnchor.LowerCenter,
Text = "ONLINE"
},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = $"0 0", OffsetMin = "-35 -10", OffsetMax = "-3 0" },
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_TIME",
Components =
{
new CuiTextComponent
{
Color = "1 1 1 0.7",
FontSize = 8,
Align = TextAnchor.LowerCenter,
Text = "TIME"
},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = $"0 0", OffsetMin = "0 -10", OffsetMax = "55 0" },
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_TIME",
Components =
{
new CuiTextComponent
{
Color = "1 1 1 0.7",
FontSize = 8,
Align = TextAnchor.LowerCenter,
Text = "EVENTS"
},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = $"0 0", OffsetMin = "-200 -10", OffsetMax = "-40 0" },
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_TIME",
Name = "OnlinePanel_CHINOOK",
Components =
{
new CuiTextComponent
{
Color = CH47Helicopter? config.ActiveColor.StartsWith("#") ? HexToRustFormat(config.ActiveColor) : config.ActiveColor : "1 1 1 1" ,
FontSize = 20,
Align = TextAnchor.UpperLeft,
Text = "•"
},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = $"0 0", OffsetMin = "-200 0", OffsetMax = "-40 34" },
new CuiOutlineComponent{ Color = "0 0 0 1", Distance = "-0.2 0.2"}
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_CHINOOK",
Components =
{
new CuiTextComponent
{
Color = CH47Helicopter? config.ActiveColor.StartsWith("#") ? HexToRustFormat(config.ActiveColor) : config.ActiveColor : "1 1 1 1" ,
FontSize = 12,
Font = "robotocondensed-regular.ttf",
Align = TextAnchor.UpperLeft,
Text = config.ChinookName
},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = $"0 0", OffsetMin = "10 0", OffsetMax = "80 30" },
new CuiOutlineComponent{ Color = "0 0 0 1", Distance = "-0.2 0.2"}
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_TIME",
Name = "OnlinePanel_1",
Components =
{
new CuiTextComponent
{
Color = CargoShip? config.ActiveColor.StartsWith("#") ? HexToRustFormat(config.ActiveColor) : config.ActiveColor : "1 1 1 1" ,
FontSize = 20,
Align = TextAnchor.UpperLeft,
Text = "•"
},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = $"0 0", OffsetMin = "-200 -10", OffsetMax = "-40 17" },
new CuiOutlineComponent{ Color = "0 0 0 1", Distance = "-0.2 0.2"}
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_1",
Components =
{
new CuiTextComponent
{
Color =CargoShip? config.ActiveColor.StartsWith("#") ? HexToRustFormat(config.ActiveColor) : config.ActiveColor : "1 1 1 1",
FontSize = 12,
Font = "robotocondensed-regular.ttf",
Align = TextAnchor.MiddleLeft,
Text = config.ShipName
},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = $"0 0", OffsetMin = "10 0", OffsetMax = "80 34" },
new CuiOutlineComponent{ Color = "0 0 0 1", Distance = "-0.2 0.2"}
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_TIME",
Name = "OnlinePanel_AIRK",
Components =
{
new CuiTextComponent
{
Color = CargoPlane? config.ActiveColor.StartsWith("#") ? HexToRustFormat(config.ActiveColor) : config.ActiveColor : "1 1 1 1",
FontSize = 20,
Align = TextAnchor.UpperLeft,
Text = "•"
},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = $"0 0", OffsetMin = "-120 0", OffsetMax = "-40 34" },
new CuiOutlineComponent{ Color = "0 0 0 1", Distance = "-0.2 0.2"}
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_AIRK",
Components =
{
new CuiTextComponent
{
Color = CargoPlane? config.ActiveColor.StartsWith("#") ? HexToRustFormat(config.ActiveColor) : config.ActiveColor : "1 1 1 1",
FontSize = 12,
Font = "robotocondensed-regular.ttf",
Align = TextAnchor.UpperLeft,
Text = config.AirName
},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = $"0 0", OffsetMin = "10 0", OffsetMax = "80 30" },
new CuiOutlineComponent{ Color = "0 0 0 1", Distance = "-0.2 0.2"}
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_TIME",
Name = "OnlinePanel_2",
Components =
{
new CuiTextComponent
{
Color = BaseHelicopter? config.ActiveColor.StartsWith("#") ? HexToRustFormat(config.ActiveColor) : config.ActiveColor : "1 1 1 1",
FontSize = 20,
Align = TextAnchor.UpperLeft,
Text = "•"
},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = $"0 0", OffsetMin = "-120 -10", OffsetMax = "-40 17" },
new CuiOutlineComponent{ Color = "0 0 0 1", Distance = "-0.2 0.2"}
}
});
container.Add(new CuiElement
{
Parent = "OnlinePanel_2",
Components =
{
new CuiTextComponent
{
Color = BaseHelicopter? config.ActiveColor.StartsWith("#") ? HexToRustFormat(config.ActiveColor) : config.ActiveColor : "1 1 1 1",
FontSize = 12,
Font = "robotocondensed-regular.ttf",
Align = TextAnchor.MiddleLeft,
Text = config.HeliName
},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = $"0 0", OffsetMin = "10 0", OffsetMax = "80 34" },
new CuiOutlineComponent{ Color = "0 0 0 1", Distance = "-0.2 -0.2"}
}
});
CuiHelper.DestroyUi(player, "OnlinePanel_Messages");
container.Add(new CuiElement
{
Name = "OnlinePanel_Messages",
Parent = "Hud",
Components =
{
new CuiTextComponent { Color = "1 1 1 1", FontSize = 10, Align = TextAnchor.LowerCenter, Text = CurrentMessages,Font = "robotocondensed-regular.ttf"},
new CuiRectTransformComponent{ AnchorMin = "0.3447913 0.003", AnchorMax = $"0.640625 0.08"},
}
});
CuiHelper.DestroyUi(player, "OnlinePanel_Main");
CuiHelper.AddUi(player, container);
}
private static string HexToRustFormat(string hex)
{
if (string.IsNullOrEmpty(hex))
{
hex = "#FFFFFFFF";
}
var str = hex.Trim('#');
if (str.Length == 6)
str += "FF";
if (str.Length != 8)
{
throw new Exception(hex);
throw new InvalidOperationException("Cannot convert a wrong format.");
}
var r = byte.Parse(str.Substring(0, 2), NumberStyles.HexNumber);
var g = byte.Parse(str.Substring(2, 2), NumberStyles.HexNumber);
var b = byte.Parse(str.Substring(4, 2), NumberStyles.HexNumber);
var a = byte.Parse(str.Substring(6, 2), NumberStyles.HexNumber);
Color color = new Color32(r, g, b, a);
return $"{color.r:F2} {color.g:F2} {color.b:F2} {color.a:F2}";
}
}
}