diff --git a/core/smn_core.cpp b/core/smn_core.cpp index df817a92..777267d0 100644 --- a/core/smn_core.cpp +++ b/core/smn_core.cpp @@ -83,6 +83,18 @@ static cell_t GetTime(IPluginContext *pContext, const cell_t *params) return static_cast(t); } +static cell_t FormatTime(IPluginContext *pContext, const cell_t *params) +{ + char *format, *buffer; + pContext->LocalToString(params[1], &buffer); + pContext->LocalToString(params[3], &format); + + time_t t = time(NULL); + strftime(buffer, params[2], format, localtime(&t)); + + return 1; +} + static cell_t GetPluginIterator(IPluginContext *pContext, const cell_t *params) { IPluginIterator *iter = g_PluginSys.GetPluginIterator(); @@ -332,5 +344,6 @@ REGISTER_NATIVES(coreNatives) {"ReadPlugin", ReadPlugin}, {"ThrowError", ThrowError}, {"SetFailState", SetFailState}, + {"FormatTime", FormatTime}, {NULL, NULL}, }; diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index dc6b351d..fdd337a5 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -264,6 +264,16 @@ native LogError(const String:format[], any:...); */ native GetTime(bigStamp[2]={0,0}); +/** + * Format date and time. + * + * @param buffer Destination string buffer. + * @param maxlength Maximum length of output string buffer. + * @param format Formatting rules. + * @noreturn + */ +native FormatTime(String:buffer[], maxlength, const String:format[]); + /** * Loads a game config file. *