mirror of
https://github.com/creazy231/cs2-css-flashlight.git
synced 2026-09-27 20:17:04 +02:00
The light was positioned once at toggle time and then handed to the engine via SetParent + SetParentAttachmentMaintainOffset on the pawn's `axis_of_intent` attachment. That attachment carries the body's yaw but not the view pitch, so once parented the beam could only ever rotate horizontally — looking up or down did nothing. Drop the parenting and drive the light's transform ourselves every tick from the pawn's live AbsOrigin and V_angle, which is how the plugin behaved before 0.1.1 replaced the per-tick teleport with a parented entity. Also: - OnTick no longer short-circuits on !AllowUseKey, which otherwise stopped the light updating for servers that only expose css_fl_toggle. - ForwardDistance now offsets the light horizontally only. Applying it along the pitched forward vector put the light below ground when looking straight down (crouched eye height 46 minus 54). - Sweep up the light when the pawn is dead; an un-parented entity no longer dies with its pawn. - Remove the now-unused AttachmentName config key. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
111 lines
3.4 KiB
C#
111 lines
3.4 KiB
C#
using System.Text.Json.Serialization;
|
|
using CounterStrikeSharp.API.Core;
|
|
|
|
namespace Flashlight;
|
|
|
|
public class FlashlightConfig : BasePluginConfig
|
|
{
|
|
[JsonPropertyName("Enabled")]
|
|
public bool Enabled { get; set; } = true;
|
|
|
|
[JsonPropertyName("AllowUseKey")]
|
|
public bool AllowUseKey { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Which team may use the flashlight: Any, CT, or T.
|
|
/// </summary>
|
|
[JsonPropertyName("AllowedTeam")]
|
|
public string AllowedTeam { get; set; } = "Any";
|
|
|
|
[JsonPropertyName("ToggleCooldownSeconds")]
|
|
public float ToggleCooldownSeconds { get; set; } = 0.25f;
|
|
|
|
[JsonPropertyName("Brightness")]
|
|
public float Brightness { get; set; } = 1.0f;
|
|
|
|
[JsonPropertyName("Range")]
|
|
public float Range { get; set; } = 2048f;
|
|
|
|
[JsonPropertyName("ColorR")]
|
|
public byte ColorR { get; set; } = 255;
|
|
|
|
[JsonPropertyName("ColorG")]
|
|
public byte ColorG { get; set; } = 255;
|
|
|
|
[JsonPropertyName("ColorB")]
|
|
public byte ColorB { get; set; } = 255;
|
|
|
|
[JsonPropertyName("ColorTemperature")]
|
|
public float ColorTemperature { get; set; } = 6500f;
|
|
|
|
[JsonPropertyName("CastShadows")]
|
|
public bool CastShadows { get; set; } = true;
|
|
|
|
[JsonPropertyName("SoftX")]
|
|
public float SoftX { get; set; } = 1.0f;
|
|
|
|
[JsonPropertyName("SoftY")]
|
|
public float SoftY { get; set; } = 1.0f;
|
|
|
|
[JsonPropertyName("Skirt")]
|
|
public float Skirt { get; set; } = 0.5f;
|
|
|
|
[JsonPropertyName("SkirtNear")]
|
|
public float SkirtNear { get; set; } = 1.0f;
|
|
|
|
[JsonPropertyName("SizeX")]
|
|
public float SizeX { get; set; } = 45f;
|
|
|
|
[JsonPropertyName("SizeY")]
|
|
public float SizeY { get; set; } = 45f;
|
|
|
|
[JsonPropertyName("SizeZ")]
|
|
public float SizeZ { get; set; } = 0.03f;
|
|
|
|
[JsonPropertyName("ForwardDistance")]
|
|
public float ForwardDistance { get; set; } = 54f;
|
|
|
|
[JsonPropertyName("StandEyeOffsetZ")]
|
|
public float StandEyeOffsetZ { get; set; } = 64f;
|
|
|
|
[JsonPropertyName("CrouchEyeOffsetZ")]
|
|
public float CrouchEyeOffsetZ { get; set; } = 46f;
|
|
|
|
[JsonPropertyName("LightCookie")]
|
|
public string LightCookie { get; set; } = "materials/effects/lightcookies/flashlight.vtex";
|
|
|
|
public void Clamp()
|
|
{
|
|
ToggleCooldownSeconds = Math.Max(0f, ToggleCooldownSeconds);
|
|
Brightness = Math.Max(0f, Brightness);
|
|
Range = Math.Max(1f, Range);
|
|
ColorTemperature = Math.Clamp(ColorTemperature, 1000f, 12000f);
|
|
SoftX = Math.Max(0f, SoftX);
|
|
SoftY = Math.Max(0f, SoftY);
|
|
Skirt = Math.Max(0f, Skirt);
|
|
SkirtNear = Math.Max(0f, SkirtNear);
|
|
SizeX = Math.Max(0f, SizeX);
|
|
SizeY = Math.Max(0f, SizeY);
|
|
SizeZ = Math.Max(0f, SizeZ);
|
|
ForwardDistance = Math.Max(0f, ForwardDistance);
|
|
StandEyeOffsetZ = Math.Max(0f, StandEyeOffsetZ);
|
|
CrouchEyeOffsetZ = Math.Max(0f, CrouchEyeOffsetZ);
|
|
|
|
if (string.IsNullOrWhiteSpace(LightCookie))
|
|
{
|
|
LightCookie = "materials/effects/lightcookies/flashlight.vtex";
|
|
}
|
|
|
|
AllowedTeam = NormalizeAllowedTeam(AllowedTeam);
|
|
}
|
|
|
|
public static string NormalizeAllowedTeam(string? value)
|
|
{
|
|
return value?.Trim().ToUpperInvariant() switch
|
|
{
|
|
"T" or "TERRORIST" or "TERRORISTS" => "T",
|
|
"CT" or "COUNTERTERRORIST" or "COUNTERTERRORISTS" or "COUNTER-TERRORIST" or "COUNTER-TERRORISTS" => "CT",
|
|
_ => "Any"
|
|
};
|
|
}
|
|
}
|