Skip to content

Commit

Permalink
2023-11-2 update
Browse files Browse the repository at this point in the history
fix_botkick
  • Loading branch information
fbef0102 committed Nov 1, 2023
1 parent 27f05d8 commit 2f28674
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Help server to record, make server more fun, and more useful plugins for adm.
* 沒有團隊聊天頻道只有公開聊天頻道
* <b>[l4d_current_survivor_progress](/l4d_current_survivor_progress)</b>: Print survivor progress in flow percents
* 使用指令顯示人類目前的路程
* <b>[fix_botkick](/fix_botkick)</b>: Fixed no Survivor bots issue or too many Survivor bots issue after map loading.
* <b>[fix_botkick](/fix_botkick)</b>: Fixed no Survivor bots issue after map loading.
* 解決換圖之後沒有任何倖存者Bot的問題
* <b>[lockdown_system-l4d2](/lockdown_system-l4d2)</b>: Locks Saferoom Door Until Someone Opens It.
* 倖存者必須等待時間到並合力對抗屍潮與Tank才能打開終點安全門
Expand Down
Binary file modified fix_botkick/plugins/fix_botkick.smx
Binary file not shown.
30 changes: 22 additions & 8 deletions fix_botkick/readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Description | 內容
Fixed no Survivor bots issue or too many Survivor bots issue after map loading.
(Usually this bug happens when using readyup plugin.)
Fixed no Survivor bots issue after map loading.

* Video | 影片展示
<br>None
Expand All @@ -9,6 +8,13 @@ Fixed no Survivor bots issue or too many Survivor bots issue after map loading.
* No survivor bots after map loading (This is bug). (修復換圖後沒有倖存者bot)
<br/>![fix_botkick_1](image/fix_botkick_1.jpg)

* <details><summary>How does it work?</summary>

* After map loading, fixed no survivor bots issue sometimes.
* Usually this bug happens when using ready up plugin.
* Or using l4d1+2 character plugin like CSM
</details>

* Require | 必要安裝
<br>None

Expand Down Expand Up @@ -41,6 +47,9 @@ Fixed no Survivor bots issue or too many Survivor bots issue after map loading.

* <details><summary>Changelog | 版本日誌</summary>

* v1.0 (2023-11-2)
* Improve code

* v1.4 (2023-8-24)
* Improve code

Expand All @@ -53,13 +62,18 @@ Fixed no Survivor bots issue or too many Survivor bots issue after map loading.
解決換圖之後沒有任何倖存者Bot的問題

* 原理
* 使用某一些藥抗插件或者readyup插件才會發生這個bug: 換圖之後偶而沒有任何倖存者Bot
* 安裝這個插件修復上述問題
* 修復換圖之後沒有任何倖存者Bot
* 使用某一些藥抗插件或者readyup插件會經常發生這個bug
* 使用L4D1+2角色模組插件也會有這個bug
* 建議等真的有這個bug再來安裝此插件
* 此插件不適用於多人對抗或多人5+戰役伺服器

* 功能
* 管理員手動輸入!botfix修復

* <details><summary>命令中文介紹 (點我展開)</summary>

* **管理員手動輸入!botfix修復 (權限: ADMFLAG_ROOT)**
```php
sm_botfix
```
</details>

* <details><summary>相關的官方指令中文介紹 (點我展開)</summary>

Expand Down
74 changes: 49 additions & 25 deletions fix_botkick/scripting/fix_botkick.sp
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#define PLUGIN_VERSION "1.4"

#include <sourcemod>
#pragma semicolon 1
#pragma newdecls required //強制1.7以後的新語法

#define ADD_BOT "sb_add"
#define DELAY_BOT_CLIENT_Check 1.0
#include <sourcemod>
#define PLUGIN_VERSION "1.0h-2023/11/2"

public Plugin myinfo =
{
Expand All @@ -16,10 +13,14 @@ public Plugin myinfo =
url = "https://steamcommunity.com/profiles/76561198026784913/"
}

#define DELAY_BOT_CLIENT_Check 1.0

ConVar g_hSurvivorLimit;
int g_iCvarSurvLimit;
static bool bTempBlock;

int g_iPlayerSpawn, g_iRoundStart;

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
EngineVersion test = GetEngineVersion();
Expand All @@ -45,43 +46,61 @@ public void OnPluginStart()
HookEvent("player_team", SF_ev_PlayerTeam);
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);//每回合開始就發生的event
HookEvent("player_spawn",Event_PlayerSpawn, EventHookMode_PostNoCopy);
HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy); //trigger twice in versus/survival/scavenge mode, one when all survivors wipe out or make it to saferom, one when first round ends (second round_start begins).
HookEvent("map_transition", Event_RoundEnd, EventHookMode_PostNoCopy); //all survivors make it to saferoom, and server is about to change next level in coop mode (does not trigger round_end)
HookEvent("mission_lost", Event_RoundEnd, EventHookMode_PostNoCopy); //all survivors wipe out in coop mode (also triggers round_end)
HookEvent("finale_vehicle_leaving", Event_RoundEnd, EventHookMode_PostNoCopy); //final map final rescue vehicle leaving (does not trigger round_end)

RegAdminCmd("sm_botfix", CmdBotFix, ADMFLAG_ROOT);
}

void OnCvarChange_SurvivorLimit(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_iCvarSurvLimit = g_hSurvivorLimit.IntValue;
}

public void OnMapStart()
{
bTempBlock = false;
SetConVarBounds(g_hSurvivorLimit, ConVarBound_Upper, true, 32.0);
SetConVarBounds(g_hSurvivorLimit, ConVarBound_Lower, true, 1.0);
}

public Action CmdBotFix(int client, int args)
public void OnMapEnd()
{
ClearDefault();
}

Action CmdBotFix(int client, int args)
{
SF_Fix();
ReplyToCommand(client, "Checking complete.");
return Plugin_Handled;
}

int g_iPlayerSpawn, g_iRoundStart;
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
if( g_iPlayerSpawn == 1 && g_iRoundStart == 0 )
CreateTimer(0.5, tmrStart, _, TIMER_FLAG_NO_MAPCHANGE);
g_iRoundStart = 1;
}

public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
if( g_iPlayerSpawn == 0 && g_iRoundStart == 1 )
CreateTimer(0.5, tmrStart, _, TIMER_FLAG_NO_MAPCHANGE);
g_iPlayerSpawn = 1;
}

void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
ClearDefault();
}

Action tmrStart(Handle timer)
{
g_iPlayerSpawn = 0;
g_iRoundStart = 0;
ClearDefault();

bTempBlock = false;

for (int i = 1; i <= MaxClients; i++)
Expand All @@ -106,17 +125,16 @@ void SF_ev_PlayerTeam(Event event, const char[] name, bool dontBroadcast)
{
if (event.GetBool("disconnect") == false){
bTempBlock = true;
CreateTimer(1.0, SF_t_CheckBots);
CreateTimer(DELAY_BOT_CLIENT_Check, SF_t_CheckBots);
}
}
}


Action SF_t_CheckBots(Handle timer)
{
for (int i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i)&&IsClientInGame(i)&&!IsFakeClient(i))
if(IsClientInGame(i) && !IsFakeClient(i))
{
SF_Fix();
break;
Expand All @@ -129,11 +147,11 @@ Action SF_t_CheckBots(Handle timer)
void SF_Fix()
{
int iSurvivorCount;
bool bKickFakeClient;

for (int i = 1; i <= MaxClients; i++)
if (IsClientInGame(i) && GetClientTeam(i) == 2)
iSurvivorCount++;

if(iSurvivorCount == g_iCvarSurvLimit)
return;

Expand All @@ -142,23 +160,27 @@ void SF_Fix()
static int iFlag;

if (!iFlag)
iFlag = GetCommandFlags(ADD_BOT);
iFlag = GetCommandFlags("sb_add");

SetCommandFlags(ADD_BOT, iFlag & ~FCVAR_CHEAT);
SetCommandFlags("sb_add", iFlag & ~FCVAR_CHEAT);

while (iSurvivorCount < g_iCvarSurvLimit){
LogMessage("Bug detected. Trying to add a bot %d/%d", iSurvivorCount, g_iCvarSurvLimit);
ServerCommand(ADD_BOT);
ServerCommand("sb_add");
iSurvivorCount++;
}

SetCommandFlags(ADD_BOT, iFlag);
SetCommandFlags("sb_add", iFlag);

CreateTimer(DELAY_BOT_CLIENT_Check, SF_t_CheckBots);

return;
}

if (iSurvivorCount > g_iCvarSurvLimit){
/*if (iSurvivorCount > g_iCvarSurvLimit){
while (iSurvivorCount > g_iCvarSurvLimit){
LogMessage("Bug detected. Trying to kick a bot %d/%d", iSurvivorCount, g_iCvarSurvLimit);
bKickFakeClient = false;
bool bKickFakeClient = false;
for (int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && GetClientTeam(i) == 2 && IsFakeClient(i))
Expand All @@ -182,11 +204,13 @@ void SF_Fix()
}
}
}
CreateTimer(DELAY_BOT_CLIENT_Check, SF_t_CheckBots);
}
}*/
}

public void OnCvarChange_SurvivorLimit(ConVar convar, const char[] oldValue, const char[] newValue)
void ClearDefault()
{
g_iCvarSurvLimit = g_hSurvivorLimit.IntValue;
}
g_iRoundStart = 0;
g_iPlayerSpawn = 0;
}

0 comments on commit 2f28674

Please sign in to comment.