|
1 |
| -using Synapse.Command; |
2 |
| -using UnityEngine; |
3 |
| -using Synapse.Api; |
| 1 | +using Neuron.Core.Meta; |
| 2 | +using Neuron.Modules.Commands; |
| 3 | +using Neuron.Modules.Commands.Command; |
| 4 | +using Synapse3.SynapseModule.Command; |
| 5 | +using Synapse3.SynapseModule.Item; |
4 | 6 |
|
5 |
| -namespace MoreTools.Commands |
| 7 | +namespace MoreTools.Commands; |
| 8 | + |
| 9 | +[Automatic] |
| 10 | +[SynapseRaCommand( |
| 11 | + CommandName = "Grenade", |
| 12 | + Aliases = new[] { "gn" }, |
| 13 | + Description = "Spawns grenades at the player location", |
| 14 | + Permission = "moretools.grenade", |
| 15 | + Platforms = new[] { CommandPlatform.RemoteAdmin, CommandPlatform.ServerConsole }, |
| 16 | + Parameters = new[] { "Players", "(Amount)" } |
| 17 | +)] |
| 18 | +public class Grenade : PlayerCommand |
6 | 19 | {
|
7 |
| - [CommandInformation( |
8 |
| - Name = "Grenade", |
9 |
| - Aliases = new string[] { "gn" }, |
10 |
| - Description = "Spawns grenades at the player location", |
11 |
| - Permission = "moretools.grenade", |
12 |
| - Platforms = new Platform[] { Platform.RemoteAdmin, Platform.ServerConsole }, |
13 |
| - Usage = "Grenade players (optional amount)", |
14 |
| - Arguments = new[] { "Players", "(Amount)" } |
15 |
| - )] |
16 |
| - public class Grenade : ISynapseCommand |
| 20 | + public override void Execute(SynapseContext context, ref CommandResult result) |
17 | 21 | {
|
18 |
| - public CommandResult Execute(CommandContext context) |
| 22 | + if (context.Arguments.Length < 1) |
19 | 23 | {
|
20 |
| - if (context.Arguments.Count < 1) |
21 |
| - return new CommandResult |
22 |
| - { |
23 |
| - Message = "Usage: Grenade players (optional amount)", |
24 |
| - State = CommandResultState.Error |
25 |
| - }; |
26 |
| - |
27 |
| - if (context.Arguments.Count < 2) |
28 |
| - context.Arguments = new System.ArraySegment<string>(new[] { context.Arguments.At(0), "1" }); |
| 24 | + result.Response = "Usage: grenade players (optional amount)"; |
| 25 | + result.StatusCode = CommandStatusCode.Error; |
| 26 | + return; |
| 27 | + } |
29 | 28 |
|
30 |
| - if (!Extensions.TryGetPlayers(context.Arguments.At(0), context.Player, out var players)) |
31 |
| - return new CommandResult |
32 |
| - { |
33 |
| - Message = "No Player was found", |
34 |
| - State = CommandResultState.Error |
35 |
| - }; |
| 29 | + if (context.Arguments.Length < 2) |
| 30 | + context.Arguments = new[] { context.Arguments[0], "1" }; |
36 | 31 |
|
37 |
| - if (!int.TryParse(context.Arguments.At(1), out var amount)) |
38 |
| - return new CommandResult |
39 |
| - { |
40 |
| - Message = "Invalid Amount of grenades", |
41 |
| - State = CommandResultState.Error |
42 |
| - }; |
| 32 | + if (!PlayerService.TryGetPlayers(context.Arguments[0], out var players, context.Player)) |
| 33 | + { |
| 34 | + result.Response = "No Player was found"; |
| 35 | + result.StatusCode = CommandStatusCode.NotFound; |
| 36 | + return; |
| 37 | + } |
43 | 38 |
|
44 |
| - foreach (var player in players) |
45 |
| - for (int i = 0; i < amount; i++) |
46 |
| - Map.Get.SpawnGrenade(player.Position, Vector3.zero,3,Synapse.Api.Enum.GrenadeType.Grenade,context.Player); |
| 39 | + if (!int.TryParse(context.Arguments[1], out var amount)) |
| 40 | + { |
| 41 | + result.Response = "Invalid Amount"; |
| 42 | + return; |
| 43 | + } |
47 | 44 |
|
48 |
| - return new CommandResult |
| 45 | + foreach (var player in players) |
| 46 | + for (int i = 0; i < amount; i++) |
49 | 47 | {
|
50 |
| - Message = "Grenades are spawned", |
51 |
| - State = CommandResultState.Ok |
52 |
| - }; |
53 |
| - } |
| 48 | + var item = new SynapseItem(ItemType.GrenadeHE, player.Position); |
| 49 | + item.Throwable.Fuse(player); |
| 50 | + } |
| 51 | + |
| 52 | + result.Response = "Grenade was spawned"; |
54 | 53 | }
|
55 | 54 | }
|
0 commit comments