Hallo,
I want a ticker that calls a function every 5 minutes.
This is my Code.
Code:
function Initialize(Plugin)
  Plugin:SetName("MyPlugin")
  Plugin:SetVersion(1)
  local World = cRoot:Get():GetDefaultWorld()
  World:ScheduleTask(10, TaskFunction)
  return true
end
function TaskFunction(World)
  LOG(World:GetName())
end
But the Function TaskFunction is called only once.
Why this?
 
 
Code:
function Initialize(Plugin)
    Plugin:SetName("MyPlugin")
    Plugin:SetVersion(1)
    local World = cRoot:Get():GetDefaultWorld()
    Callback = function(World)
        LOG(World:GetName())
        World:ScheduleTask(6000, Callback)
    end
    World:ScheduleTask(10, Callback)
    return true
end
This should work, had the same problem 
Edit: Sorry misunderstood your question.
You can not directly, add a function as parameter.
 
 
The cWorld:ScheduleTask only schedules a function once. You have to reschedule it every time.
 
 (12-23-2014, 07:06 PM)STR_Warrior Wrote: [ -> ]The cWorld:ScheduleTask only schedules a function once. You have to reschedule it every time.
Well, i've only the Hook Option with HOOK_WORLD_TICK?
http://mc-server.xoft.cz/LuaAPI/OnWorldTick.html
Here my Example Code:
Code:
function Initialize(Plugin)
  Plugin:SetName("MyPlugin")
  Plugin:SetVersion(1)
  cPluginManager.AddHook(cPluginManager.HOOK_TICK, OnTick)
  return true
end
function TaskFunction(World)
  LOG(World:GetName())
end
function OnTick(Time)
  local World = cRoot:Get():GetDefaultWorld()
  World:ScheduleTask(10,
    function()
      LOG("Execute")
    end
  )
end
 
 
Or a Call the Function recursively.
Is that the best Option, realy?
Code:
function Initialize(Plugin)
  Plugin:SetName("MyPlugin")
  Plugin:SetVersion(1)
  local World = cRoot:Get():GetDefaultWorld()
  TaskFunction(World)
  return true
end
function TaskFunction(World)
  World:ScheduleTask(100, TaskFunction)
  LOG(World:GetName())
end
 
 
You can use the example by Seadragon91
function Initialize(Plugin)
    Plugin:SetName("MyPlugin")
    Plugin:SetVersion(1)
    local World = cRoot:Get():GetDefaultWorld()
    Callback = function(World)
        LOG(World:GetName())
        World:ScheduleTask(6000, Callback)
    end
    World:ScheduleTask(10, Callback)
    return true
end
You can reschedule it in the function itself.
 
 
Small problem here. Using a /reload will crash the server, if a scheduler task is started.
 
 (12-23-2014, 07:54 PM)Seadragon91 Wrote: [ -> ]Small problem here. Using a /reload will crash the server, if a scheduler task is started.
Right, the same problem I also have.
 
 
The Problem here is, if the plugin is reloaded, is still a Schedule Task open. I can't close the running Task before the Plugin is reloaded.
How can i solve this Problem?