Cuberite Forum

Full Version: Placing blocks in lua
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I'm new to lua, and I was wondering if there was any way to place a specific block in a specific place after the block previously in that place was broken?
A plugin can be written to do that.

There is a hook named HOOK_PLAYER_BROKEN_BLOCK with that you can detect what block and where it has been broken. Then you can place a new one immediately or after a specific time.
That should be easy, if you have any problems / questions just ask  Smile
I'm still a little confused about hoe to place a block with lua, as I said I'm very new to lua and developing plugins.
The function that will be called for the hook, contains the param Player. With it you can get the world the player is in:

Code:
Player:GetWorld():SetBlock(Player:GetPosX(), Player:GetPosY(), Player:GetPosZ(), E_BLOCK_CAKE, 0)

API:
Player
World
World:SetBlock()
E_BLOCK_CAKE

If you want I could write a example plugin, that would place a block if a player breaks a block.
If you could it would be much appreciated.
1) Create a folder named PlaceBlocks inside of folder Plugins
2) Save the content into the file PlaceBlocks.lua
3) Add the plugin name to the section Plugins in settings.ini

Code:
function Initialize(a_Plugin)
    a_Plugin:SetName( "PlaceBlocks" )
    a_Plugin:SetVersion( 1 )
    
    cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_BROKEN_BLOCK, OnPlayerBrokenBlock)
    
    return true
end

function OnPlayerBrokenBlock(Player, BlockX, BlockY, BlockZ, BlockFace, BlockType, BlockMeta)
    if BlockType == E_BLOCK_GRASS then
        Player:GetWorld():SetBlock(BlockX, BlockY, BlockZ, E_BLOCK_STONE, 0)
    end
end
This plugin example replaces the grass blocks that the player breaks with an stone block.
Thank you, this clears so much up for me.
Sorry if i'm annoying you but, how would I change all blocks of stone for example to a different block after a set amount of time, and repeatedly to this?
Do you know the area where you want to replace the blocks?
Yes, but there will be multiple separate areas and new areas being added.
Pages: 1 2