реализуй мне это желательно без лишнего класса using System.Globalization; using…
- User
реализуй мне это желательно без лишнего класса
using System.Globalization; using System.Text.Json.Serialization; using CounterStrikeSharp.API.Modules.Utils;
namespace CustomRounds;
public class MainConfig { public bool Random { get; set; } = false; public Dictionary<string, int> Rounds { get; set; } = new();
public List<Positions> ChickenSpawns { get; set; } = new() { };}
public class Positions { [JsonIgnore] public Vector Vector => GetFromString(Position);
private static Vector GetFromString(string position) { var split = position.Split(' '); if (split.Length >= 3 && float.TryParse(split[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var x) && float.TryParse(split[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var y) && float.TryParse(split[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var z)) { return new Vector(x, y, z); } return Vector.Zero; } public string Position { get; set; } = string.Empty;}
- Assistant
To eliminate the
Positionsclass and keep your configuration simple, you can directly use aList<string>or aList<Vector>to store the chicken spawn positions in theMainConfigclass. Here's a refactored version of your code: - User
и добавь их по дефолту туда
private readonly Vector[] _positions = [ new Vector(-467.8291f, -1556.3018f, -39.96875f), new Vector(48.475086f, -1678.1808f, -167.96875f), new Vector(138.41733f, -1429.3252f, -175.96875f), new Vector(139.6984f, -1996.8335f, -167.96875f), new Vector(70.29725f, -1988.7999f, -167.96875f), new Vector(-719.18335f, -2424.963f, -169.53558f), new Vector(-803.7273f, -1891.9352f, -179.96875f), new Vector(-745.54913f, -1534.501f, -167.96875f), new Vector(-287.9016f, -1715.9772f, -167.96875f) ];
- Assistant
To add these positions by default to your configuration, you can initialize the
ChickenSpawnslist with these vector values directly in the constructor of theMainConfigclass. Here's how you can do it:using CounterStrikeSharp.API.Modules.Utils; namespace CustomRounds { public class MainConfig { public bool Random { get; set; } = false; public Dictionary<string, int> Rounds { get; set; } = new(); public List<Vector> ChickenSpawns { get; set; } public MainConfig() { ChickenSpawns = new List<Vector> { new Vector(-467.8291f, -1556.3018f, -39.96875f), new Vector(48.475086f, -1678.1808f, -167.96875f), new Vector(138.41733f, -1429.3252f, -175.96875f), new Vector(139.6984f, -1996.8335f, -167.96875f), new Vector(70.29725f, -1988.7999f, -167.96875f), new Vector(-719.18335f, -2424.963f, -169.53558f), new Vector(-803.7273f, -1891.9352f, -179.96875f), new Vector(-745.54913f, -1534.501f, -167.96875f), new Vector(-287.9016f, -1715.9772f, -167.96875f) }; } } }