• 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!

Item stats on Hover-Mouse

Vivelo

New Member
Joined
Aug 30, 2018
Messages
34
Reaction score
3
Hello everybody,
as in the topic, I am looking for a script that will bring up the stats of an item when hovering over it with the mouse.
I'm not very good at programming but maybe some of you can help me.

Perhaps the script inventory.lua in which my character's outfit is displayed will help?

Lua:
InventorySlotStyles = {
    [InventorySlotHead] = "HeadSlot",
    [InventorySlotNeck] = "NeckSlot",
    [InventorySlotBack] = "BackSlot",
    [InventorySlotBody] = "BodySlot",
    [InventorySlotRight] = "RightSlot",
    [InventorySlotLeft] = "LeftSlot",
    [InventorySlotLeg] = "LegSlot",
    [InventorySlotFeet] = "FeetSlot",
    [InventorySlotFinger] = "FingerSlot",
    [InventorySlotAmmo] = "AmmoSlot",
    [InventorySlotOutfit] = "OutfitSlot"
}

outfitinv = nil
inventoryWindow = nil
inventoryPanel = nil
inventoryButton = nil
purseButton = nil
healthInfoWindow = nil
healthBar = nil
manaBar = nil
experienceBar = nil
soulLabel = nil
capLabel = nil
healthTooltip = "Your character health is %d out of %d."
manaTooltip = "Your character mana is %d out of %d."
experienceTooltip = "You have %d%% to advance to level %d."

function init()
    connect(
        LocalPlayer,
        {
            onInventoryChange = onInventoryChange,
            onBlessingsChange = onBlessingsChange
        }
    )
    connect(g_game, {onGameStart = refresh})

    g_keyboard.bindKeyDown("Ctrl+I", toggle)

    inventoryButton = modules.client_topmenu.addRightGameToggleButton("inventoryButton", tr("Inventory") .. " (Ctrl+I)", "/images/topbuttons/inventory", toggle)
    inventoryButton:setOn(true)

    inventoryWindow = g_ui.loadUI("inventory", modules.game_interface.getRightPanel())
    inventoryWindow:disableResize()
    inventoryPanel = inventoryWindow:getChildById("contentsPanel")

    purseButton = inventoryPanel:getChildById("purseButton")
    local function purseFunction()
        local purse = g_game.getLocalPlayer():getInventoryItem(InventorySlotPurse)
        if purse then
            g_game.use(purse)
        end
    end
    purseButton.onClick = purseFunction

    refresh()
    inventoryWindow:setup()
end

function terminate()
    disconnect(
        g_game,
        {
            onOpenOutfitWindow = create,
            onGameEnd = destroy
        }
    )
    destroy()
end

function terminate()
    disconnect(
        LocalPlayer,
        {
            onInventoryChange = onInventoryChange,
            onBlessingsChange = onBlessingsChange
        }
    )
    disconnect(g_game, {onGameStart = refresh})

    g_keyboard.unbindKeyDown("Ctrl+I")

    inventoryWindow:destroy()
    inventoryButton:destroy()
end

function toggleAdventurerStyle(hasBlessing)
    for slot = InventorySlotFirst, InventorySlotLast do
        local itemWidget = inventoryPanel:getChildById("slot" .. slot)
        if itemWidget then
            itemWidget:setOn(hasBlessing)
        end
    end
end

function refresh()
    local player = g_game.getLocalPlayer()
    for i = InventorySlotFirst, InventorySlotPurse do
        if g_game.isOnline() then
            onInventoryChange(player, i, player:getInventoryItem(i))
        else
            onInventoryChange(player, i, nil)
        end
        toggleAdventurerStyle(player and Bit.hasBit(player:getBlessings(), Blessings.Adventurer) or false)
    end

    local creatureBox = inventoryPanel:getChildById("slot12")
    local player = g_game.getLocalPlayer()
    if player then
        creatureBox:setCreature(player)
    end

    purseButton:setVisible(g_game.getFeature(GamePurseSlot))
end

function toggle()
    if inventoryButton:isOn() then
        inventoryWindow:close()
        inventoryButton:setOn(false)
    else
        inventoryWindow:open()
        inventoryButton:setOn(true)
    end
end

function onMiniWindowClose()
    inventoryButton:setOn(false)
end

-- hooked events
function onInventoryChange(player, slot, item, oldItem)
    if slot > InventorySlotPurse then
        return
    end

    if slot == InventorySlotPurse then
        if g_game.getFeature(GamePurseSlot) then
            purseButton:setEnabled(item and true or false)
        end
        return
    end

    local itemWidget = inventoryPanel:getChildById("slot" .. slot)
    if item then
        itemWidget:setStyle("InventoryItem")
        itemWidget:setItem(item)
    else
        itemWidget:setStyle(InventorySlotStyles[slot])
        itemWidget:setItem(nil)
    end
end

function onBlessingsChange(player, blessings, oldBlessings)
    local hasAdventurerBlessing = Bit.hasBit(blessings, Blessings.Adventurer)
    if hasAdventurerBlessing ~= Bit.hasBit(oldBlessings, Blessings.Adventurer) then
        toggleAdventurerStyle(hasAdventurerBlessing)
    end
end


