Cuberite Forum
Need Help for hooks - 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: Need Help for hooks (/thread-3460.html)



Need Help for hooks - Dredd - 02-03-2025

Hi all, i have a problem. I don't understand how to do it right.
Need:
When opening the oven or chest, notice the movement of objects, and perform some actions before closing the window.
My code doesn't work because the hook doesn't have the necessary functions.
My code:

Init.lua contains:
PHP Code:
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_OPENING_WINDOWOnOpeningWindow

Hooks.lua contains:
PHP Code:
function OnOpeningWindow(PlayerWindow)
     local OnClicked = function(WindowClickingPlayerSlotNumClickActionClickedItem)
          LOG('Clicked')
          return true
     end
     Window
():SetOnClicked(OnClicked)
end 

I don't understand how to get a callback to track clicks or movements of objects in an open window.

if I open a new window unrelated to the chest or furnace block, then I can receive a callback.
It works, but the window is not attached to the chest block:
PHP Code:
local OnClicked = function(WindowClickingPlayerSlotNumClickActionClickedItem)
     LOG('Clicked')
end
local Window 
cLuaWindow(cWindow.wtChest33'TestChest')
Window:SetOnClicked(OnClicked)
Player:OpenWindow(Window

Hhow to transfer an object to cLuaWindow and whether it is necessary?