partiusfabaa / cs2-VIPCore

48 stars 18 forks source link

Added API for blocking VIP feature to be used #73

Closed oylsister closed 3 weeks ago

oylsister commented 3 weeks ago

What do you think?


using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Capabilities;
using VipCoreApi;

namespace VipRestriction
{
    public class CPlugin : BasePlugin
    {
        public override string ModuleName => "Vip Restriction";
        public override string ModuleVersion => "1.0";
        private IVipCoreApi? _vipAPI { get; set; } 
        public static PluginCapability<IVipCoreApi> _vipCap { get; } = new("vipcore:core");

        public override void OnAllPluginsLoaded(bool hotReload)
        {
            _vipAPI = _vipCap.Get();

            if (_vipAPI == null)
                return;

            _vipAPI.OnPlayerUseFeature += OnPlayerUseFeature;
        }

        public HookResult? OnPlayerUseFeature(CCSPlayerController client, string feature, IVipCoreApi.FeatureState state, IVipCoreApi.FeatureType type)
        {
            if(client.TeamNum == 2)
            {
                Server.PrintToChatAll("Terrorist are not allowed.");
                return HookResult.Handled;
            }

            return HookResult.Continue;
        }
    }
}```