Skip to content

Commit e9536da

Browse files
update SpawnProjectile to return a reference
1 parent 45517aa commit e9536da

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

MethodSystem/Methods/ProjectileMethods/SpawnProjectileMethod.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
using JetBrains.Annotations;
1+
using InventorySystem.Items.Pickups;
2+
using JetBrains.Annotations;
23
using LabApi.Features.Wrappers;
34
using SER.ArgumentSystem.Arguments;
45
using SER.ArgumentSystem.BaseArguments;
6+
using SER.Helpers.Exceptions;
57
using SER.MethodSystem.BaseMethods;
8+
using SER.MethodSystem.MethodDescriptors;
69

710
namespace SER.MethodSystem.Methods.ProjectileMethods;
811

912
[UsedImplicitly]
10-
public class SpawnProjectileMethod : SynchronousMethod
13+
public class SpawnProjectileMethod : ReferenceReturningMethod<Pickup>, ICanError
1114
{
1215
public override string Description => "Spawns a live projectile at a given position.";
1316

17+
public string[] ErrorReasons =>
18+
[
19+
"Failed to spawn projectile with provided arguments."
20+
];
21+
1422
public override Argument[] ExpectedArguments { get; } =
1523
[
1624
new EnumArgument<ProjectileType>("projectile type"),
@@ -43,7 +51,7 @@ public override void Execute()
4351
var owner = Args.GetPlayer("owner");
4452
var timeUntilDetonation = Args.GetFloat("time until detonation");
4553

46-
TimedGrenadeProjectile.SpawnActive(
54+
var pickupBase = TimedGrenadeProjectile.SpawnActive(
4755
new(
4856
positionX,
4957
positionY,
@@ -52,7 +60,14 @@ public override void Execute()
5260
projectileType,
5361
owner,
5462
timeUntilDetonation
55-
);
63+
)?.Base;
64+
65+
if (Pickup.Get(pickupBase) is not { } pickup)
66+
{
67+
throw new ScriptRuntimeError(ErrorReasons[0]);
68+
}
69+
70+
ReturnValue = pickup;
5671
}
5772

5873
public enum ProjectileType

0 commit comments

Comments
 (0)