Raised This Month: $ Target: $400
 0% 

Solved hook to specific timestamp


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Watermelonnable
Member
Join Date: Feb 2017
Old 12-04-2019 , 00:17   hook to specific timestamp
Reply With Quote #1

Hello guys!

I want to hook to an specific timestamp per map and store a value to use in another timestamp. For example: When there are 5 minutes left in the map, I want to execute a vote and store the result. Then execute another function when there's 30 seconds of timeleft and use the previously stored value.

Can you give me some hints in the right direction to achieve this? Also plugins that works in similar ways can be helpful so I can read them.

Last edited by Watermelonnable; 12-04-2019 at 18:15.
Watermelonnable is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 12-04-2019 , 08:05   Re: hook to specific timestamp
Reply With Quote #2

First of all, this should be in Suggestions/Request.

You can run tasks in your plugin_init().
Something like:

Code:
set_task(get_timeleft() - 300.0, "Hook5MinutesRemaining");
For 5 minutes or
Code:
set_task(get_timeleft() - 30.0, "Hook30SecondsRemaining");
For 30 seconds.

Last edited by redivcram; 12-04-2019 at 08:05.
redivcram is offline
Watermelonnable
Member
Join Date: Feb 2017
Old 12-04-2019 , 08:43   Re: hook to specific timestamp
Reply With Quote #3

Thank you, this is what I was looking for
Watermelonnable is offline
Watermelonnable
Member
Join Date: Feb 2017
Old 12-04-2019 , 12:14   Re: hook to specific timestamp
Reply With Quote #4

Quote:
Originally Posted by redivcram View Post
First of all, this should be in Suggestions/Request.

You can run tasks in your plugin_init().
Something like:

Code:
set_task(get_timeleft() - 300.0, "Hook5MinutesRemaining");
For 5 minutes or
Code:
set_task(get_timeleft() - 30.0, "Hook30SecondsRemaining");
For 30 seconds.
Hey man, for some reason the function gets executed right after I start the server. Any idea of why? This is how I registered it in the plugin_ini block:

PHP Code:
set_task(get_timeleft() - 30.0"DoMagic"
EDIT:

I added an extra check in my function but I think this shouldn't be the normal process.
PHP Code:
if ((get_timeleft() - 30.0) > 50.0) {
    return 
PLUGIN_HANDLED;


Last edited by Watermelonnable; 12-04-2019 at 13:43.
Watermelonnable is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-04-2019 , 15:47   Re: hook to specific timestamp
Reply With Quote #5

The "set_task" function has a flag that allows it to count the time until the end of the map:

Quote:
Optional set of flags:
"a" - repeat timer a set amount of times
"b" - loop indefinitely until timer is stopped
"c" - time interval is treated as absolute time after
map start
"d" - time interval is treated as absolute time before
map change
So, instead of using maths, you can do:

Code:
set_task(300.0, "Hook5MinutesRemaining", .flags = "d")
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Watermelonnable
Member
Join Date: Feb 2017
Old 12-04-2019 , 15:59   Re: hook to specific timestamp
Reply With Quote #6

Quote:
Originally Posted by OciXCrom View Post
The "set_task" function has a flag that allows it to count the time until the end of the map:



So, instead of using maths, you can do:

Code:
set_task(300.0, "Hook5MinutesRemaining", .flags = "d")
Thank you. I will try this and let you know the results.

For the meantime I did some debugging and came across that
PHP Code:
get_timeleft() 
and also

PHP Code:
 get_pcvar_num(get_cvar_pointer("mp_timelimit")) 
returns 0 if I try to assign those values inside plugin_init. Can you please tell me why?

EDIT: Your solution worked like a charm Thank you again

Last edited by Watermelonnable; 12-04-2019 at 16:05.
Watermelonnable is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-04-2019 , 16:26   Re: hook to specific timestamp
Reply With Quote #7

You should get cvar values inside "plugin_cfg" instead of "plugin_init". This is when all the config files have been read and the values have been updated.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Watermelonnable
Member
Join Date: Feb 2017
Old 12-04-2019 , 18:15   Re: hook to specific timestamp
Reply With Quote #8

Quote:
Originally Posted by OciXCrom View Post
You should get cvar values inside "plugin_cfg" instead of "plugin_init". This is when all the config files have been read and the values have been updated.
Yeah I tried that too before but still got 0 values
Watermelonnable 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 11:32.


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