Countdown
#1
How can i make a countdown or something else like Bukkit Scheduler?
Give it a method for that? I need it for a minigame.
Reply
Thanks given by:
#2
What do you want to schedule? If you want to set a block after some ticks you can use QueueSetBlock. If you want to schedule a function... You can't Sad sorry. We do have an issue on github for it: https://github.com/mc-server/MCServer/issues/150

I did once create a plugin that counted down using OnTick and then execute it. You could maybe use the code from that:
Table = {}

function Initialize(Plugin)
	PLUGIN = Plugin
	Plugin:SetName("Scheduler")
	Plugin:SetVersion(1)
	
	cPluginManager.AddHook(cPluginManager.HOOK_TICK, OnTick)
	
	return true
end

function Add(Function, Parameters, Ticks)
  table.insert(Table, {Function, Parameters, Ticks})
end

function OnTick(Time)
	for I=1, #Table do
		if Table[I][4] < 0 then
			Table[I][2](Table[I][3])
			table.remove(Table, I)
		else
			Table[I][4] = Table[I][4] - 1
		end
	end
end
Reply
Thanks given by:
#3
(01-13-2014, 12:37 AM)STR_Warrior Wrote: What do you want to schedule? If you want to set a block after some ticks you can use QueueSetBlock. If you want to schedule a function... You can't Sad sorry. We do have an issue on github for it: https://github.com/mc-server/MCServer/issues/150

I did once create a plugin that counted down using OnTick and then execute it. You could maybe use the code from that:
Table = {}

function Initialize(Plugin)
	PLUGIN = Plugin
	Plugin:SetName("Scheduler")
	Plugin:SetVersion(1)
	
	cPluginManager.AddHook(cPluginManager.HOOK_TICK, OnTick)
	
	return true
end

function Add(Function, Parameters, Ticks)
  table.insert(Table, {Function, Parameters, Ticks})
end

function OnTick(Time)
	for I=1, #Table do
		if Table[I][4] < 0 then
			Table[I][2](Table[I][3])
			table.remove(Table, I)
		else
			Table[I][4] = Table[I][4] - 1
		end
	end
end

Thanks. What do you mean with Parameters?
Ticks is 20 * seconds as always?
Reply
Thanks given by:
#4
Parameters is a table with all you parameters. For example I want to queue an function that needs block coordinates:
-- The function that you want to queue.
-- It simple prints all coordinates.
function MyFunction(Params)
 -- Do something awesome with the coordinates.
end

-- Add the function in the queue
BlockX = -50
BlockY = 128
BlockZ = 324
Add(MyFunction, {BlockX, BlockY, BlockZ}, 500)
-- The function now gets called in 500 ticks.

BUT Because it uses tables to store all the parameters you have to put this code directly in your plugin. You can't use Inter-plugin communication to make the scheduler an 2th plugin.

Yes I think 20 * ticks is seconds.
Reply
Thanks given by:
#5
Actually you should schedule tasks for a specific world, and use the OnWorldTick() function to tick only those scheduled tasks that match the currently ticked world.
Reply
Thanks given by:
#6
I created that plugin before the OnWorldTick hook existed Wink
Reply
Thanks given by:
#7
Thanks currently i'm working on the hooks..

But i think MCServer hasn't an id for fire or cake. Is this right? How can i block placing of fire or cakes?
And how can i block smelting from ice blocks?
Reply
Thanks given by:
#8
(01-13-2014, 02:18 AM)daniel0916 Wrote: But i think MCServer hasn't an id for fire or cake. Is this right? How can i block placing of fire or cakes?
Use the OnRightClick hook. You can use E_BLOCK_FIRE for fire and E_BLOCK_CAKE for cake.
daniel0916 Wrote:And how can i block smelting from ice blocks?
You can't but don't worry ice and snow smelting isn't implemented yet.
Reply
Thanks given by:
#9
Give it more blocks who haven't a id? I need to block all blocks from griefing..

And give it a hook who will be called when a player lose food?

And how can i block that a block will be broken when it burns and fire spreading?

Sorry for the many questions but now i'm working for a minigame on MCServer.
Reply
Thanks given by:
#10
You know, you don't need to quote everything when it's right above your post, the forum then becomes a chaos of quotes inside quotes inside quotes. Consider this a conversation, and only quote if you want to react to something very specific and older in the conversation.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)