AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved hook to specific timestamp (https://forums.alliedmods.net/showthread.php?t=320092)

Watermelonnable 12-04-2019 00:17

hook to specific timestamp
 
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.

redivcram 12-04-2019 08:05

Re: hook to specific timestamp
 
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.

Watermelonnable 12-04-2019 08:43

Re: hook to specific timestamp
 
Thank you, this is what I was looking for :)

Watermelonnable 12-04-2019 12:14

Re: hook to specific timestamp
 
Quote:

Originally Posted by redivcram (Post 2675629)
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;



OciXCrom 12-04-2019 15:47

Re: hook to specific timestamp
 
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")

Watermelonnable 12-04-2019 15:59

Re: hook to specific timestamp
 
Quote:

Originally Posted by OciXCrom (Post 2675706)
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

OciXCrom 12-04-2019 16:26

Re: hook to specific timestamp
 
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.

Watermelonnable 12-04-2019 18:15

Re: hook to specific timestamp
 
Quote:

Originally Posted by OciXCrom (Post 2675718)
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


All times are GMT -4. The time now is 02:42.

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