Here is a graphic example:

1596474713228.png

THANKS FOR ALL HELP!

Edit: I need script for TFS 0.3.6 :D
 
Last edited:
There is no simple ready-made way to do this and probably no one will do it for free. Displaying item tooltip requires creating new widget and maybe new protocol opcode.
 
Start with modules/game_interface/widgets/uiitem.lua , find:
Lua:
function UIItem:onHoverChange(hovered)

Add inside this function, under: UIWidget.onHoverChange(self, hovered) , simple:
Lua:
  local item = self:getItem()
  if item and not self:getTooltip() then
    self:setTooltip('Description. ID: ' .. item:getId())
  end

And now.. your adventure start's here. ;)
Preview: Video

Basically you need to create new "tooltip" frame that will contain all item info and display it in format that what you want to be.
So, design, icons, etc. takes time, parsing item info from server<>client or doing it manually via client (if you have static items = easier way).
Just use your imagination :) That's pretty all what you could use.

I haven't done it yet cuz of lack of time and doing some other stuff in my project.
But atleast I showed you where to start.
Have fun! Hope you finish this! :)
 
Start with modules/game_interface/widgets/uiitem.lua , find:
Lua:
function UIItem:onHoverChange(hovered)

Add inside this function, under: UIWidget.onHoverChange(self, hovered) , simple:
Lua:
  local item = self:getItem()
  if item and not self:getTooltip() then
    self:setTooltip('Description. ID: ' .. item:getId())
  end

And now.. your adventure start's here. ;)
Preview: Video

Basically you need to create new "tooltip" frame that will contain all item info and display it in format that what you want to be.
So, design, icons, etc. takes time, parsing item info from server<>client or doing it manually via client (if you have static items = easier way).
Just use your imagination :) That's pretty all what you could use.

I haven't done it yet cuz of lack of time and doing some other stuff in my project.
But atleast I showed you where to start.
Have fun! Hope you finish this! :)

Ohh <3 Thanks you a lot! I try!
Post automatically merged:

There is no simple ready-made way to do this and probably no one will do it for free. Displaying item tooltip requires creating new widget and maybe new protocol opcode.

I will ask immediately how much (for example) such a script would cost?
Post automatically merged:

Start with modules/game_interface/widgets/uiitem.lua , find:
Lua:
function UIItem:onHoverChange(hovered)

Add inside this function, under: UIWidget.onHoverChange(self, hovered) , simple:
Lua:
  local item = self:getItem()
  if item and not self:getTooltip() then
    self:setTooltip('Description. ID: ' .. item:getId())
  end

And now.. your adventure start's here. ;)
Preview: Video

Basically you need to create new "tooltip" frame that will contain all item info and display it in format that what you want to be.
So, design, icons, etc. takes time, parsing item info from server<>client or doing it manually via client (if you have static items = easier way).
Just use your imagination :) That's pretty all what you could use.

I haven't done it yet cuz of lack of time and doing some other stuff in my project.
But atleast I showed you where to start.
Have fun! Hope you finish this! :)

I started as you asked, but unfortunately it doesn't work.
 
Last edited:
@Vivelo

You placed it in right place, are you sure about that?
Try compare your onHoverChange function with mine:
Lua:
function UIItem:onHoverChange(hovered)
  UIWidget.onHoverChange(self, hovered)

  local item = self:getItem()
  if item and not self:getTooltip() then
    self:setTooltip('Description. ID: ' .. item:getId())
  end 

  if self:isVirtual() or not self:isDraggable() then return end

  local draggingWidget = g_ui.getDraggingWidget()
  if draggingWidget and self ~= draggingWidget then
    local gotMap = draggingWidget:getClassName() == 'UIGameMap'
    local gotItem = draggingWidget:getClassName() == 'UIItem' and not draggingWidget:isVirtual()
    if hovered and (gotItem or gotMap) then
      self:setBorderWidth(1)
      draggingWidget.hoveredWho = self
    else
      self:setBorderWidth(0)
      draggingWidget.hoveredWho = nil
    end
  end
end
 
@Vivelo

You placed it in right place, are you sure about that?
Try compare your onHoverChange function with mine:
Lua:
function UIItem:onHoverChange(hovered)
  UIWidget.onHoverChange(self, hovered)

  local item = self:getItem()
  if item and not self:getTooltip() then
    self:setTooltip('Description. ID: ' .. item:getId())
  end

  if self:isVirtual() or not self:isDraggable() then return end

  local draggingWidget = g_ui.getDraggingWidget()
  if draggingWidget and self ~= draggingWidget then
    local gotMap = draggingWidget:getClassName() == 'UIGameMap'
    local gotItem = draggingWidget:getClassName() == 'UIItem' and not draggingWidget:isVirtual()
    if hovered and (gotItem or gotMap) then
      self:setBorderWidth(1)
      draggingWidget.hoveredWho = self
    else
      self:setBorderWidth(0)
      draggingWidget.hoveredWho = nil
    end
  end
end

Yes, the same place:

1596477104825.png
Post automatically merged:

Yes, the same place:

1596477104825.png

OKEY NEVERMIND :D I paste this for old Client... :D My mistake! Now its work! Thanks a lot one more time!
 
Back
Top