2Rec
Excellent OT User
- Joined
- Jul 31, 2013
- Messages
- 550
- Solutions
- 48
- Reaction score
- 885
Ok, so, i started to tinker with OTC and in order to understand this freaking thing i made those 2 quick features, that i think are pretty cool and useful.
I would really appreciate an advice from some OTClient big shots and enjoy other people to test shit out of it. Feel free to post fixes or remakes if you want.
I know it's not the most efficient way to make it, but i couldn't find a better way to code it than with exOpcodes. Therefore i'm asking for help.
Don't treat it like a complete code. Anyway, features work as intended so far.
modules/game_interface/widgets/uiitem.lua
Inside UIItemnMouseRelease()
-- searchContainer() is either mine or made by Stigma if i recall, didn't have this one credited in my lib, and i forgot :v
Cheers
I would really appreciate an advice from some OTClient big shots and enjoy other people to test shit out of it. Feel free to post fixes or remakes if you want.
I know it's not the most efficient way to make it, but i couldn't find a better way to code it than with exOpcodes. Therefore i'm asking for help.
Don't treat it like a complete code. Anyway, features work as intended so far.
Known issues:
---
1.Button
data/images/ui/miniwindow_pickbuttons.png
modules/game_containers/container.otui
- clone() stops actively decaying items, like 'lit torch' from decay;
- gotta find a way to hide button if container is not a part of players inventory;
---
1.Button
data/images/ui/miniwindow_pickbuttons.png
modules/game_containers/container.otui
Code:
UIButton
id: pickAllButton
anchors.top: upButton.top
anchors.right: upButton.left
margin-right: 3
size: 14 14
image-source: /images/ui/miniwindow_pickbuttons
image-clip: 0 0 14 14
$hover:
image-clip: 0 14 14 14
$pressed:
image-clip: 0 28 14 14
2. Client
modules/game_containers/containers.lua
Inside function onOpenContainer()
modules/game_containers/containers.lua
Inside function onOpenContainer()
Lua:
-- pick up all button
local pickButton = containerWindow:getChildById('pickAllButton')
pickButton.onClick = function()
local contId = container:getId()
local protocolGame = g_game.getProtocolGame()
if protocolGame then
protocolGame:sendExtendedOpcode(52, contId)
return true
end
end
--
modules/game_interface/widgets/uiitem.lua
Inside UIItemnMouseRelease()
Lua:
-- drag on double click
self.onDoubleClick = function()
local itPos = "{x = ".. item:getPosition().x ..", y = ".. item:getPosition().y ..", z = ".. item:getPosition().z .."}"
local protocolGame = g_game.getProtocolGame()
if protocolGame then
protocolGame:sendExtendedOpcode(51, itPos)
return true
end
end
--
3. Server
data/creaturescripts/extendedopcodes.lua
data/creaturescripts/extendedopcodes.lua
Lua:
local function parseT(s)
local t = {}
for k, v in string.gmatch(s, "(%w+) = (%w+)") do
t[k] = v
end
return t
end
function searchContainer(container, items)
items = items or {}
for i = container:getSize()-1, 0, -1 do
local item = container:getItem(i)
if item:getType():isContainer() then
searchContainer(item, items)
else
items[#items+1] = item
end
end
return items
end
function onExtendedOpcode(player, opcode, buffer)
if opcode == OPCODE_ITEMONDOUBLECLICK then
local t = parseT(buffer)
local contY = t.y
local container = player:getContainerById(contY - 64)
local playerBp = player:getSlotItem(CONST_SLOT_BACKPACK)
local item = container:getItem(t.z)
if not playerBp then
return false
end
if playerBp:getEmptySlots(true) == 0 then
player:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
return false
end
if item:getTopParent():getId() == player:getId() then
return false
end
if item:getWeight() > player:getFreeCapacity() then
player:sendCancelMessage(RETURNVALUE_NOTENOUGHCAPACITY)
return false
end
local clone = item:clone()
player:addItemEx(clone)
item:remove()
end
if opcode == OPCODE_PICKUPALL then
local container = player:getContainerById(tonumber(buffer))
local items = searchContainer(container)
local playerBp = player:getSlotItem(CONST_SLOT_BACKPACK)
local weight = 0
if not playerBp then
return false
end
for i = 1, #items do
weight = weight + items[i]:getWeight()
end
for k, v in pairs(items) do
if playerBp:getEmptySlots(true) == 0 then
player:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
return false
end
if weight > player:getFreeCapacity() then
player:sendCancelMessage(RETURNVALUE_NOTENOUGHCAPACITY)
return false
end
if v:getTopParent():getId() == player:getId() then
return false
end
local clone = v:clone()
player:addItemEx(clone)
v:remove()
end
end
end
Cheers
Last edited: