Skip to content

Commit

Permalink
Added 5272: ([request] getTimer)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flobu committed Apr 6, 2010
1 parent cba22f8 commit 9a275fc
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 0 deletions.
21 changes: 21 additions & 0 deletions MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Util.cpp
Expand Up @@ -233,6 +233,27 @@ int CLuaFunctionDefs::IsTimer ( lua_State* luaVM )
return 1;
}

int CLuaFunctionDefs::GetTimer ( lua_State* luaVM )
{
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
if ( pLuaMain )
{
CLuaTimer* pLuaTimer = lua_totimer ( luaVM, 1 );
if ( pLuaTimer )
{
lua_pushnumber( luaVM, pLuaTimer->GetTimeLeft () );
lua_pushnumber( luaVM, pLuaTimer->GetRepeats () );
lua_pushnumber( luaVM, pLuaTimer->GetDelay () );
return 3;
}
else
m_pScriptDebugging->LogBadType ( luaVM, "getTimer" );
}

lua_pushboolean ( luaVM, false );
return 1;
}


int CLuaFunctionDefs::GetTickCount_ ( lua_State* luaVM )
{
Expand Down
1 change: 1 addition & 0 deletions MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h
Expand Up @@ -462,6 +462,7 @@ class CLuaFunctionDefs
LUA_DECLARE ( ResetTimer );
LUA_DECLARE ( GetTimers );
LUA_DECLARE ( IsTimer );
LUA_DECLARE ( GetTimer );
LUA_DECLARE ( GetTickCount_ );
LUA_DECLARE ( GetCTime );
LUA_DECLARE ( tocolor );
Expand Down
1 change: 1 addition & 0 deletions MTA10/mods/shared_logic/lua/CLuaManager.cpp
Expand Up @@ -760,6 +760,7 @@ void CLuaManager::LoadCFunctions ( void )
CLuaCFunctions::AddFunction ( "killTimer", CLuaFunctionDefs::KillTimer );
CLuaCFunctions::AddFunction ( "getTimers", CLuaFunctionDefs::GetTimers );
CLuaCFunctions::AddFunction ( "isTimer", CLuaFunctionDefs::IsTimer );
CLuaCFunctions::AddFunction ( "getTimer", CLuaFunctionDefs::GetTimer );
CLuaCFunctions::AddFunction ( "getTickCount", CLuaFunctionDefs::GetTickCount_ );
CLuaCFunctions::AddFunction ( "getRealTime", CLuaFunctionDefs::GetCTime );
CLuaCFunctions::AddFunction ( "tocolor", CLuaFunctionDefs::tocolor );
Expand Down
8 changes: 8 additions & 0 deletions MTA10/mods/shared_logic/lua/CLuaTimer.cpp
Expand Up @@ -48,3 +48,11 @@ void CLuaTimer::ExecuteTimer ( CLuaMain* pLuaMain )
if ( m_iLuaFunction != LUA_REFNIL && m_pArguments )
m_pArguments->Call ( pLuaMain, m_iLuaFunction );
}


unsigned long CLuaTimer::GetTimeLeft ( void )
{
unsigned long ulCurrentTime = timeGetTime ();
unsigned long ulTimeLeft = m_ulStartTime + m_ulDelay - ulCurrentTime;
return ulTimeLeft;
}
2 changes: 2 additions & 0 deletions MTA10/mods/shared_logic/lua/CLuaTimer.h
Expand Up @@ -46,6 +46,8 @@ class CLuaTimer

void ExecuteTimer ( class CLuaMain* pLuaMain );

unsigned long GetTimeLeft ( void );

inline bool IsBeingDeleted ( void ) { return m_bBeingDeleted; }
inline void SetBeingDeleted ( bool bBeingDeleted ) { m_bBeingDeleted = bBeingDeleted; }
private:
Expand Down
22 changes: 22 additions & 0 deletions MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefinitions.cpp
Expand Up @@ -9740,6 +9740,28 @@ int CLuaFunctionDefinitions::GetTimers ( lua_State* luaVM )
}


int CLuaFunctionDefinitions::GetTimer ( lua_State* luaVM )
{
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
if ( pLuaMain )
{
CLuaTimer* pLuaTimer = lua_totimer ( luaVM, 1 );
if ( pLuaTimer )
{
lua_pushnumber( luaVM, pLuaTimer->GetTimeLeft () );
lua_pushnumber( luaVM, pLuaTimer->GetRepeats () );
lua_pushnumber( luaVM, pLuaTimer->GetDelay () );
return 3;
}
else
m_pScriptDebugging->LogBadType ( luaVM, "getTimer" );
}

lua_pushboolean ( luaVM, false );
return 1;
}


int CLuaFunctionDefinitions::GetColorFromString ( lua_State* luaVM )
{
unsigned char ucColorRed, ucColorGreen, ucColorBlue, ucColorAlpha;
Expand Down
Expand Up @@ -420,6 +420,7 @@ class CLuaFunctionDefinitions
static int ResetTimer ( lua_State* luaVM );
static int GetTimers ( lua_State* luaVM );
static int IsTimer ( lua_State* luaVM );
static int GetTimer ( lua_State* luaVM );
static int GetColorFromString ( lua_State* luaVM );
static int Reference ( lua_State* luaVM );
static int Dereference ( lua_State* luaVM );
Expand Down
1 change: 1 addition & 0 deletions MTA10_Server/mods/deathmatch/logic/lua/CLuaManager.cpp
Expand Up @@ -588,6 +588,7 @@ void CLuaManager::LoadCFunctions ( void )
CLuaCFunctions::AddFunction ( "resetTimer", CLuaFunctionDefinitions::ResetTimer );
CLuaCFunctions::AddFunction ( "getTimers", CLuaFunctionDefinitions::GetTimers );
CLuaCFunctions::AddFunction ( "isTimer", CLuaFunctionDefinitions::IsTimer );
CLuaCFunctions::AddFunction ( "getTimer", CLuaFunctionDefinitions::GetTimer );
CLuaCFunctions::AddFunction ( "getColorFromString", CLuaFunctionDefinitions::GetColorFromString );
CLuaCFunctions::AddFunction ( "ref", CLuaFunctionDefinitions::Reference );
CLuaCFunctions::AddFunction ( "deref", CLuaFunctionDefinitions::Dereference );
Expand Down
8 changes: 8 additions & 0 deletions MTA10_Server/mods/deathmatch/logic/lua/CLuaTimer.cpp
Expand Up @@ -44,3 +44,11 @@ void CLuaTimer::ExecuteTimer ( CLuaMain* pLuaMain )
m_Arguments.Call ( pLuaMain, m_iLuaFunction );
}
}


unsigned long CLuaTimer::GetTimeLeft ( void )
{
unsigned long ulCurrentTime = GetTime ();
unsigned long ulTimeLeft = m_ulStartTime + m_ulDelay - ulCurrentTime;
return ulTimeLeft;
}
2 changes: 2 additions & 0 deletions MTA10_Server/mods/deathmatch/logic/lua/CLuaTimer.h
Expand Up @@ -46,6 +46,8 @@ class CLuaTimer

void ExecuteTimer ( class CLuaMain* pLuaMain );

unsigned long GetTimeLeft ( void );

inline bool IsBeingDeleted ( void ) { return m_bBeingDeleted; }
inline void SetBeingDeleted ( bool bBeingDeleted ) { m_bBeingDeleted = bBeingDeleted; }
private:
Expand Down

0 comments on commit 9a275fc

Please sign in to comment.