From e4770acd4465e5751628733db900a2afef9d611a Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Sat, 1 Jun 2024 18:40:37 +0800 Subject: [PATCH] [bot] Implement `n_IsPlayerConnected(...)` --- bot/net/netgame.h | 1 + bot/net/playerpool.h | 6 ++++++ bot/scrcustom.cpp | 5 +++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bot/net/netgame.h b/bot/net/netgame.h index 0a6fadc..671a154 100644 --- a/bot/net/netgame.h +++ b/bot/net/netgame.h @@ -70,6 +70,7 @@ public: int GetGameState() { return m_iGameState; }; + CPlayerPool * GetPlayerPool() { return m_pPlayerPool; }; RakClientInterface * GetRakClient() { return m_pRakClient; }; void Init(PCHAR szHostOrIp,int iPort,PCHAR szPlayerName,PCHAR szPass,PCHAR szNpcMode); diff --git a/bot/net/playerpool.h b/bot/net/playerpool.h index ff0a5c5..3b16a89 100644 --- a/bot/net/playerpool.h +++ b/bot/net/playerpool.h @@ -25,4 +25,10 @@ public: BOOL Delete(PLAYERID playerId, BYTE byteReason); + // Find out if the slot is inuse. + BOOL GetSlotState(PLAYERID playerId) { + if(playerId >= MAX_PLAYERS) { return FALSE; } + return m_bPlayerSlotState[playerId]; + }; + }; \ No newline at end of file diff --git a/bot/scrcustom.cpp b/bot/scrcustom.cpp index febe3db..671bb09 100644 --- a/bot/scrcustom.cpp +++ b/bot/scrcustom.cpp @@ -248,8 +248,9 @@ static cell AMX_NATIVE_CALL n_GetPlayerName(AMX *amx, cell *params) // native IsPlayerConnected(playerid) static cell AMX_NATIVE_CALL n_IsPlayerConnected(AMX *amx, cell *params) { - // TODO: n_IsPlayerConnected - return 0; + PLAYERID playerId = (PLAYERID)params[1]; + if (playerId >= MAX_PLAYERS || pNetGame->GetPlayerPool()->GetSlotState(playerId)) return 0; + return 1; } //----------------------------------------------------------------------------------