Placing blocks in lua
#11
Then you probably want something like this:
-- g_Areas - An array containing cuboid objects. We assume all cuboids have their coordinates sorted.
-- world - The cWorld object where all modifications will be taking place
-- g_CoolDownPeriodTicks - The amount of ticks before the areas should be replaced again.

function ReplaceAllBlocks()
	-- Assuming area is a cCuboid
	for idx, area in ipairs(g_Areas) do
		local blockArea = cBlockArea();
		blockArea:Read(world, area);
		local sizeX, sizeY, sizeZ = blockArea:GetCoordRange()
		for relX = 0, sizeX do
			for relY = 0, sizeY do
				for relZ = 0, sizeZ do
					if (blockArea:GetRelBlockType(relX, relY, relZ) == E_BLOCK_STONE) then
						blockArea:SetRelBlockType(relX, relY, relZ, E_BLOCK_DIRT)
					end
				end
			end
		end
		blockArea:Write(world, area.p1)
	end
	world:ScheduleTask(g_CoolDownPeriodTicks, world)
end

You can add new areas by putting them into g_Areas. Currently only one world is used, but it shouldn't be hard to make this work for multiple worlds.
Reply
Thanks given by: yoboykai
#12
Thank you, I will try this out.
Reply
Thanks given by:
#13
Could it be your trying to make a auto reset mine ?
I seen it on some server, there are some ore's that give you the ore, or currency
Once you mine it, it turns to stone, then after a bit it turns back to the ore it was before.
MCServer: infinity.thugie.nl:25566 - Online when possible, not when crashed or updating lol.
Reply
Thanks given by:
#14
(03-13-2017, 08:22 AM)ThuGie Wrote: Could it be your trying to make a auto reset mine ?
I seen it on some server, there are some ore's that give you the ore, or currency
Once you mine it, it turns to stone, then after a bit it turns back to the ore it was before.

That's exactly what i'm trying to do.
Reply
Thanks given by:
#15
Such a plugin will be a bit more difficult than it seems at first.

You'll need to store the list of all blocks that will need converting back to ore - most likely in a SQLite database. And for the conversion from stone to ore, you'll need to make use of ChunkStay, which is an advanced technique (basically, you need to force the server to load a chunk if it is not loaded). You will need to use the per-world task scheduler. The plugin will need to do some processing when it's loaded - in case the server is restarted while some ores are in their "stone" state, you'll need to re-schedule their conversion back to ore.

SQLite in Cuberite: https://api.cuberite.org/sqlite3.html
ChunkStay: https://api.cuberite.org/cWorld.html#ChunkStay_1
Task scheduling: https://api.cuberite.org/cWorld.html#ScheduleTask_1

Basic workflow:
Add a player-block-break handler that:
- places stone right after a player digs an ore block
- stores into the database the world, block coords, ore type and tick when the block should be converted back to ore
- schedules a task on the world to turn the block back to ore
The scheduled task should:
- look in the database for all blocks that are due for conversion back to ore
- use ChunkStay to load the chunks and convert back to ore (as long as the block there is still stone (?))
- delete all blocks that it has processed from the database
Upon loading, the plugin should:
- inspect the database for any blocks that should already be converted, process them (like the Scheduled task)
- schedule tasks on each world for all blocks' conversions left in the database
Reply
Thanks given by: yoboykai




Users browsing this thread: 1 Guest(s)