[bot] Implement/match n_SetTimer(...)

* Implement/match `CScriptTimers::New(...)`
This commit is contained in:
RD42 2024-08-29 23:14:15 +08:00
parent 05e8c3b2a8
commit 323f51a166
4 changed files with 37 additions and 3 deletions

View File

@ -90,6 +90,7 @@ public:
CPlayerPool * GetPlayerPool() { return m_pPlayerPool; }; CPlayerPool * GetPlayerPool() { return m_pPlayerPool; };
CVehiclePool * GetVehiclePool() { return m_pVehiclePool; }; CVehiclePool * GetVehiclePool() { return m_pVehiclePool; };
RakClientInterface * GetRakClient() { return m_pRakClient; }; RakClientInterface * GetRakClient() { return m_pRakClient; };
CScriptTimers * GetTimers() { return m_pScriptTimers; };
CGameMode * GetBotMode() { return m_pGameMode; }; CGameMode * GetBotMode() { return m_pGameMode; };
void Init(PCHAR szHostOrIp,int iPort,PCHAR szPlayerName,PCHAR szPass,PCHAR szNpcMode); void Init(PCHAR szHostOrIp,int iPort,PCHAR szPlayerName,PCHAR szPass,PCHAR szNpcMode);

View File

@ -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; } } #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[]) // native print(const string[])
@ -33,8 +35,11 @@ static cell AMX_NATIVE_CALL n_format(AMX *amx, cell *params)
// native SetTimer(funcname[], interval, repeating) // native SetTimer(funcname[], interval, repeating)
static cell AMX_NATIVE_CALL n_SetTimer(AMX *amx, cell *params) static cell AMX_NATIVE_CALL n_SetTimer(AMX *amx, cell *params)
{ {
// TODO: n_SetTimer CHECK_PARAMS(3);
return 0;
char* szFuncName;
amx_StrParam(amx, params[1], szFuncName);
return pNetGame->GetTimers()->New(szFuncName, params[2], params[3], amx);
} }
// native KillTimer(timerid) // native KillTimer(timerid)

View File

@ -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;
}
//----------------------------------------------------------------------------------

View File

@ -4,7 +4,13 @@
struct ScriptTimer_s struct ScriptTimer_s
{ {
char _gap0[279]; char szScriptFunc[255];
int iTotalTime;
int iRemainingTime;
BOOL bRepeating;
BOOL bKilled;
AMX* pAMX;
int iParamCount;
void* cellParams; void* cellParams;
}; };
@ -21,6 +27,7 @@ public:
CScriptTimers(); CScriptTimers();
~CScriptTimers(); ~CScriptTimers();
DWORD New(char* szScriptFunc, int iInterval, BOOL bRepeating, AMX* pAMX);
void FreeMem(ScriptTimer_s* Timer); void FreeMem(ScriptTimer_s* Timer);
}; };