L4D2 Multiplayer RMC Source code
--------------------------------------------------
public void PrintToChatAll(char format[])
{
char buffer[256];
int i = 1;
while (i <= MaxClients)
{
if (IsClientInGame(i))
{
SetGlobalTransTarget(i);
VFormat(buffer, 254, format, 2);
PrintToChat(i, "%s", buffer);
i++;
}
i++;
}
return void 0;
}
public void OnPluginStart()
{
CreateConVar("L4D2_Multiplayer_RMC_version", "1.1", "L4D2多人游戏设置", 8512, false, 0, false, 0);
RegConsoleCmd("sm_jg", Jointhegame, "", 0);
RegConsoleCmd("sm_joingame", Jointhegame, "", 0);
RegConsoleCmd("sm_away", Gotoaway, "", 0);
RegConsoleCmd("sm_addbot", CreateOneBot, "", 0);
RegConsoleCmd("sm_sinfo", Vserverinfo, "", 0);
RegConsoleCmd("sm_bd", Bindkeyhots, "", 0);
RegConsoleCmd("sm_rhelp", Scdescription, "", 0);
RegAdminCmd("kb", Kbcheck, 2, "", "", 0);
RegConsoleCmd("sm_sp", RListLoadplayer, "", 0);
RegConsoleCmd("sm_zs", Rzhisha, "", 0);
RegAdminCmd("sset", Numsetcheck, 2, "", "", 0);
HookEvent("round_start", EventHook 25, EventHookMode 2);
HookEvent("player_team", EventHook 27, EventHookMode 1);
hUsermnums = CreateConVar("L4D2_Rmc_total", "4", "服务器支持玩家人数设置", 0, true, 1, true, 24);
usermnums = GetConVarInt(hUsermnums);
hRJoincheck = CreateConVar("l4d2_ADM_CHA", "0", "[0=关|1=开]是否开启2个管理员预留通道", 0, true, 0, true, 1);
RJoincheck = GetConVarBool(hRJoincheck);
hAwayCEnable = CreateConVar("L4D2_Away_Enable", "0", "[0=关|1=开]是否只允许管理员使用!away加入观察者.1=On,0=Off", 0, true, 0, true, 1);
AwayCEnable = GetConVarBool(hAwayCEnable);
hAutoBotcheck = CreateConVar("l4d2_AUOT_ADDBOT", "1", "[0=关|1=开]是否开启自动增加BOT", 0, true, 0, true, 1);
RAutoBotcheck = GetConVarBool(hAutoBotcheck);
RCNcheck = 0;
AutoExecConfig(true, "l4d2_rmc", "sourcemod");
return void 0;
}
public void OnMapStart()
{
SetConVarInt(FindConVar("z_spawn_flow_limit"), 999999, false, false);
RJoincheck = GetConVarBool(hRJoincheck);
AwayCEnable = GetConVarBool(hAwayCEnable);
RAutoBotcheck = GetConVarBool(hAutoBotcheck);
if (!RCNcheck)
{
usermnums = GetConVarInt(hUsermnums);
if (usermnums < 1)
{
usermnums = 1;
}
}
return void 0;
}
public Action Event_rmcRoundStart(Handle event, char name[], bool dontBroadcast)
{
CreateTimer(1, rmcRepDelays, any 0, 0);
return Action 0;
}
public Action JgHintplayers16(Handle timer, any client)
{
if (0 < Botnums())
{
if (0 < Alivebotnums())
{
ClientCommand(client, "jointeam 2");
ClientCommand(client, "go_away_from_keyboard");
return Action 3;
}
PrintToChat(client, "\x05[加入失败:]\x04请等待BOT被拯救后再输入!jg加入.");
return Action 3;
}
PrintToChat(client, "\x05[加入失败:]\x04没有足够的BOT允许你控制,请输入!addbot增加电脑. ");
return Action 3;
}
public void OnClientDisconnect(int client)
{
int var1;
if (client)
{
Rmc_ChangeTeam[client] = 0;
CreateTimer(1, DisKickClient, any 0, 0);
}
return void 0;
}
public Action DisKickClient(Handle timer)
{
char asnus[4];
char aynus[4];
char abnus[4];
int asnus1 = 0;
int aynus1 = 0;
int abnus1 = 0;
Format(asnus, 3, "%i", Survivors());
Format(aynus, 3, "%i", Gonaways());
Format(abnus, 3, "%i", Botnums());
asnus1 = StringToInt(asnus, 10);
aynus1 = StringToInt(aynus, 10);
abnus1 = StringToInt(abnus, 10);
if (abnus1 > aynus1)
{
if (asnus1 > 4)
{
int i = 1;
while (i <= MaxClients)
{
int var1;
if (IsClientInGame(i))
{
KickClient(i, "");
}
i++;
}
}
}
return Action 0;
}
public Action rmcRepDelays(Handle timer)
{
if (usermnums < 1)
{
usermnums = 1;
}
if (RJoincheck)
{
ServerCommand("sm_cvar sv_maxplayers %i", usermnums + 2);
ServerCommand("sm_cvar sv_visiblemaxplayers %i", usermnums);
PrintToChatAll("\x04[提示] \x03公共位置\x01[%i] \x03管理员预留位置\x01[2]", 2272);
}
else
{
ServerCommand("sm_cvar sv_maxplayers %i", usermnums);
ServerCommand("sm_cvar sv_visiblemaxplayers %i", usermnums);
}
return Action 0;
}
public bool OnClientConnect(int client, char rejectmsg[], int maxlen)
{
if (RJoincheck)
{
int Rnmax = GetConVarInt(FindConVar("sv_maxplayers"));
int asnus1 = Allplayersn();
if (Rnmax + -2 <= asnus1)
{
int var1;
if (client)
{
KickClient(client, "服务器已满,你不是管理员无法进入预留通道!");
}
Rmc_ChangeTeam[client] = 0;
return true;
}
Rmc_ChangeTeam[client] = 0;
return true;
}
Rmc_ChangeTeam[client] = 0;
return true;
}
public Action Kbcheck(int client, int args)
{
if (GetUserFlagBits(client))
{
int ix = 1;
while (ix <= MaxClients)
{
int var1;
if (IsClientInGame(ix))
{
KickClient(ix, "");
ix++;
}
ix++;
}
PrintToChatAll("\x05[提示]\x03 踢除所有bot.");
return Action 0;
}
ReplyToCommand(client, "[提示] 该功能只限管理员使用.");
return Action 0;
}
public Action Numsetcheck(int client, int args)
{
if (GetUserFlagBits(client))
{
rDisplaySnumMenu(client);
return Action 0;
}
ReplyToCommand(client, "[提示] 该功能只限管理员使用.");
return Action 0;
}
public int rDisplaySnumMenu(int client)
{
char namelist[64];
char nameno[4];
Handle menu = CreateMenu(MenuHandler 61, MenuAction 28);
SetMenuTitle(menu, "服务器人数设置");
int i = 1;
while (i <= 24)
{
Format(nameno, 3, "%i", i);
AddMenuItem(menu, nameno, namelist, 0);
i++;
}
SetMenuExitButton(menu, true);
DisplayMenu(menu, client, 0);
return 0;
}
public int rNumMenuHandler(Handle menu, MenuAction action, int client, int itemNum)
{
if (action == MenuAction 4)
{
char clientinfos[12];
int userids = 0;
GetMenuItem(menu, itemNum, clientinfos, 10, 0, "", 0);
userids = StringToInt(clientinfos, 10);
usermnums = userids;
RCNcheck = 1;
PrintToChat(client, "\x05[提醒:]\x04 默认人数请修改l4d2_rmc.cfg");
CreateTimer(0.1, rmcRepDelays, any 0, 0);
}
return 0;
}
public Action Scdescription(int client, int args)
{
PrintToChatAll("\x05[插件说明]\x03 !jg\x04或\x03!joingame\x04 加入游戏, \x03!away\x04 观察者, \x03!addbot\x04 增加一个电脑,");
PrintToChatAll("\x05[插件说明]\x03 !sinfo\x04 显示服务器人数信息, \x03!rhelp\x04 显示插件使用说明, \x03!bd\x04 绑定键盘 L 键自动输入joingame");
PrintToChatAll("\x05[插件说明]\x03 !sp\x04 显示还在加载中的玩家列表, \x03!zs\x04 自杀");
PrintToChatAll("\x05[插件说明]\x03 !kb\x04 踢除所有bot, \x03!sset\x04 设置服务器人数 \x03");
return Action 3;
}
public Action Bindkeyhots(int client, int args)
{
ClientCommand(client, "bind l \"say_team !joingame\"");
PrintToChat(client, "\x05[提醒:]\x04已绑定键盘\x03 L \x04键为自动输入\x03!joingame\x04");
return Action 3;
}
2018年04月17日 19点04分
3