AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with time (https://forums.alliedmods.net/showthread.php?t=232378)

PyKw 12-29-2013 17:22

Help with time
 
Hi, so i want a plugin that when its 20:00 a message is send to all connected players.
I tried this but not working...
Code:

#include <amxmodx>

public plugin_init()
{
        register_plugin("On Time", "1.0", "PyKw")
}

public check_time()
{
        new h, m, s;
        time(h, m, s)
        if(h == 20)
                client_print(0, print_chat, "Its 20:00")
}

Please help!

Torge 12-29-2013 17:34

Re: Help with time
 
Try to let the time get checked every 1 second.

PyKw 12-29-2013 17:45

Re: Help with time
 
Like this ?

Code:

#include <amxmodx>

public plugin_init()
{
        register_plugin("On Time", "1.0", "PyKw")
        set_task(0.1, "check_time", _, _, _, "b")
}

public check_time()
{
        new h, m, s;
        time(h, m, s)
        if(h == 20)
                client_print(0, print_chat, "Its 20:00")
}


Torge 12-29-2013 17:52

Re: Help with time
 
Yeah, did u test it and it worked?

PyKw 12-29-2013 18:13

Re: Help with time
 
It is working, but the task is repeating, and i am getting spammed with:
Code:

Its 20:00
Its 20:00
Its 20:00
Its 20:00
Its 20:00
Its 20:00
Its 20:00
Its 20:00
Its 20:00


Torge 12-29-2013 18:17

Re: Help with time
 
Stop the task and try to re-start it again at another time.

PyKw 12-29-2013 18:20

Re: Help with time
 
How i do that?

fysiks 12-29-2013 18:39

Re: Help with time
 
Quote:

Originally Posted by PyKw (Post 2078192)
It is working, but the task is repeating, and i am getting spammed with:
Code:

Its 20:00
Its 20:00
Its 20:00
Its 20:00
Its 20:00
Its 20:00
Its 20:00
Its 20:00
Its 20:00


You are executing the function 10 times per second. Also, if you only check "h" it will print every time the function executes during that whole hour.

I think one option would be to execute the function every minute and check both h == 20 and m == 0.

PyKw 12-29-2013 18:51

Re: Help with time
 
Thanks, i solved. You can close this topic.

Black Rose 12-31-2013 06:57

Re: Help with time
 
Just pause the plugin or remove the task when it's done.
Efficient.

Here's another function you can use though i'm planning on improving it.
Code:
/*  set_timetask (const Hour, const Minute, const Second, const function[], id = 0, const parameter[] = "", len = 0) * Creates a task to execute function at given time. * Does not repeat. */ stock set_timetask(const Hour, const Minute, const Second, const function[], id = 0, const parameter[] = "", len = 0) {         new curHour, curMinute, curSecond;     time(curHour, curMinute, curSecond);     new curTime = curHour * 3600 + curMinute * 60 + curSecond;     new goalTime = Hour * 3600 + Minute * 60 + Second;         new taskTime = goalTime - curTime;         if ( taskTime < 0 )         taskTime += 86400; // Tomorrow         return set_task(1.0 * taskTime, function, id, parameter, len); }


All times are GMT -4. The time now is 10:07.

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