LuaWindow
MCServer needs a class open for lua that allows them to create custom windows. For example if you use a command that it will open a window with 9 slots or something. This is the idea i have on how to work with it in Lua but i have no idea if it is possible:
Then with the use of a hook, the plugin should know what item the player clicked on.
MCServer needs a class open for lua that allows them to create custom windows. For example if you use a command that it will open a window with 9 slots or something. This is the idea i have on how to work with it in Lua but i have no idea if it is possible:
function HandleCommand( Split, Player ) Window = cLuaWindow(cWindow.Chest, 3 * 9); -- Create a chest window with 27 slots, besides the player inventory Item = cItem( E_BLOCK_DEAD_BUSH, 1, 0, 0 ) -- Create a item. It's just an example <-- Window:SetSlot( 1, Item ) -- Set the first slot to the Item /\ Window:SetOnSlotChange(MyOnSlotChangeFunction); -- When the player changes a slot, the given function gets called Window:SetOnWindowClose(MyOnWindowCloseFunction); -- When the player closes the window, the given function gets called Player:OpenWindow( Window ) -- Send the window to the player and let him open it || end
Then with the use of a hook, the plugin should know what item the player clicked on.
- Client expects a window type with the "OpenWindow" packet, which specifies the UI to show and the number of slots. The types are listed in the cWindow class: cWindow::Inventory, cWindow::Chest, cWindow::Anvil ...)
- We could pack the Window:Create into the object constructor:
Window = cLuaWindow(cWindow.Chest, 3 * 9); -- Create a chest window with 27 slots, besides the player inventory
- MCServer windows are sectioned into SlotAreas. One SlotArea services a groupd of slots of a similar function, such as the armor slots or the crafting grid. It would be wise to use the same distinction for Lua (so that the player inventory can be handled automatically by the server)
- Disregard this, this can be handled automatically by the API adapter. As far as Lua is concerned, the window can have a contiguous array of slots, count of which is given in the constructor.
- Hooks are more suited for global callbacks. The window callbacks are more local, so consider using an approach already used for commands - pass in a function which is to be called when something happens:
Window:SetOnSlotChange(MyOnSlotChangeFunction); Window:SetOnWindowClose(MyOnWindowCloseFunction);
- Should it be possible to reuse the window object once the player closes it?
- Should it be possible to pass the same window object to more different players?