mirror of
https://github.com/creazy231/cs2-css-flashlight.git
synced 2026-09-27 20:17:04 +02:00
⚙️ Add AllowedTeam and bump to 0.1.1
Restrict flashlight by CT/T/Any via config, drop tracked docs, and ship the 0.1.1 version bump. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
6f46cee3c1
commit
c7779740c7
8 changed files with 73 additions and 212 deletions
|
|
@ -16,7 +16,7 @@ public class FlashlightPlugin : BasePlugin, IPluginConfig<FlashlightConfig>
|
|||
public override string ModuleAuthor => "creazy.eth";
|
||||
public override string ModuleName => "Flashlight";
|
||||
public override string ModuleDescription => "Flashlight for Counter-Strike 2";
|
||||
public override string ModuleVersion => "0.1.0";
|
||||
public override string ModuleVersion => "0.1.1";
|
||||
|
||||
public FlashlightConfig Config { get; set; } = new();
|
||||
|
||||
|
|
@ -169,6 +169,12 @@ public class FlashlightPlugin : BasePlugin, IPluginConfig<FlashlightConfig>
|
|||
|
||||
private void TryToggleFlashlight(CCSPlayerController player, PlayerFlashlightState state)
|
||||
{
|
||||
// Turning on is restricted by AllowedTeam; turning off is always allowed.
|
||||
if (!state.IsOn && !FlashlightLogic.IsTeamAllowed(Config.AllowedTeam, (byte)player.Team))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var isOn = state.IsOn;
|
||||
var canToggle = state.CanToggle;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@ public class FlashlightConfig : BasePluginConfig
|
|||
[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;
|
||||
|
||||
|
|
@ -97,5 +103,17 @@ public class FlashlightConfig : BasePluginConfig
|
|||
{
|
||||
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"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,4 +59,18 @@ public static class FlashlightLogic
|
|||
{
|
||||
return !isOn && hasValidLight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether <paramref name="team"/> may use the flashlight.
|
||||
/// Team values match CS2: 2 = Terrorist, 3 = Counter-Terrorist.
|
||||
/// </summary>
|
||||
public static bool IsTeamAllowed(string allowedTeam, byte team)
|
||||
{
|
||||
return allowedTeam switch
|
||||
{
|
||||
"T" => team == 2,
|
||||
"CT" => team == 3,
|
||||
_ => true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue