diff --git a/bot/scrtimers.cpp b/bot/scrtimers.cpp index 9184627..8ed7300 100644 --- a/bot/scrtimers.cpp +++ b/bot/scrtimers.cpp @@ -1,6 +1,8 @@ #include "main.h" +extern CNetGame* pNetGame; + //---------------------------------------------------------------------------------- CScriptTimers::CScriptTimers() @@ -106,3 +108,57 @@ void CScriptTimers::Kill(DWORD dwTimerId) //----------------------------------------------------------- +void CScriptTimers::Process(int iElapsedTime) +{ + DwordTimerMap::iterator itor; + CGameMode *pGameMode; + for (itor = m_Timers.begin(); itor != m_Timers.end(); itor++) + { + itor->second->iRemainingTime -= iElapsedTime; + if (itor->second->iRemainingTime <= 0) + { + DwordTimerMap::iterator itor_tmp = ++itor; itor--; + if (!itor->second->bKilled) + { + pGameMode = pNetGame->GetBotMode(); + if (pGameMode) + { + int idx; + AMX* amx = itor->second->pAMX; + if (amx && !amx_FindPublic(amx, itor->second->szScriptFunc, &idx)) + { + cell ret; + int count = itor->second->iParamCount; + int i = 0; + if (count > 0) + { + cell* pars = (cell*)itor->second->cellParams; + while (i < count) + { + amx_Push(amx, pars[i]); + i++; // Go forwards to maintain push order + } + } + amx_Exec(amx, &ret, idx); + } + } + } + + if (itor->second->bRepeating) + { + itor->second->iRemainingTime = itor->second->iTotalTime; + } + else + { + // Release parameter memory + FreeMem(itor->second); + Delete(itor->first); + } + itor = itor_tmp; + } + if (itor == m_Timers.end()) break; + } +} + +//---------------------------------------------------------------------------------- +// EOF diff --git a/bot/scrtimers.h b/bot/scrtimers.h index efb1565..1dc64fd 100644 --- a/bot/scrtimers.h +++ b/bot/scrtimers.h @@ -31,6 +31,7 @@ public: DWORD New(char* szScriptFunc, int iInterval, BOOL bRepeating, AMX* pAMX); void Delete(DWORD dwTimerId); void Kill(DWORD dwTimerId); + void Process(int iElapsedTime); void FreeMem(ScriptTimer_s* Timer); };