[游戏代码]求生之路插件:人物角色选择

本文分享了一款《求生之路》(L4D)的游戏插件,重点在于角色选择的实现。提供了代码下载链接以及原作者的论坛讨论帖,帮助玩家和开发者理解并定制角色选择功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码下载:https://pan.baidu.com/s/1RweUPiDNA0_TfFsBLsC_WA


#define PLUGIN_VERSION "1.0 Special"
#define PLUGIN_NAME "[紫冰]人物选择插件"
#define DEBUG 0

// includes
#include <sourcemod>
#include <sdktools>

// Client numbers are dynamic, keep changing according to the spawn order
new bool:g_bSpawned[MAXPLAYERS+1];

// CVars Handles
new Handle:g_hActivate;
new Handle:h_Fun;

// Variables
new g_InfectedTicket; // Number used to determine what the spawn infected function should spawn

// Arrays
new bool:OneToSpawn[MAXPLAYERS+1]; // Used to tell the plugin that this client will be the one to spawn and not place any spawn restrictions on that client
new bool:Fun;
new bool:Activate;

// Offsets

new offsetIsGhost; // Offset to see if the player is a ghost or not
new offsetIsAlive; // Offset to see if the player is alive or not
new offsetlifeState // Offset to prevent the player from spawning when the player is not supposed to

public Plugin:myinfo = 
{
	name = PLUGIN_NAME,
	author = "作者:L4D2&编译:紫冰",
	description = "一代人物自由选择.",
	version = PLUGIN_VERSION,
	url = "http://blog.youkuaiyun.com/zbzibing"
}

public OnPluginStart()
{
	
	offsetIsGhost = FindSendPropInfo("CTerrorPlayer", "m_isGhost");
	offsetIsAlive = FindSendPropInfo("CTransitioningPlayer", "m_isAlive");
	offsetlifeState = FindSendPropInfo("CTerrorPlayer", "m_lifeState");
	
	// Clean up the spawn variable (deprecated)
	for(new i=1; i<=GetMaxClients(); ++i)
	{
		g_bSpawned[i]=false;
	}
	
	// convars
	g_hActivate = CreateConVar("l4d_chars_enable", "1", "人物更换角色开关.", FCVAR_PLUGIN|FCVAR_NOTIFY, true, 0.0, true, 1.0);
	h_Fun = CreateConVar("l4d_chars_fun_mode", "0", "值为1,只改变角色,不改变能力(1值感染者使用游戏会崩溃)", FCVAR_PLUGIN|FCVAR_NOTIFY, true, 0.0, true, 1.0);
	HookConVarChange(h_Fun, ConVarFun);
	HookConVarChange(g_hActivate, ConVarActivate);
	Fun = GetConVarBool(h_Fun);
	Activate = GetConVarBool(g_hActivate);
	
	// config file
	AutoExecConfig(true, "L4D_BX");
	
	// sourcemod command
	RegConsoleCmd("sm_bx", PlayerPanelActivator);
}

// Adding ConVar Hooks allows us to change the cvar in-game AND have it take effect on change immediately

public ConVarFun(Handle:convar, const String:oldValue[], const String:newValue[])
{
	Fun = GetConVarBool(h_Fun);
}
public ConVarActivate(Handle:convar, const String:oldValue[], const String:newValue[])
{
	Activate = GetConVarBool(g_hActivate);
}
public OnClientPutInServer(client)
{
	if (client)
	{
		if (Activate)
			CreateTimer(30.0, AnnounceCharSelect, client);
	}
}

public CharPanel(Handle:menu, MenuAction:action, param1, param2)
{
	if (action == MenuAction_Select)
	{
		switch (param2)
		{
			case 1:
			{
				if (!Fun)
				{
					// get prop
					new offset = FindSendPropInfo("CTerrorPlayer", "m_survivorCharacter");
					new char = GetEntData(param1, offset, 1);
					
					// set char
					char = 1;
					SetEntData(param1, offset, char, 1, true);
					
					// update client model info
					decl String:model[] = "models/survivors/survivor_teenangst.mdl";
					SetEntityModel(param1, model);
					
					PrintToChat(param1, "\x04[紫冰]\x01当前角色:\x03佐伊");
				}
				else
				{
					decl String:model[] = "models/survivors/survivor_teenangst.mdl";
					SetEntityModel(param1, model);
					PrintToChat(param1, "\x04[紫冰]\x01当前角色:\x03佐伊");
				}
			}
			case 2:
			{
				if (!Fun)
				{
					// get prop
					new offset = FindSendPropInfo("CTerrorPlayer", "m_survivorCharacter");
					new char = GetEntData(param1, offset, 1);
					
					// set char
					char = 2;
					SetEntData(param1, offset, char, 1, true)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值