Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: vcmptr on Mar 13, 2015, 06:03 PM

Title: Scheduled Tasks
Post by: vcmptr on Mar 13, 2015, 06:03 PM
I'm trying to create scheduled tasks. 
function tasks()
{
NewTimer("tasks",60000,1);
local now = date()
if(now.hour.tointeger() == 00)
{
SetWeather( 7 );
}
if(now.hour.tointeger() == 06)
{
OffCarLights();
}
if(now.hour.tointeger() == 18)
{
SetWeather( 5 );
}
if(now.hour.tointeger() == 20)
{
OpenCarLights();
}

}

But its not useful.  Example I can't schedule task from week to week. How can I make like Cron Job?
Title: Re: Scheduled Tasks
Post by: Sebastian on Mar 14, 2015, 06:51 PM
I really don't understand what you mean, but I have a suggestion: learn to use switch function, instead of 9999 x if !

You should understand the difference by reading this:
Quote from: shadow.heekzLet's say there are 60 boxes, and an object, hidden in one of them.
If you will use "if" variant, will be like you are searching in every box until you find the object. (lot of effort and lost time)
But if you will use "switch" variant, will be like you know where is the object, and gonna search in the correct box. (much faster)

Also, here is an example:

switch( hour )
{
          case 0:
                    SetWeather( 7 );
                    break;
          case 6:
                    OffCarLights( );
                    break;
          case 18:
                    SetWeather( 5 );
                    break;
          default: break;
}
Title: Re: Scheduled Tasks
Post by: vcmptr on Mar 14, 2015, 07:26 PM
My fucking English... Thanks for the suggestion.
Title: Re: Scheduled Tasks
Post by: aXXo on Mar 15, 2015, 10:28 AM
I believe you are trying to create an automatic system where a task is called on a weekly basis. The struggle is, that creating a timer is not feasible, because unfortunately our servers don't stay online for a week consistently.

Or maybe, you are trying to assign specific tasks to each day of the week. But even though the scripts can tell you the date, it can not detect(?) if the day is a Sunday or a Monday.
Title: Re: Scheduled Tasks
Post by: vcmptr on Mar 15, 2015, 11:18 AM
Quote from: aXXo on Mar 15, 2015, 10:28 AMI believe you are trying to create an automatic system where a task is called on a weekly basis. The struggle is, that creating a timer is not feasible, because unfortunately our servers don't stay online for a week consistently.

Or maybe, you are trying to assign specific tasks to each day of the week. But even though the scripts can tell you the date, it can not detect(?) if the day is a Sunday or a Monday.
Nice idea! Date function giving with index "wday". Thanks. :)