diff --git a/core/smn_core.cpp b/core/smn_core.cpp index bc7b342a..c37dbd95 100644 --- a/core/smn_core.cpp +++ b/core/smn_core.cpp @@ -11,6 +11,7 @@ * Version: $Id$ */ +#include #include "sm_globals.h" #include "sourcemod.h" @@ -28,8 +29,20 @@ static cell_t ThrowError(IPluginContext *pContext, const cell_t *params) return 0; } +static cell_t GetTime(IPluginContext *pContext, const cell_t *params) +{ + time_t t = time(NULL); + cell_t *addr; + pContext->LocalToPhysAddr(params[1], &addr); + + *(time_t *)addr = t; + + return static_cast(t); +} + REGISTER_NATIVES(coreNatives) { + {"GetTime", GetTime}, {"ThrowError", ThrowError}, {NULL, NULL}, }; diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index 4143dfb6..67cd32b8 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -146,6 +146,14 @@ native LogMessage(const String:format[], {Handle,Float,String,_}:...); */ native LogError(const String:format[], {Handle,Float,String,_}:...); +/** + * Gets the system time as a unix timestamp. + * + * @param bigStamp Optional array to store the 64bit timestamp in. + * @return 32bit timestamp (number of seconds since unix epoch). + */ +native GetTime(bigStamp[2]={0,0}); + /** * Sets the seed value for the global Half-Life 2 Random Stream *