Raised This Month: $ Target: $400
 0% 

Doing something on specific date-time


Post New Thread Reply   
 
Thread Tools Display Modes
tuty
Veteran Member
Join Date: Jul 2008
Location: UK
Old 09-22-2011 , 17:46   Re: Doing something on specific date-time
Reply With Quote #11

Quote:
Originally Posted by hleV View Post
Hunter-Digital's way (even if not displayed in a code) is obviously better than yours. Instead of saying "use whatever you like" you should advise the guy to use the better way, and instead of requesting the guy with better idea to create a code, do it yourself if you feel like it's needed (and as it turns out, it's not). Unless, of couse, you don't realize which way is better, in which case you probably shouldn't be helping people at all, since in this case it's pretty obvious.

Not trying to sound rude here, but if you intend to help, then help.

that part with understanding wich way is better... i dont give a shit..i just helped the guy and you all started to flame...
jesus christ what's wrong with you guys?...
__________________
tuty is offline
Send a message via ICQ to tuty Send a message via AIM to tuty
Erox902
Veteran Member
Join Date: Jun 2009
Location: Never Never Land
Old 09-22-2011 , 18:08   Re: Doing something on specific date-time
Reply With Quote #12

Quote:
Originally Posted by tuty View Post
that part with understanding wich way is better... i dont give a shit..i just helped the guy and you all started to flame...
jesus christ what's wrong with you guys?...
We did not flame you in anyway! Hunter just said that there is a much better way to do it and then you got pissed of on him since he did'nt post the code.
And he should'nt!

Quote:
Originally Posted by hleV View Post
Hunter-Digital's way (even if not displayed in a code) is obviously better than yours. Instead of saying "use whatever you like" you should advise the guy to use the better way, and instead of requesting the guy with better idea to create a code, do it yourself if you feel like it's needed (and as it turns out, it's not). Unless, of couse, you don't realize which way is better, in which case you probably shouldn't be helping people at all, since in this case it's pretty obvious.

Not trying to sound rude here, but if you intend to help, then help.
Read!

Quote:
Originally Posted by tuty View Post
are you fucking retarded? i know how to do it and i dont want this fricking code...i didnt requested this just read my fucking posts. if my code can help you i'm glad, if not gtfo :/ im too lazy to create his code for someone who need this...
You are the one flaming!

Last edited by Erox902; 09-22-2011 at 18:14.
Erox902 is offline
tuty
Veteran Member
Join Date: Jul 2008
Location: UK
Old 09-22-2011 , 19:40   Re: Doing something on specific date-time
Reply With Quote #13

i apologize if i helped that guy, i shouldn't post it ..cuz there are o lot of "god's" here who know better.... and dude, get a life
__________________
tuty is offline
Send a message via ICQ to tuty Send a message via AIM to tuty
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 09-22-2011 , 20:44   Re: Doing something on specific date-time
Reply With Quote #14

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.

EDIT:
The tiny code I briefly tested with:
Code:
#include <amxmodx>

// 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[] = "15:00:00" // example with all values: "09:16:02 24/06/2011"

public plugin_init()
{
	new time = (parse_time(g_szTimeInput, g_szTimeFormat) - get_systime())

	server_print("[debug] time until event: %d seconds", time)

	if(time > 0)
		set_task(0.0 + time, "targetTime")
}

public targetTime()
{
	server_print("[debug] it's time !")
}
__________________

Last edited by Hunter-Digital; 09-22-2011 at 20:55.
Hunter-Digital is offline
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 #15

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
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 09-22-2011 , 22:55   Re: Doing something on specific date-time
Reply With Quote #16

Is there a reason for creating an entity ? For this trivial thing set_task() is enough

Also, mp_timelimit could verry likely change during the game and it could also be 0, so I dunno if that prediction could help or hurt :}

A possibly needed thing would be to check against changelevel delays... a task could fail if the level changes right before the task should occur and init the plugin right after it should've occured, then it's just ommited.
__________________

Last edited by Hunter-Digital; 09-22-2011 at 23:03.
Hunter-Digital is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-22-2011 , 23:28   Re: Doing something on specific date-time
Reply With Quote #17

Quote:
Originally Posted by Hunter-Digital View Post
Is there a reason for creating an entity ? For this trivial thing set_task() is enough
It may seem like overkill to create a thinking entity versus just using set_task(). But I was thinking that if the task is not going to be called for 30-45 minutes, the CPU will be checking every cycle to see if its time to execute the task; creating an entity and setting nextthink to task time and be done with it seems like a cheaper approach. Will a difference be noticed using either, probably not, but IMO it is the proper\efficient way.

Quote:
Originally Posted by Hunter-Digital View Post
Also, mp_timelimit could verry likely change during the game and it could also be 0, so I dunno if that prediction could help or hurt :}

A possibly needed thing would be to check against changelevel delays... a task could fail if the level changes right before the task should occur and init the plugin right after it should've occured, then it's just ommited.
There are a lot of "what ifs?" that can be thrown into just about any situation\condition in a plugin. What I put together is just a rough skeleton of how to execute a task at a particular time, the end-scripter can put in all of the checks.
__________________

Last edited by Bugsy; 09-22-2011 at 23:49.
Bugsy is online now
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 09-23-2011 , 04:19   Re: Doing something on specific date-time
Reply With Quote #18

It's fine to use an entity too, but I guess I would remove the time limit check, so if the map got extended, the entity would later do think after all.

Also a new task/think should be set on callback.
__________________

Last edited by hleV; 09-23-2011 at 04:24.
hleV is offline
Reply



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