diff --git a/bot/scrtimers.cpp b/bot/scrtimers.cpp index 2862979..21b6e39 100644 --- a/bot/scrtimers.cpp +++ b/bot/scrtimers.cpp @@ -34,6 +34,29 @@ void CScriptTimers::FreeMem(ScriptTimer_s* Timer) //---------------------------------------------------------------------------------- +// Kills only the timers found in one mode + +void CScriptTimers::DeleteForMode(AMX* pEndedAMX) +{ + bool bRestart = false; + DwordTimerMap::iterator itor; + for (itor = m_Timers.begin(); itor != m_Timers.end(); bRestart?(itor=m_Timers.begin()):(itor++)) + { + bRestart = false; + if (itor->second->pAMX == pEndedAMX) + { + FreeMem(itor->second); + SAFE_DELETE(itor->second); + m_Timers.erase(itor); + + // Can't continue iteration if a node is deleted, start iteration from start again. + bRestart = true; + } + } +} + +//---------------------------------------------------------------------------------- + DWORD CScriptTimers::New(char* szScriptFunc, int iInterval, BOOL bRepeating, AMX* pAMX) { m_dwTimerCount++; diff --git a/bot/scrtimers.h b/bot/scrtimers.h index 03b3b61..c1ad00f 100644 --- a/bot/scrtimers.h +++ b/bot/scrtimers.h @@ -27,6 +27,7 @@ public: CScriptTimers(); ~CScriptTimers(); + void DeleteForMode(AMX* pEndedAMX); DWORD New(char* szScriptFunc, int iInterval, BOOL bRepeating, AMX* pAMX); void Kill(DWORD dwTimerId); void FreeMem(ScriptTimer_s* Timer);