Cuberite Forum
Placing blocks in lua - 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: Placing blocks in lua (/thread-2907.html)

Pages: 1 2


Placing blocks in lua - yoboykai - 02-25-2017

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?


RE: Placing blocks in lua - Seadragon91 - 02-25-2017

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


RE: Placing blocks in lua - yoboykai - 02-25-2017

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.


RE: Placing blocks in lua - Seadragon91 - 02-25-2017

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.


RE: Placing blocks in lua - yoboykai - 02-26-2017

If you could it would be much appreciated.


RE: Placing blocks in lua - Seadragon91 - 02-27-2017

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.


RE: Placing blocks in lua - yoboykai - 02-28-2017

Thank you, this clears so much up for me.


RE: Placing blocks in lua - yoboykai - 03-12-2017

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?


RE: Placing blocks in lua - NiLSPACE - 03-12-2017

Do you know the area where you want to replace the blocks?


RE: Placing blocks in lua - yoboykai - 03-13-2017

Yes, but there will be multiple separate areas and new areas being added.