Skip to content

Commit ab49be3

Browse files
Create SpawnProjectileMethod.cs
1 parent 888e9f4 commit ab49be3

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
3+
using SER.ArgumentSystem.Arguments;
4+
using SER.ArgumentSystem.BaseArguments;
5+
using SER.MethodSystem.BaseMethods;
6+
7+
namespace SER.MethodSystem.Methods.ProjectileMethods;
8+
9+
[UsedImplicitly]
10+
public class SpawnProjectileMethod : SynchronousMethod
11+
{
12+
public override string Description => "Spawns a live projectile at a given position.";
13+
14+
public override Argument[] ExpectedArguments { get; } =
15+
[
16+
new EnumArgument<ProjectileType>("projectile type"),
17+
new FloatArgument("position x"),
18+
new FloatArgument("position y"),
19+
new FloatArgument("position z"),
20+
new PlayerArgument("owner")
21+
{
22+
DefaultValue = new(null, "server")
23+
},
24+
new FloatArgument("time until detonation")
25+
{
26+
DefaultValue = new(-1f, "default")
27+
}
28+
];
29+
30+
public override void Execute()
31+
{
32+
var projectileType = Args.GetEnum<ProjectileType>("projectile type") switch
33+
{
34+
ProjectileType.Scp018 => ItemType.SCP018,
35+
ProjectileType.Grenade => ItemType.GrenadeHE,
36+
ProjectileType.Flashbang => ItemType.GrenadeFlash,
37+
ProjectileType.Scp2176 => ItemType.SCP2176,
38+
_ => throw new ArgumentOutOfRangeException()
39+
};
40+
var positionX = Args.GetFloat("position x");
41+
var positionY = Args.GetFloat("position y");
42+
var positionZ = Args.GetFloat("position z");
43+
var owner = Args.GetPlayer("owner");
44+
var timeUntilDetonation = Args.GetFloat("time until detonation");
45+
46+
TimedGrenadeProjectile.SpawnActive(
47+
new(
48+
positionX,
49+
positionY,
50+
positionZ
51+
),
52+
projectileType,
53+
owner,
54+
timeUntilDetonation
55+
);
56+
}
57+
58+
public enum ProjectileType
59+
{
60+
Scp018,
61+
Grenade,
62+
Flashbang,
63+
Scp2176
64+
}
65+
}

0 commit comments

Comments
 (0)