Raised This Month: $ Target: $400
 0% 

Doing something on specific date-time


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-22-2011 , 21:43   Re: Doing something on specific date-time
Reply With Quote #7

Quote:
Originally Posted by Hunter-Digital View Post
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_timeg_szTimeInput g_szTimeFormat ) - get_systime() );

    if ( ( 
iTaskTime ) && ( ( iTaskTime 60 ) < get_cvar_num"mp_timelimit" ) ) )
    {
        
server_print"Task will execute in %d seconds" iTaskTime );
        
        
g_TaskEntity create_entity"info_target" );
        
entity_set_stringg_TaskEntity EV_SZ_classname "task_entity" );
        
register_think"task_entity" "Task_EntityThink" );
        
        
entity_set_floatg_TaskEntity EV_FL_nextthink get_gametime() + floatiTaskTime ) );
    }
    else
    {
        
server_print"The task time will not occur during current map." );
    }
}

public 
Task_EntityThinkiEntity )
{
    if ( 
iEntity == g_TaskEntity )
    {
        
//Do stuff

        
entity_set_intg_TaskEntity EV_INT_flags FL_KILLME );
        
call_thinkg_TaskEntity );
    }

__________________
Bugsy is online now
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode