Cuberite Forum
Countdown - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: Countdown (/thread-1314.html)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13


Countdown - daniel0916 - 01-13-2014

How can i make a countdown or something else like Bukkit Scheduler?
Give it a method for that? I need it for a minigame.


RE: Countdown - NiLSPACE - 01-13-2014

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



RE: Countdown - daniel0916 - 01-13-2014

(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?


RE: Countdown - NiLSPACE - 01-13-2014

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.


RE: Countdown - xoft - 01-13-2014

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.


RE: Countdown - NiLSPACE - 01-13-2014

I created that plugin before the OnWorldTick hook existed Wink


RE: Countdown - daniel0916 - 01-13-2014

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?


RE: Countdown - NiLSPACE - 01-13-2014

(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.


RE: Countdown - daniel0916 - 01-13-2014

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.


RE: Countdown - xoft - 01-13-2014

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.