Skip to content

Commit 888e9f4

Browse files
Create SpawnPickupMethod.cs
1 parent da36cb3 commit 888e9f4

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
3+
using SER.ArgumentSystem.Arguments;
4+
using SER.ArgumentSystem.BaseArguments;
5+
using SER.Helpers.Exceptions;
6+
using SER.MethodSystem.BaseMethods;
7+
using SER.MethodSystem.MethodDescriptors;
8+
using UnityEngine;
9+
10+
namespace SER.MethodSystem.Methods.PickupMethods;
11+
12+
[UsedImplicitly]
13+
public class SpawnPickupMethod : SynchronousMethod, ICanError
14+
{
15+
public override string Description => "Spawns an item pickup at a given position.";
16+
17+
public string[] ErrorReasons =>
18+
[
19+
"Provided item cannot be spawned."
20+
];
21+
22+
public override Argument[] ExpectedArguments { get; } =
23+
[
24+
new EnumArgument<ItemType>("item type"),
25+
new FloatArgument("position x"),
26+
new FloatArgument("position y"),
27+
new FloatArgument("position z"),
28+
];
29+
30+
public override void Execute()
31+
{
32+
var itemType = Args.GetEnum<ItemType>("item type");
33+
var positionX = Args.GetFloat("position x");
34+
var positionY = Args.GetFloat("position y");
35+
var positionZ = Args.GetFloat("position z");
36+
37+
var pickup = Pickup.Create(
38+
itemType,
39+
new Vector3(
40+
positionX,
41+
positionY,
42+
positionZ
43+
)
44+
);
45+
46+
if (pickup is null) throw new ScriptRuntimeError(ErrorReasons[0]);
47+
pickup.Spawn();
48+
}
49+
}

0 commit comments

Comments
 (0)