[CS2]C4倒计时 趣味内容 游戏性拓展

bvii 一级用户组 19小时前 21

插件介绍:

  • 如图,有帖子发过类似的,但这个是通过控制台设置的C4倒计时计算

mp_c4timer 80 //设置c4爆炸时间


插件依赖:


安装方法:

  • 按照CounterStrikeSharp插件安装方法安装即可

使用方法:

  • C4已安放!

下载地址

  • 附件,只编译了windows版,Linux自行编译

源码

using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Utils;
using System.Collections.Generic;

public class C4Timer : BasePlugin
{
    public override string ModuleName => "C4Timer";
    public override string ModuleVersion => "1.0";

    private float _plantTime = 0f;
    private ConVar? _c4TimerCvar;

    public override void Load(bool hotReload)
    {
        RegisterEventHandler<EventBombPlanted>(OnBombPlanted);
        RegisterEventHandler<EventBombDefused>(OnBombDefused);
        RegisterEventHandler<EventBombExploded>(OnBombExploded);
        RegisterEventHandler<EventRoundStart>(OnRoundStart);
        RegisterListener<Listeners.OnTick>(OnTick);
    }

    private HookResult OnRoundStart(EventRoundStart _, GameEventInfo __)
    {
        _plantTime = 0f;
        return HookResult.Continue;
    }

    private HookResult OnBombPlanted(EventBombPlanted @event, GameEventInfo _)
    {
        _c4TimerCvar = ConVar.Find("mp_c4timer");
        _plantTime = Server.CurrentTime;
        return HookResult.Continue;
    }

    private HookResult OnBombDefused(EventBombDefused _, GameEventInfo __)
    {
        _plantTime = 0f;
        return HookResult.Continue;
    }

    private HookResult OnBombExploded(EventBombExploded _, GameEventInfo __)
    {
        _plantTime = 0f;
        return HookResult.Continue;
    }

    private int GetC4Duration()
    {
        return _c4TimerCvar?.GetPrimitiveValue<int>() ?? 40;
    }

    private void OnTick()
    {
        if (_plantTime == 0f)
            return;

        float remain = GetC4Duration() - (Server.CurrentTime - _plantTime);
        if (remain <= 0) return;

        foreach (var p in Utilities.GetPlayers().Where(p => p.IsValid && !p.IsBot))
            p.PrintToCenterAlert($"C4爆炸倒计时:{remain:F1}s");
    }
}
上传的附件:

CSGO插件分享-申明 1、本网站名称:CSGO插件分享-中文站  网址:https://bbs.csgocn.net
2、本站的宗旨在于为CSGO玩家提供一个插件分享的中文资源平台,多数插件来源于SourceMod论坛,并配以中文介绍和安装教程。
3、欢迎有能力的朋友共享有趣的CSGO插件资源。
4、本站资源大多为百度网盘,如发现链接失效,可以点: 这里进行反馈,我们会第一时间更新。
最新回复 (1)
返回