代码下载: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)