2010-03-30 13:33:21 +00:00
|
|
|
/*--
|
2010-03-30 17:16:26 +00:00
|
|
|
Schedule.c
|
2010-03-30 13:33:21 +00:00
|
|
|
Authors:
|
|
|
|
|
2010-09-13 15:27:48 +00:00
|
|
|
Schedule can be used to execute scripts or functions repetitively with delay.
|
2010-03-30 13:33:21 +00:00
|
|
|
--*/
|
2010-02-18 23:49:27 +00:00
|
|
|
|
2010-03-30 13:33:21 +00:00
|
|
|
// Executes a script repetitively with delay.
|
2011-07-31 17:27:26 +00:00
|
|
|
global func Schedule(object obj, string script, int interval, int repeats)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-03-30 13:33:21 +00:00
|
|
|
// Defaults.
|
2010-09-13 15:27:48 +00:00
|
|
|
if (!repeats)
|
2010-03-30 13:33:21 +00:00
|
|
|
repeats = 1;
|
|
|
|
// Create effect.
|
|
|
|
var effect = AddEffect("IntSchedule", obj, 1, interval, obj);
|
2010-12-21 00:40:40 +00:00
|
|
|
if (!effect)
|
2010-03-30 13:33:21 +00:00
|
|
|
return false;
|
|
|
|
// Set variables.
|
2012-05-05 10:09:44 +00:00
|
|
|
effect.Script = script;
|
|
|
|
effect.Repeats = repeats;
|
2010-03-30 13:33:21 +00:00
|
|
|
return true;
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2012-05-05 10:09:44 +00:00
|
|
|
global func FxIntScheduleTimer(object obj, proplist effect)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-03-30 13:33:21 +00:00
|
|
|
// Just a specific number of repeats.
|
2012-05-05 10:09:44 +00:00
|
|
|
var done = --effect.Repeats <= 0;
|
2010-03-30 13:33:21 +00:00
|
|
|
// Execute.
|
2012-05-05 10:09:44 +00:00
|
|
|
eval(effect.Script);
|
|
|
|
// Remove schedule if done.
|
|
|
|
if (done)
|
|
|
|
return FX_Execute_Kill;
|
|
|
|
return FX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds a timed call to an object, replacement of DefCore TimerCall.
|
2012-06-05 20:51:09 +00:00
|
|
|
global func AddTimer(
|
|
|
|
string function /* function that will be called every time step */
|
|
|
|
, int interval /* interval in frames in which the function will be called */)
|
2012-05-05 10:09:44 +00:00
|
|
|
{
|
2012-06-05 20:51:09 +00:00
|
|
|
/*
|
|
|
|
// script for a mine that checks for enemies every second
|
|
|
|
func Initialize()
|
|
|
|
{
|
|
|
|
AddTimer("CheckForEnemies", 36);
|
|
|
|
}
|
|
|
|
|
|
|
|
func CheckForEnemies()
|
|
|
|
{
|
|
|
|
if(FindObject(Find_AtPoint(), Find_OCF(OCF_Alive)))
|
|
|
|
Explode(30);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2012-05-05 10:09:44 +00:00
|
|
|
if (!this)
|
|
|
|
return false;
|
|
|
|
// Default to one second.
|
|
|
|
if (interval == nil)
|
|
|
|
interval = 36;
|
|
|
|
// Create effect and add function and repeat infinitely.
|
|
|
|
var effect = AddEffect("IntScheduleCall", this, 1, interval, this);
|
|
|
|
effect.Function = function;
|
|
|
|
effect.NoStop = true;
|
|
|
|
effect.Pars = [];
|
|
|
|
return true;
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2010-03-30 13:33:21 +00:00
|
|
|
// Executes a function repetitively with delay.
|
|
|
|
global func ScheduleCall(object obj, string function, int interval, int repeats, par0, par1, par2, par3, par4)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-03-30 13:33:21 +00:00
|
|
|
// Defaults.
|
2010-09-13 15:27:48 +00:00
|
|
|
if (!repeats)
|
2010-03-30 13:33:21 +00:00
|
|
|
repeats = 1;
|
|
|
|
// Create effect.
|
|
|
|
var effect = AddEffect("IntScheduleCall", obj, 1, interval, obj);
|
2010-12-21 00:40:40 +00:00
|
|
|
if (!effect)
|
2010-03-30 13:33:21 +00:00
|
|
|
return false;
|
|
|
|
// Set variables.
|
2012-05-05 10:09:44 +00:00
|
|
|
effect.Function = function;
|
|
|
|
effect.Repeats = repeats;
|
|
|
|
effect.Pars = [par0, par1, par2, par3, par4];
|
2010-03-30 13:33:21 +00:00
|
|
|
return true;
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2012-05-05 10:09:44 +00:00
|
|
|
global func FxIntScheduleCallTimer(object obj, proplist effect)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-03-30 13:33:21 +00:00
|
|
|
// Just a specific number of repeats.
|
2012-05-05 10:09:44 +00:00
|
|
|
var done = --effect.Repeats <= 0;
|
2010-03-30 13:33:21 +00:00
|
|
|
// Execute.
|
2012-05-05 10:09:44 +00:00
|
|
|
Call(effect.Function, effect.Pars[0], effect.Pars[1], effect.Pars[2], effect.Pars[3], effect.Pars[4]);
|
|
|
|
// Remove schedule call if done, take into account infinite schedules.
|
|
|
|
if (done && !effect.NoStop)
|
|
|
|
return FX_Execute_Kill;
|
|
|
|
return FX_OK;
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2010-03-30 13:33:21 +00:00
|
|
|
global func ClearScheduleCall(object obj, string function)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-03-30 13:33:21 +00:00
|
|
|
var i, effect;
|
|
|
|
// Count downwards from effectnumber, to remove effects.
|
|
|
|
i = GetEffectCount("IntScheduleCall", obj);
|
|
|
|
while (i--)
|
|
|
|
// Check All ScheduleCall-Effects.
|
|
|
|
if (effect = GetEffect("IntScheduleCall", obj, i))
|
|
|
|
// Found right function.
|
2012-05-11 15:31:47 +00:00
|
|
|
if (effect.Function == function)
|
2010-03-30 13:33:21 +00:00
|
|
|
// Remove effect.
|
2012-04-12 09:48:23 +00:00
|
|
|
RemoveEffect(nil, obj, effect);
|
2010-03-30 13:33:21 +00:00
|
|
|
return;
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|