Quote:
Originally Posted by Hunter-Digital
Hmm, wow.
Anyway, I was searching for a function that accepts string input and outputs timestamps, and I've found it, parse_time() with get_systime() should greatly help.
|
Nice find Hunter-Digital. I was going to use my unixtime include to calculate the timestamp, good to know I can use parse_time() instead in the future. In your code for the set_task() interval you could just do float( time ) instead of 0.0 + time.
In addition to what Hunter did, here's additional code that will determine if the task time will happen within the current map and if so create a thinking entity to think\execute at the time.
PHP Code:
#include <amxmodx>
#include <engine>
// use what values you don't want to be dynamic, for example if you want years to not matter, don't enter year.
new const g_szTimeFormat[] = "%H:%M:%S" // all possible values: "%H:%M:%S %d/%m/%Y"
new const g_szTimeInput[] = "21:56:00" // example with all values: "09:16:02 24/06/2011"
new g_TaskEntity;
public plugin_init()
{
new iTaskTime = ( parse_time( g_szTimeInput , g_szTimeFormat ) - get_systime() );
if ( ( iTaskTime > 0 ) && ( ( iTaskTime / 60 ) < get_cvar_num( "mp_timelimit" ) ) )
{
server_print( "Task will execute in %d seconds" , iTaskTime );
g_TaskEntity = create_entity( "info_target" );
entity_set_string( g_TaskEntity , EV_SZ_classname , "task_entity" );
register_think( "task_entity" , "Task_EntityThink" );
entity_set_float( g_TaskEntity , EV_FL_nextthink , get_gametime() + float( iTaskTime ) );
}
else
{
server_print( "The task time will not occur during current map." );
}
}
public Task_EntityThink( iEntity )
{
if ( iEntity == g_TaskEntity )
{
//Do stuff
entity_set_int( g_TaskEntity , EV_INT_flags , FL_KILLME );
call_think( g_TaskEntity );
}
}
__________________