From 323f51a166c94938621e7d4da7f6b8c50bb04943 Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Thu, 29 Aug 2024 23:14:15 +0800 Subject: [PATCH] [bot] Implement/match `n_SetTimer(...)` * Implement/match `CScriptTimers::New(...)` --- bot/net/netgame.h | 1 + bot/scrcustom.cpp | 9 +++++++-- bot/scrtimers.cpp | 21 +++++++++++++++++++++ bot/scrtimers.h | 9 ++++++++- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/bot/net/netgame.h b/bot/net/netgame.h index 678e15c..2e033bb 100644 --- a/bot/net/netgame.h +++ b/bot/net/netgame.h @@ -90,6 +90,7 @@ public: CPlayerPool * GetPlayerPool() { return m_pPlayerPool; }; CVehiclePool * GetVehiclePool() { return m_pVehiclePool; }; RakClientInterface * GetRakClient() { return m_pRakClient; }; + CScriptTimers * GetTimers() { return m_pScriptTimers; }; CGameMode * GetBotMode() { return m_pGameMode; }; void Init(PCHAR szHostOrIp,int iPort,PCHAR szPlayerName,PCHAR szPass,PCHAR szNpcMode); diff --git a/bot/scrcustom.cpp b/bot/scrcustom.cpp index dbc3bbb..55522bd 100644 --- a/bot/scrcustom.cpp +++ b/bot/scrcustom.cpp @@ -3,6 +3,8 @@ #define CHECK_PARAMS(n) { if (params[0] != (n * sizeof(cell))) { logprintf("SCRIPT: Bad parameter count (Count is %d, Should be %d): ", params[0] / sizeof(cell), n); return 0; } } +extern CNetGame* pNetGame; + //---------------------------------------------------------------------------------- // native print(const string[]) @@ -33,8 +35,11 @@ static cell AMX_NATIVE_CALL n_format(AMX *amx, cell *params) // native SetTimer(funcname[], interval, repeating) static cell AMX_NATIVE_CALL n_SetTimer(AMX *amx, cell *params) { - // TODO: n_SetTimer - return 0; + CHECK_PARAMS(3); + + char* szFuncName; + amx_StrParam(amx, params[1], szFuncName); + return pNetGame->GetTimers()->New(szFuncName, params[2], params[3], amx); } // native KillTimer(timerid) diff --git a/bot/scrtimers.cpp b/bot/scrtimers.cpp index 3c47ce4..a5983cb 100644 --- a/bot/scrtimers.cpp +++ b/bot/scrtimers.cpp @@ -34,3 +34,24 @@ void CScriptTimers::FreeMem(ScriptTimer_s* Timer) //---------------------------------------------------------------------------------- +DWORD CScriptTimers::New(char* szScriptFunc, int iInterval, BOOL bRepeating, AMX* pAMX) +{ + m_dwTimerCount++; + + ScriptTimer_s* NewTimer = new ScriptTimer_s; + + strncpy(NewTimer->szScriptFunc, szScriptFunc, 255); + NewTimer->iTotalTime = iInterval; + NewTimer->iRemainingTime = iInterval; + NewTimer->bRepeating = bRepeating; + NewTimer->iParamCount = 0; + NewTimer->bKilled = false; + NewTimer->pAMX = pAMX; + NewTimer->cellParams = NULL; + + m_Timers.insert(DwordTimerMap::value_type(m_dwTimerCount, NewTimer)); + return m_dwTimerCount; +} + +//---------------------------------------------------------------------------------- + diff --git a/bot/scrtimers.h b/bot/scrtimers.h index a020f87..9002159 100644 --- a/bot/scrtimers.h +++ b/bot/scrtimers.h @@ -4,7 +4,13 @@ struct ScriptTimer_s { - char _gap0[279]; + char szScriptFunc[255]; + int iTotalTime; + int iRemainingTime; + BOOL bRepeating; + BOOL bKilled; + AMX* pAMX; + int iParamCount; void* cellParams; }; @@ -21,6 +27,7 @@ public: CScriptTimers(); ~CScriptTimers(); + DWORD New(char* szScriptFunc, int iInterval, BOOL bRepeating, AMX* pAMX); void FreeMem(ScriptTimer_s* Timer); };