• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

New generic slot in a MiniWindow

Booker

New Member
Joined
Apr 2, 2015
Messages
46
Reaction score
4
Hello, i'm making my first scripts in lua by my own and got to an issue: i'm trying to create a window where there are 3 slots and only 1 type of item can be assigned to it, it actually looks like this right now:
QSEfiD8.png

The problem is, when i try to place any item on them, i get the error:
"You cannot dress this object there."

My question: I don't need the code, just a help to know where i need to edit and if i need to make big changes for this to get going.

Btw, my code:
.otui
Code:
PartnerSlot < Item
  image-source: /images/game/slots/finger
  $on:
    image-source: /images/game/slots/body-blessed

PartnerSlot_1 < PartnerSlot
  id: partnerSlot1
  &position: {x=65535, y=6, z=0}
  $on:
    image-source: /images/game/slots/body-blessed

PartnerSlot_2 < PartnerSlot
  id: partnerSlot2
  &position: {x=65535, y=4, z=0}
  $on:
    image-source: /images/game/slots/body-blessed

PartnerSlot_3 < PartnerSlot
  id: partnerSlot3
  &position: {x=65535, y=5, z=0}
  $on:
    image-source: /images/game/slots/body-blessed

MiniWindow
  id: partnerbag
  !text: tr('Partners')
  icon: /images/topbuttons/inventory
  height: 100

  MiniWindowContents
    PartnerSlot_1
      anchors.right: partnerSlot2.left
      anchors.top: parent.top
      margin-top: 25
      margin-right: 15

    PartnerSlot_2
      anchors.horizontalCenter: parent.horizontalCenter
      anchors.top: parent.top
      margin-top: 10

    PartnerSlot_3
      margin-top: 25
      anchors.left: partnerSlot2.right
      anchors.top: parent.top
      margin-left: 15
lua:
Lua:
partnerWindow = nil

function init()
    connect(LocalPlayer,
        {
            onInventoryChange = onInventoryChange
        }
    )

    partnerWindow = g_ui.loadUI('partnerstats', modules.game_interface.getRightPanel())
    partnerWindow:disableResize()

    partnerStatsButton = modules.client_topmenu.addRightGameToggleButton(
        'partnerStatsButton',
        tr('Partners'),
        '/images/topbuttons/login',
        toggle
    )
    partnerStatsButton:setOn(true)
    refresh()
    partnerWindow:setup()
end

function onInventoryChange(player, slot, item, oldItem)
    local itemWidget = partnerWindow:getChildById('partnerSlot'..slot)
    if item then
        itemWidget:setItem(item)
    else
        itemWidget:setItem(nil)
    end
end

function refresh()
    local player = g_game.getLocalPlayer()

    for i = InventorySlotFirst, InventorySlotLast do
        if g_game.isOnline() then
            onInventoryChange(player, i, player:getInventoryItem(i))
        else
            onInventoryChange(player, i, nil)
        end
    end
end

function terminate()
    disconnect(LocalPlayer,
        {
            onInventoryChange = onInventoryChange
        }
    )

    partnerWindow:destroy()
    partnerStatsButton:destroy()
end

function toggle()
    if partnerWindow:isVisible() then
        partnerWindow:hide()
        partnerStatsButton:setOn(false)
    else
        partnerWindow:show()
        partnerStatsButton:setOn(true)
        partnerWindow:focus()
    end
end
I part of the code i got from game_interface module...

Tfs 1.2

Thank you!
 
Last edited:
You need, change the Tfs sources... Look for the keywords like "SLOTP_RING" and "CONST_SLOT_RING" and add your Slots..
 
Hello and thanks for trying to help =]
Made all the changes and compiled with no errors, really appreciate.

On OTC:
in const.h, there are 4 more "extra" slot types :
C++:
enum InventorySlot {
        InventorySlotHead = 1,
        InventorySlotNecklace,
        InventorySlotBackpack,
        InventorySlotArmor,
        InventorySlotRight,
        InventorySlotLeft,
        InventorySlotLegs,
        InventorySlotFeet,
        InventorySlotRing,
        InventorySlotAmmo,
        InventorySlotPurse,
        InventorySlotExt1, <---------
        InventorySlotExt2, <---------
        InventorySlotExt3, <---------
        InventorySlotExt4, <---------
        LastInventorySlot
    };
can i use these insted of compiling it again?
 
Didn't make any changes to OTC sources yet. My code is inside the spoiler on the thread.
Apparently, this is the error i get from OTC:
attempt to index local 'itemWidget' (a nil value)
The part of the code:
Lua:
function onInventoryChange(player, slot, item, oldItem)
    local itemWidget = partnerWindow:getChildById('partnerSlot'..slot)
    if item then
        itemWidget:setItem(item)
    else
        itemWidget:setItem(nil)
    end
end
Looks like itemWidget isn't returning anything, am i right? My .otui looks correct to me, the "Items" have the id: PartnerSlot1, PartnerSlot2, PartnerSlot3.
This is the part that uses the function:
Lua:
function refresh()
    local player = g_game.getLocalPlayer()

    for i = 1, 12 do
        if g_game.isOnline() then
            onInventoryChange(player, i, player:getInventoryItem(i))
        else
            onInventoryChange(player, i, nil)
        end
    end
end
 
Ok, changed. Just to add, i put this in player.lua:
Old:
Lua:
InventorySlotOther = 0
InventorySlotHead = 1
InventorySlotNeck = 2
InventorySlotBack = 3
InventorySlotBody = 4
InventorySlotRight = 5
InventorySlotLeft = 6
InventorySlotLeg = 7
InventorySlotFeet = 8
InventorySlotFinger = 9
InventorySlotAmmo = 10
InventorySlotPurse = 11

InventorySlotFirst = 1
InventorySlotLast = 10

Now:
Lua:
InventorySlotOther = 0
InventorySlotHead = 1
InventorySlotNeck = 2
InventorySlotBack = 3
InventorySlotBody = 4
InventorySlotRight = 5
InventorySlotLeft = 6
InventorySlotLeg = 7
InventorySlotFeet = 8
InventorySlotFinger = 9
InventorySlotAmmo = 10
InventorySlotPurse = 11
InventorySlotExt1 = 12  <!-- changed -->

InventorySlotFirst = 1
InventorySlotLast = 12 <!-- changed -->
And in inventory.lua:

Under:
Lua:
[InventorySlotAmmo] = "AmmoSlot"

Placed:
Lua:
[InventorySlotExt1] = "PartnerSlot"
But still, no success.
This change in inventory.lua causes the main inventory window to crash and doesn't even open up. (yes, i added a comma to the line above)
 
Back
Top