-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathTestConsoleCommandsSystem.cs
More file actions
68 lines (58 loc) · 2.2 KB
/
Copy pathTestConsoleCommandsSystem.cs
File metadata and controls
68 lines (58 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using SampSharp.Entities;
using SampSharp.Entities.SAMP;
using SampSharp.Entities.SAMP.Commands;
namespace TestMode.OpenMp.Entities.Systems;
public class TestConsoleCommandsSystem(IEntityManager entityManager) : ISystem
{
[ConsoleCommand(Name = "list_players")]
public void ConsoleListPlayers()
{
var players = entityManager.GetComponents<Player>();
Console.WriteLine($"Active players: {players.Count()}");
foreach (var player in players.Where(p => p.IsComponentAlive))
{
Console.WriteLine($" [{player.Entity}] {player.Name} (Health: {player.Health:F0}, Armor: {player.Armour:F0})");
}
}
[ConsoleCommand(Name = "server_info")]
public void ConsoleServerInfo()
{
var playerCount = entityManager.GetComponents<Player>().Length;
Console.WriteLine("=== Server Info ===");
Console.WriteLine($"Active Players: {playerCount}");
Console.WriteLine($"Current Time: {DateTime.UtcNow:yyyy-MM-dd HH:mm:ss}");
Console.WriteLine("===================");
}
[ConsoleCommand(Name = "time")]
public void ConsoleTime(IServerService server)
{
Console.WriteLine($"Server tick count: {server.TickCount}ms");
Console.WriteLine($"Server tick rate: {server.TickRate}");
Console.WriteLine($"Max players: {server.MaxPlayers}");
Console.WriteLine($"Player pool size: {server.PlayerPoolSize}");
}
[ConsoleCommand(Name = "add_numbers")]
[Alias("add")]
public void AddCommand(int a, int b)
{
Console.WriteLine($"{a} + {b} = {a + b}");
}
[ConsoleCommand(Name = "double_number")]
public void DoubleValueCommand([CommandParameter("value", typeof(DoubleIntParser))] int v)
{
Console.WriteLine(v);
}
private class DoubleIntParser : ICommandParameterParser
{
private readonly IntParser _inner = new();
public bool TryParse(IServiceProvider services, ref StringSpan inputText, out object? result)
{
if (_inner.TryParse(services, ref inputText, out result) && result is int num)
{
result = num * 2;
return true;
}
return false;
}
}
}