[游戏代码]求生之路插件:倒计时写法

这篇博客介绍了如何在游戏《求生之路》中编写插件实现倒计时功能,包括学习连接语法和具体的时间脚本写法教程。

学习连接
语法的教程
时间脚本写法教程

#include <sourcemod>
#include <sdktools>

new Handle:a1 = null;
ConVar gamestart_sec;

public Plugin:myinfo = 
{
	name = "[紫冰] 倒计时",
	author = "紫冰",
	description = "倒计时功能",
	version = "1.0",
	url = ""
};

public OnPluginStart()
{
	HookEvent("round_start",	Event_RoundStart);
	HookEvent("vote_passed", 	Event_VoteEnded);
	HookEvent("vote_changed", 	Event_VoteEnded);
	HookEvent("map_transition", Event_VoteEnded);
	
	RegConsoleCmd("sm_a1",Command_a1,"");
	gamestart_sec = CreateConVar("l4d1_timer_sec","60","时间设定", FCVAR_SPONLY);
}
//初始时间
public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
	CreateTimer(0.1, GameReStart);
}

public Action GameReStart(Handle timer)
{
	if(a1 != null)
	{
		ResetTimer();
	}
	else
	{
		a1 = CreateTimer(1.0, GameStart,GetConVarInt(gamestart_sec));
	}
	return Plugin_Handled;
}
public Action GameStart(Handle timer,int time)
{
	if( time > 0 && a1 != null)
	{
		CreateTimer( 1.0, GameStart, --time);
	}
	else
	{
		return Plugin_Stop;
	}
	if(time <= 10 && time > 0)
	{
		EmitSoundToAll("ambient/alarms/klaxon1.wav", _, SNDCHAN_AUTO, SNDLEVEL_RAIDSIREN, SND_NOFLAGS, SNDVOL_NORMAL, SNDPITCH_LOW, -1, NULL_VECTOR, NULL_VECTOR, true, 0.0);
	}
	PrintHintTextToAll("尸潮来袭: %i 秒", time);
	return Plugin_Continue;
}

void ResetTimer()
{
	if(a1 != null)
	{
		KillTimer(a1);
		a1 = null;
	}
}

public Action Event_VoteEnded(Event event, const char[] name, bool dontBroadcast)
{
	PrintToChatAll("\x04[调试] 执行了投票操作...");
	a1 = null;
}

public Action Command_a1(client, args)
{
	a1 = null;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值