Ascuas Funkeln
Rakkedo Game
- Joined
- Apr 14, 2013
- Messages
- 549
- Solutions
- 32
- Reaction score
- 304
- Location
- Poland
- GitHub
- AscuasFunkeln
Hello, lets make some more things with our clients~!
Let's start~!
Step 1
Download this prepared icon, and paste it to otclient/data/images/ui/
Step 2
Now open container.otui and containers.lua in otclient/modules/game_containers/
Step 3
In container.otui
After this
Add this:
All should look like this, full code bellow.
Step 4
Now open containers.lua
And after this:
Add this:
Full code bellow:
Step 5
Now in server add this things:
in data/creaturescripts/
creaturescripts.xml
login.lua
And now script.
Ok, server code updated(24.04.2020), now one click shoudl stacking everything in backpack, movie edited
Let's start~!
Step 1
Download this prepared icon, and paste it to otclient/data/images/ui/
Step 2
Now open container.otui and containers.lua in otclient/modules/game_containers/
Step 3
In container.otui
After this
Code:
UIButton
id: upButton
anchors.top: stackingButton.top
anchors.right: stackingButton.left
margin-right: 3
size: 14 14
image-source: /images/ui/miniwindow_buttons
image-clip: 42 0 14 14
$hover:
image-clip: 42 14 14 14
$pressed:
image-clip: 42 28 14 14
Add this:
Code:
UIButton
id: stackingButton
anchors.top: minimizeButton.top
anchors.right: minimizeButton.left
margin-right: 3
size: 14 14
image-source: /images/ui/stacking_buttons
image-clip: 0 14 14 14
$hover:
image-clip: 0 14 14 14
$pressed:
image-clip: 0 28 14 14
Code:
PageButton < Button
size: 30 18
margin: 1
ContainerWindow < MiniWindow
height: 150
UIItem
id: containerItemWidget
virtual: true
size: 16 16
anchors.top: parent.top
anchors.left: parent.left
margin-top: 4
margin-left: 4
UIButton
id: upButton
anchors.top: stackingButton.top
anchors.right: stackingButton.left
margin-right: 3
size: 14 14
image-source: /images/ui/miniwindow_buttons
image-clip: 42 0 14 14
$hover:
image-clip: 42 14 14 14
$pressed:
image-clip: 42 28 14 14
UIButton
id: stackingButton
anchors.top: minimizeButton.top
anchors.right: minimizeButton.left
margin-right: 3
size: 14 14
image-source: /images/ui/stacking_buttons
image-clip: 0 14 14 14
$hover:
image-clip: 0 14 14 14
$pressed:
image-clip: 0 28 14 14
Panel
id: pagePanel
anchors.left: parent.left
anchors.right: parent.right
anchors.top: miniwindowTopBar.bottom
height: 20
margin: 2 3 0 3
background: #00000066
visible: false
Label
id: pageLabel
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
margin-top: 2
text-auto-resize: true
PageButton
id: prevPageButton
text: <
anchors.top: parent.top
anchors.left: parent.left
PageButton
id: nextPageButton
text: >
anchors.top: parent.top
anchors.right: parent.right
MiniWindowContents
padding-right: 0
layout:
type: grid
cell-size: 34 34
flow: true
Step 4
Now open containers.lua
And after this:
Lua:
local upButton = containerWindow:getChildById('upButton')
upButton.onClick = function()
g_game.openParent(container)
end
upButton:setVisible(container:hasParent())
Lua:
local stackingButton = containerWindow:getChildById('stackingButton')
stackingButton.onClick = function()
local protocolGame = g_game.getProtocolGame()
if protocolGame then
protocolGame:sendExtendedOpcode(141, 1)
end
end
stackingButton:setVisible(true)
Full code bellow:
Lua:
function init()
g_ui.importStyle('container')
connect(Container, { onOpen = onContainerOpen,
onClose = onContainerClose,
onSizeChange = onContainerChangeSize,
onUpdateItem = onContainerUpdateItem })
connect(Game, { onGameEnd = clean() })
reloadContainers()
end
function terminate()
disconnect(Container, { onOpen = onContainerOpen,
onClose = onContainerClose,
onSizeChange = onContainerChangeSize,
onUpdateItem = onContainerUpdateItem })
disconnect(Game, { onGameEnd = clean() })
end
function reloadContainers()
clean()
for _,container in pairs(g_game.getContainers()) do
onContainerOpen(container)
end
end
function clean()
for containerid,container in pairs(g_game.getContainers()) do
destroy(container)
end
end
function destroy(container)
if container.window then
container.window:destroy()
container.window = nil
container.itemsPanel = nil
end
end
function refreshContainerItems(container)
for slot=0,container:getCapacity()-1 do
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
itemWidget:setItem(container:getItem(slot))
end
if container:hasPages() then
refreshContainerPages(container)
end
end
function toggleContainerPages(containerWindow, pages)
containerWindow:getChildById('miniwindowScrollBar'):setMarginTop(pages and 42 or 22)
containerWindow:getChildById('contentsPanel'):setMarginTop(pages and 42 or 22)
containerWindow:getChildById('pagePanel'):setVisible(pages)
end
function refreshContainerPages(container)
local currentPage = 1 + math.floor(container:getFirstIndex() / container:getCapacity())
local pages = 1 + math.floor(math.max(0, (container:getSize() - 1)) / container:getCapacity())
container.window:recursiveGetChildById('pageLabel'):setText(string.format('Page %i of %i', currentPage, pages))
local prevPageButton = container.window:recursiveGetChildById('prevPageButton')
if currentPage == 1 then
prevPageButton:setEnabled(false)
else
prevPageButton:setEnabled(true)
prevPageButton.onClick = function() g_game.seekInContainer(container:getId(), container:getFirstIndex() - container:getCapacity()) end
end
local nextPageButton = container.window:recursiveGetChildById('nextPageButton')
if currentPage >= pages then
nextPageButton:setEnabled(false)
else
nextPageButton:setEnabled(true)
nextPageButton.onClick = function() g_game.seekInContainer(container:getId(), container:getFirstIndex() + container:getCapacity()) end
end
end
function onContainerOpen(container, previousContainer)
local containerWindow
if previousContainer then
containerWindow = previousContainer.window
previousContainer.window = nil
previousContainer.itemsPanel = nil
else
containerWindow = g_ui.createWidget('ContainerWindow', modules.game_interface.getRightPanel())
end
containerWindow:setId('container' .. container:getId())
local containerPanel = containerWindow:getChildById('contentsPanel')
local containerItemWidget = containerWindow:getChildById('containerItemWidget')
containerWindow.onClose = function()
g_game.close(container)
containerWindow:hide()
end
-- this disables scrollbar auto hiding
local scrollbar = containerWindow:getChildById('miniwindowScrollBar')
scrollbar:mergeStyle({ ['$!on'] = { }})
local upButton = containerWindow:getChildById('upButton')
upButton.onClick = function()
g_game.openParent(container)
end
upButton:setVisible(container:hasParent())
local stackingButton = containerWindow:getChildById('stackingButton')
stackingButton.onClick = function()
local protocolGame = g_game.getProtocolGame()
if protocolGame then
protocolGame:sendExtendedOpcode(141, 1)
end
end
stackingButton:setVisible(true)
local name = container:getName()
name = name:sub(1,1):upper() .. name:sub(2)
containerWindow:setText(name)
containerItemWidget:setItem(container:getContainerItem())
containerPanel:destroyChildren()
for slot=0,container:getCapacity()-1 do
local itemWidget = g_ui.createWidget('Item', containerPanel)
itemWidget:setId('item' .. slot)
itemWidget:setItem(container:getItem(slot))
itemWidget:setMargin(0)
itemWidget.position = container:getSlotPosition(slot)
if not container:isUnlocked() then
itemWidget:setBorderColor('red')
end
end
container.window = containerWindow
container.itemsPanel = containerPanel
toggleContainerPages(containerWindow, container:hasPages())
refreshContainerPages(container)
local layout = containerPanel:getLayout()
local cellSize = layout:getCellSize()
containerWindow:setContentMinimumHeight(cellSize.height)
containerWindow:setContentMaximumHeight(cellSize.height*layout:getNumLines())
if not previousContainer then
local filledLines = math.max(math.ceil(container:getItemsCount() / layout:getNumColumns()), 1)
containerWindow:setContentHeight(filledLines*cellSize.height)
end
containerWindow:setup()
end
function onContainerClose(container)
destroy(container)
end
function onContainerChangeSize(container, size)
if not container.window then return end
refreshContainerItems(container)
end
function onContainerUpdateItem(container, slot, item, oldItem)
if not container.window then return end
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
itemWidget:setItem(item)
end
Step 5
Now in server add this things:
in data/creaturescripts/
creaturescripts.xml
Code:
<event type="extendedopcode" name="stacker" script="stacker.lua" />
Code:
player:registerEvent("stacker")
And now script.
Lua:
function onExtendedOpcode(player, opcode, buffer)
local buf = tonumber(buffer)
if opcode == 141 and buf == 1 then
local coppercount = player:getItemCount(2148)
local silvercount = player:getItemCount(2152)
local goldcount = player:getItemCount(2160)
local diamondcount = player:getItemCount(2151)
if coppercount >= 100 then
local getcoppercount = (math.floor((coppercount / 100)))
player:addItem(2152, getcoppercount)
player:removeItem(2148, (getcoppercount * 100))
else
player:removeItem(2148, coppercount)
player:addItem(2148, coppercount)
end
if silvercount >= 100 then
local getsilvercount = (math.floor((silvercount / 100)))
player:addItem(2160, getsilvercount)
player:removeItem(2152, (getsilvercount * 100))
else
player:removeItem(2152, silvercount)
player:addItem(2152, silvercount)
end
if goldcount >= 100 then
local getgoldcount = (math.floor((goldcount / 100)))
player:addItem(2151, getgoldcount)
player:removeItem(2160, (getgoldcount * 100))
else
player:removeItem(2160, goldcount)
player:addItem(2160, goldcount)
end
if diamondcount > 1 then
player:removeItem(2151, diamondcount)
player:addItem(2151, diamondcount)
end
return
end
end
Ok, server code updated(24.04.2020), now one click shoudl stacking everything in backpack, movie edited
Last edited: