Skip to content

Commit 5cded0b

Browse files
authored
Add files via upload
1 parent 129b1bf commit 5cded0b

18 files changed

Lines changed: 8235 additions & 0 deletions

ChopperDrops.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using EXILED;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace ChopperDrop
9+
{
10+
public class ChopperDrops
11+
{
12+
public Dictionary<ItemType, int> drops = new Dictionary<ItemType, int>();
13+
14+
public void AddToList(string item, int amount)
15+
{
16+
try
17+
{
18+
drops.Add((ItemType)Enum.Parse(typeof(ItemType), item), amount);
19+
}
20+
catch
21+
{
22+
Plugin.Error("Failed adding item, " + item + " with the amount of " + amount + ". Does it exist?");
23+
}
24+
}
25+
26+
}
27+
}

Config.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections.Generic;
2+
using Exiled.API.Interfaces;
3+
4+
namespace ChopperDrop
5+
{
6+
public class Config : IConfig
7+
{
8+
public bool IsEnabled { get; set; } = true;
9+
public Dictionary<ItemType,int> ChopperItems { get; set; } = new Dictionary<ItemType, int> { {ItemType.GunE11SR, 1}, {ItemType.Medkit, 3}, {ItemType.Adrenaline, 2}, {ItemType.Ammo762, 2}};
10+
public int ChopperTime { get; set; } = 600;
11+
public string ChopperText { get; set; } = "<color=lime>A supply drop is at the surface!</color>";
12+
}
13+
}

EventHandlers.cs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using System;
2+
using MEC;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using UnityEngine;
8+
using Exiled.API.Features;
9+
using Respawning;
10+
using Map = Exiled.API.Features.Map;
11+
using Object = UnityEngine.Object;
12+
13+
namespace ChopperDrop
14+
{
15+
public class EventHandlers
16+
{
17+
public Plugin<Config> pl;
18+
19+
public int time;
20+
public string dropText;
21+
public List<CoroutineHandle> coroutines = new List<CoroutineHandle>();
22+
23+
public bool roundStarted = false;
24+
public Dictionary<ItemType, int> allowedItems;
25+
public EventHandlers(Plugin<Config> plugin, Dictionary<ItemType,int> drops, int tim, string dropTex)
26+
{
27+
pl = plugin;
28+
allowedItems = drops;
29+
time = tim;
30+
dropText = dropTex;
31+
}
32+
33+
internal void RoundStart()
34+
{
35+
roundStarted = true;
36+
foreach (CoroutineHandle handle in coroutines)
37+
Timing.KillCoroutines(handle);
38+
Log.Info("Starting Chopper Thread.");
39+
coroutines.Add(Timing.RunCoroutine(ChopperThread(), "ChopperThread"));
40+
}
41+
42+
internal void WaitingForPlayers()
43+
{
44+
foreach (CoroutineHandle handle in coroutines)
45+
Timing.KillCoroutines(handle);
46+
}
47+
48+
public IEnumerator<float> ChopperThread()
49+
{
50+
while(roundStarted)
51+
{
52+
yield return Timing.WaitForSeconds(time); // Wait seconds (10 minutes by defualt)
53+
Log.Info("Spawning chopper!");
54+
55+
RespawnEffectsController.ExecuteAllEffects(RespawnEffectsController.EffectType.Selection, SpawnableTeamType.NineTailedFox);
56+
57+
Map.Broadcast(5,dropText);
58+
59+
yield return Timing.WaitForSeconds(15); // Wait 15 seconds
60+
61+
Vector3 spawn = GetRandomSpawnPoint(RoleType.NtfCadet);
62+
63+
foreach (KeyValuePair<ItemType, int> drop in allowedItems) // Drop items
64+
{
65+
Log.Info("Spawning " + drop.Value + " " + drop.Key.ToString() + "'s");
66+
for (int i = 0; i < drop.Value; i++)
67+
SpawnItem(drop.Key, spawn);
68+
}
69+
yield return Timing.WaitForSeconds(15); // Wait 15 seconds to let the chopper leave.
70+
}
71+
}
72+
73+
public static Vector3 GetRandomSpawnPoint(RoleType roleType)
74+
{
75+
GameObject randomPosition = Object.FindObjectOfType<SpawnpointManager>().GetRandomPosition(roleType);
76+
77+
return randomPosition == null ? Vector3.zero : randomPosition.transform.position;
78+
}
79+
80+
public int ItemDur(ItemType weapon)
81+
{
82+
switch (weapon)
83+
{
84+
case ItemType.GunCOM15:
85+
return 12;
86+
case ItemType.GunE11SR:
87+
return 18;
88+
case ItemType.GunProject90:
89+
return 50;
90+
case ItemType.GunMP7:
91+
return 35;
92+
case ItemType.GunLogicer:
93+
return 100;
94+
case ItemType.GunUSP:
95+
return 18;
96+
case ItemType.Ammo762:
97+
return 25;
98+
case ItemType.Ammo9mm:
99+
return 25;
100+
case ItemType.Ammo556:
101+
return 25;
102+
default:
103+
return 50;
104+
}
105+
}
106+
107+
public void SpawnItem(ItemType type, Vector3 pos)
108+
{
109+
Exiled.API.Extensions.Item.Spawn(type,ItemDur(type),pos);
110+
}
111+
}
112+
}

Plugin.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Handlers = Exiled.Events.Handlers;
2+
using MEC;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Exiled.API.Features;
9+
using Exiled.Events;
10+
using Config = Exiled.Loader.Config;
11+
12+
namespace ChopperDrop
13+
{
14+
public class ChopperDrop : Plugin<Config>
15+
{
16+
public override string Author { get; } = "KadeDev";
17+
public override string Name { get; } = "Chopper Drop";
18+
public override string Prefix { get; } = "CD";
19+
20+
public EventHandlers EventHandlers;
21+
22+
public override void OnDisabled()
23+
{
24+
foreach (CoroutineHandle handle in EventHandlers.coroutines)
25+
Timing.KillCoroutines(handle);
26+
27+
Handlers.Server.RoundStarted -= EventHandlers.RoundStart;
28+
Handlers.Server.WaitingForPlayers -= EventHandlers.WaitingForPlayers;
29+
30+
EventHandlers = null;
31+
}
32+
33+
public override void OnEnabled()
34+
{
35+
if (!Config.IsEnabled) // Enable config
36+
return;
37+
38+
EventHandlers = new EventHandlers(this, Config.ChopperItems, Config.ChopperTime, Config.ChopperText);
39+
Handlers.Server.RoundStarted += EventHandlers.RoundStart;
40+
Handlers.Server.WaitingForPlayers += EventHandlers.WaitingForPlayers;
41+
42+
Log.Info("Chopper Drop enabled! Enjoy :D");
43+
}
44+
45+
public override void OnReloaded()
46+
{
47+
// empty
48+
}
49+
}
50+
}
221 KB
Binary file not shown.
26.7 KB
Loading
65.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)