mirror of
https://github.com/roflmuffin/CounterStrikeSharp.git
synced 2025-12-06 08:03:12 -08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8cda8d9a50 | ||
|
|
575c859ddb |
@@ -144,4 +144,10 @@ public partial class CCSPlayerController
|
||||
/// Gets the active pawns button state. Will work even if the player is dead or observing.
|
||||
/// </summary>
|
||||
public PlayerButtons Buttons => (PlayerButtons)Pawn.Value.MovementServices!.Buttons.ButtonStates[0];
|
||||
|
||||
public void ExecuteClientCommand(string command)
|
||||
{
|
||||
var entityIndex = this.EntityIndex;
|
||||
if (entityIndex != null) NativeAPI.IssueClientCommand((int)entityIndex.Value.Value - 1, command);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
|
||||
@@ -7,30 +8,57 @@ namespace CounterStrikeSharp.API.Modules.Utils
|
||||
{
|
||||
public static class EnumUtils
|
||||
{
|
||||
public static string? GetEnumMemberAttributeValue<T>(T enumValue)
|
||||
/// <summary>
|
||||
/// Brute force search using Enum.GetNames as enum members pointing to other enum members do not have the correct attributes.
|
||||
/// </summary>
|
||||
public static T? GetEnumMemberAttribute<T>(this Enum enumValue) where T : Attribute
|
||||
{
|
||||
var type = enumValue.GetType();
|
||||
foreach (var name in Enum.GetNames(type))
|
||||
{
|
||||
var field = type.GetField(name);
|
||||
if (field == null) continue;
|
||||
|
||||
var fieldValue = field.GetValue(null)!;
|
||||
if (fieldValue.Equals(enumValue))
|
||||
{
|
||||
var attribute = field.GetCustomAttribute<T>();
|
||||
if (attribute != null)
|
||||
{
|
||||
return attribute;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string? GetEnumMemberAttributeValue<T>(T? enumValue) where T : Enum
|
||||
{
|
||||
var enumType = typeof(T);
|
||||
|
||||
if(!enumType.IsEnum || enumValue == null)
|
||||
if (!enumType.IsEnum || enumValue == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var enumString = enumValue.ToString();
|
||||
|
||||
if(string.IsNullOrWhiteSpace(enumString))
|
||||
if (string.IsNullOrWhiteSpace(enumString))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var memberInfo = enumType.GetMember(enumString);
|
||||
var enumMemberAttribute = memberInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType<EnumMemberAttribute>().FirstOrDefault();
|
||||
var enumMemberAttribute = memberInfo.FirstOrDefault()?.GetCustomAttributes(false)
|
||||
.OfType<EnumMemberAttribute>().FirstOrDefault();
|
||||
if (enumMemberAttribute != null)
|
||||
{
|
||||
return enumMemberAttribute.Value;
|
||||
}
|
||||
|
||||
return null;
|
||||
// Brute force search by name if we still can't find it.
|
||||
return enumValue.GetEnumMemberAttribute<EnumMemberAttribute>()?.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -481,6 +481,15 @@ namespace TestPlugin
|
||||
command.ReplyToCommand($" {(char)i}Color 0x{i:x}");
|
||||
}
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_sound", "Play a sound to client")]
|
||||
public void OnCommandSound(CCSPlayerController? player, CommandInfo command)
|
||||
{
|
||||
if (player == null) return;
|
||||
if (!player.PlayerPawn.IsValid) return;
|
||||
|
||||
player.ExecuteClientCommand($"play sounds/ui/counter_beep.vsnd");
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_pause", "Pause Game")]
|
||||
public void OnCommandPause(CCSPlayerController? player, CommandInfo command)
|
||||
|
||||
Reference in New Issue
Block a user