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

OTclientV8 ItemTooltip + rarity frames + custom color on item name

jakub742

Active Member
Joined
May 1, 2010
Messages
198
Solutions
2
Reaction score
40
Location
Slovakia
Hi, I recently started to implement item tooltip into my server and i would like to share my current progress. Maybe it will help some people.

Tfs source changes: Added tooltips for inventory items · OTCv8/forgottenserver@7f5b4fb (https://github.com/OTCv8/forgottenserver/commit/7f5b4fbc08711124dec86b0fcd7bfd78dd1165c4)

Otclientv8:

How can I add colors to the sqm of rare, epic, legendary items? OTclient (https://otland.net/threads/how-can-i-add-colors-to-the-sqm-of-rare-epic-legendary-items-otclient.287456/#post-2741182)

From this post i edited containers.lua with "setFrames()" function.

Rarity frames worked in containers, however i wanted to have rarity frames in inventory aswell.
EDIT: there was bug in containers.lua that was causing frames to be still visible in containers after moving them to another container. (Thanks @Mateus Robeerto) updates are present in the PR link below.

Inventory frames:
To show rarity frame inside inventory add following function in modules/game_inventory/inventory.lua:

LUA:
local function setFrames(item, itemWidget)
  local name = item:getTooltip()
  if (name) then
    if (string.find(name, "legendary")) then
      itemWidget:setImageSource('/images/ui/rarity_gold')
    elseif (string.find(name, "epic")) then
      itemWidget:setImageSource('/images/ui/rarity_purple')
    elseif (string.find(name, "rare")) then
      itemWidget:setImageSource('/images/ui/rarity_blue')
    end
  end
end

above function
Code:
onInventoryChange(player, slot, item, oldItem)

inside onInventoryChange add
Code:
setFrames(item, itemWidget)
after
Code:
itemWidget:setItem(item)

1728386059892.webp

After this frames are visible in inventory
1728386080695.webp

Tooltip different color for item name based on rarity:
Next i tried to change the color of text in modules/corelib/ui/tooltip.lua
I wanted different color in tooltips based on item rarity.
My first attempt resulted in full text in color similar to @Itutorial in OTClient - Where are otclient's tooltips handled? (https://otland.net/threads/where-are-otclients-tooltips-handled.290034/)
1728387678245.webp
(maybe u can use this as example :D)

In tooltip.lua i made second label widget toolTipLabel2.

toolTipLabel - contains item name (split after first new line \n)
toolTipLabel2 - contains rest of text


So we can set different colors for those 2 labels by :setColor()
Color codes used for "rare", "epic" and "legendary" used from WoW wiki: API GetItemQualityColor (https://wowpedia.fandom.com/wiki/API_GetItemQualityColor)

You can use this example to create another widget that will hold bonus stats, for example that can have different color.

Video:


If you hate my code dont hesitate to comment :D

Using this for rarity drops - [TFS 1.X] Rarity Rolls & Custom Attributes Library

Full commit with changes for OTclientV8 - Itemtooltip + rarity frames + name by jakub742 · Pull Request #1 · jakub742/otclientv8 (https://github.com/jakub742/otclientv8/pull/1/files)

Hope it will help someone ;) (Tested in Nekiro TFS 1.5 Downgrade)
 
Last edited:
TFS source changes are outdated, this wont work for tfs 1.4.2 or newer (or i dunno how to make it work)
 
TFS source changes are outdated, this wont work for tfs 1.4.2 or newer (or i dunno how to make it work)

So, you did it wrong. I tested it with the old TFS 1.3 up to the most recent 1.6, and everything is working perfectly. Look at the image; I’m using TFS 1.4.2 (1098). I implemented the rarity system about a year ago.

1728390310547.webp




Do you know how to display items in color? You can use Leo's or Oen's system to show rarity colors, or you can manually add it to items.xml by setting the name. For example, an 'Epic Magic Sword' can be shown in red for epic rarity, or you can just add 'epic' to the description. It needs to match the name on the OTClient. If it's 'epic', then you set it as 'epic'. If it's 'Epic', then you set it as 'Epic'. It depends on whether the name is lowercase or uppercase.

Leo

Oen
 
Last edited:
I just found bug with the containers module. From this post: https://otland.net/threads/how-can-i-add-colors-to-the-sqm-of-rare-epic-legendary-items-otclient.287456/#post-2741182
Do you have it aswell ? I tried to put additionals setFrames() but no help. Does anybody know how to fix this ? (when moving rare items between containers) rarity frame is still present even after item was already moved.


EDIT: solved thanks to Mateus credit and file changes updated in main post.
 
Last edited:
Here it is, complete and updated... You need to remember the server side if it's a name that will send 'Epic' to the client... So, you should set it like this here.
elseif (string.find(name, "Epic")) then

You need to check the modules game_inventory and container to see if they are lowercase or uppercase. If it's lowercase and you set it as lowercase on the server side, for example, 'Leo' or 'Oen' or any custom script, make sure the name is also lowercase, like rarity, epic, rare, etc. Understand? Both names need to match.
Post automatically merged:

 

Attachments

Last edited:
Here it is, complete and updated... You need to remember the server side if it's a name that will send 'Epic' to the client... So, you should set it like this here.
elseif (string.find(name, "Epic")) then

You need to check the modules game_inventory and container to see if they are lowercase or uppercase. If it's lowercase and you set it as lowercase on the server side, for example, 'Leo' or 'Oen' or any custom script, make sure the name is also lowercase, like rarity, epic, rare, etc. Understand? Both names need to match.
Post automatically merged:

Thanks tested containers and its working fine. Updated git commit with your containers.lua, also added
LUA:
itemWidget:setTooltip(nil)
to inventory.lua

Also added lowercase check for item name in every file. Should work even if rarity starts with uppercase "Epic".
Cheers
 
Last edited:
So, you did it wrong. I tested it with the old TFS 1.3 up to the most recent 1.6, and everything is working perfectly. Look at the image; I’m using TFS 1.4.2 (1098). I implemented the rarity system about a year ago.

View attachment 87575




Do you know how to display items in color? You can use Leo's or Oen's system to show rarity colors, or you can manually add it to items.xml by setting the name. For example, an 'Epic Magic Sword' can be shown in red for epic rarity, or you can just add 'epic' to the description. It needs to match the name on the OTClient. If it's 'epic', then you set it as 'epic'. If it's 'Epic', then you set it as 'Epic'. It depends on whether the name is lowercase or uppercase.

Leo

Oen
I did apply every single line of the code that you've shared, I got OEN's upgrade system. Result:

OEN's upgrade works fine:
1728505787785.webp

the display of the item's info works fine:
1728505804105.webp

But they don't work together.

Added prints to the code and:
setFrames: Item name (lowercased): an axe (atk:12, def:6).
it weighs 40.00 oz.
setFrames: No rarity match found, keeping default image source.

No errors whatsoever.
this is beyond my understanding and capabilities
 
OEN's upgrade works fine
When you look at the item, it shows the description with the word ‘legendary’, but when you hover over the item, it only displays ‘an axe’ instead of the correct ‘a legendary axe’. The rarity color should be yellow. Test it through the items.xml, just set the name to 'legendary', save it, and restart. Check if it appears. It seems to be an issue with the tooltip. Check my gif, it's displaying both the OnLook and the tooltip correctly, showing the name as expected.


rarity.gif
 
When you look at the item, it shows the description with the word ‘legendary’, but when you hover over the item, it only displays ‘an axe’ instead of the correct ‘a legendary axe’. The rarity color should be yellow. Test it through the items.xml, just set the name to 'legendary', save it, and restart. Check if it appears. It seems to be an issue with the tooltip. Check my gif, it's displaying both the OnLook and the tooltip correctly, showing the name as expected.


View attachment 87596
are you sure ? please check your code against my PR, because for me its working fine.

LUA:
    </item>
    <item id="2378" article="a" name="legendary battle axe">
        <attribute key="weight" value="5000"/>
        <attribute key="defense" value="10"/>
        <attribute key="attack" value="25"/>
        <attribute key="weaponType" value="axe"/>
        <attribute key="slotType" value="two-handed"/>
    </item>

changed to legendary and its showing in description and tooltip aswell (also legendary frame works aswell)
1728552738218.webp
 
When you look at the item, it shows the description with the word ‘legendary’, but when you hover over the item, it only displays ‘an axe’ instead of the correct ‘a legendary axe’. The rarity color should be yellow. Test it through the items.xml, just set the name to 'legendary', save it, and restart. Check if it appears. It seems to be an issue with the tooltip. Check my gif, it's displaying both the OnLook and the tooltip correctly, showing the name as expected.


View attachment 87596
So, I did edit axe in items.xml and put name 'legendary axe' so it displays now:

1728583095706.webp

but it doesn't work with the OEN's upgrade system for me :/
any ideas how to troubleshoot it / find the issue?
 
So, I did edit axe in items.xml and put name 'legendary axe' so it displays now:

View attachment 87605

but it doesn't work with the OEN's upgrade system for me :/
any ideas how to troubleshoot it / find the issue?
look into OEN's upgrade system. There you need to fix it. I guess its not changing item description rather using item:setCustomAttribute to set custom attributes and then reads them in onLook

this is from upgrade_system_core.lua
LUA:
    local copy = Game.createItem(target.itemid, 1)
    copy:setRarity(target:getRarityId())
    copy:setCustomAttribute("upgrade", target:getUpgradeLevel())
    copy:setCustomAttribute("item_level", target:getItemLevel())
    if target:isUnique() then
      copy:setCustomAttribute("unique", target:getUnique())
    end

So when you're creating a new item try to update item description.
Not sure where is that name eg. "legendary" in that upgrade system.

Code:
function Item.getRarity(self)
  return self:getCustomAttribute("rarity") and US_CONFIG.RARITY[self:getCustomAttribute("rarity")] or US_CONFIG.RARITY[COMMON]
end

based on this try to update item description with prefix thing:getRarity().name
Play around and try, thats what im doing most of the times. Add prints() so you can find what is stored in that getRarity().name for example.

There is no issue with item tooltip discussed here. I suggest you to create a new thread for this if you cant fix it youself.
 
look into OEN's upgrade system. There you need to fix it. I guess its not changing item description rather using item:setCustomAttribute to set custom attributes and then reads them in onLook

this is from upgrade_system_core.lua
LUA:
    local copy = Game.createItem(target.itemid, 1)
    copy:setRarity(target:getRarityId())
    copy:setCustomAttribute("upgrade", target:getUpgradeLevel())
    copy:setCustomAttribute("item_level", target:getItemLevel())
    if target:isUnique() then
      copy:setCustomAttribute("unique", target:getUnique())
    end

So when you're creating a new item try to update item description.
Not sure where is that name eg. "legendary" in that upgrade system.

Code:
function Item.getRarity(self)
  return self:getCustomAttribute("rarity") and US_CONFIG.RARITY[self:getCustomAttribute("rarity")] or US_CONFIG.RARITY[COMMON]
end

based on this try to update item description with prefix thing:getRarity().name
Play around and try, thats what im doing most of the times. Add prints() so you can find what is stored in that getRarity().name for example.

There is no issue with item tooltip discussed here. I suggest you to create a new thread for this if you cant fix it youself.
'I suggest you to create a new thread for this if you cant fix it youself.', lol
I mean.. Thank you for the try to help with the problem in your comment but the last sentence is... ughm. if you don't want people to comment your thread when they experience an issue related to your feature then why even bother to post it on a forum, just keep it for yourself :SSS


I had troubles making the frames work with OEN's upgrade system for a while. If you use OENs revscript version then this may help. No idea whether this works 100% fine or has some glitches or not. I didn't test it throughly.
I just know that the below makes the feature work, possibly it needs further upgrades/development.

go to data/scripts/upgradesystem/core.lua

inside
LookEvent.onLook = function(player, thing, position, distance, description).
find:
else
description = description:gsub(thing:getName(), thing:getRarity().name .. " %1")
if thing:getArticle():len() > 0 and thing:getRarity().name == "epic" and thing:getArticle() ~= "an" then
description = description:gsub("You see (" .. thing:getArticle() .. "%S?)", "You see an")
end
and delete it (or add -- at beginning of each line).


And then find:
function Item.rollRarity(self)

and at the end, under
self:setRarity(rarity)
add:
if self:getArticle() ~= "" then
if self:getRarity().name == "epic" then
self:setAttribute(ITEM_ATTRIBUTE_ARTICLE, "an " .. self:getRarity().name)
else
self:setAttribute(ITEM_ATTRIBUTE_ARTICLE, "a " .. self:getRarity().name)
end
else
self:setAttribute(ITEM_ATTRIBUTE_ARTICLE, self:getRarity().name)
end

result:
1728930740649.webp
 
'I suggest you to create a new thread for this if you cant fix it youself.', lol
I mean.. Thank you for the try to help with the problem in your comment but the last sentence is... ughm. if you don't want people to comment your thread when they experience an issue related to your feature then why even bother to post it on a forum, just keep it for yourself :SSS


I had troubles making the frames work with OEN's upgrade system for a while. If you use OENs revscript version then this may help. No idea whether this works 100% fine or has some glitches or not. I didn't test it throughly.
I just know that the below makes the feature work, possibly it needs further upgrades/development.

go to data/scripts/upgradesystem/core.lua

inside

find:

and delete it (or add -- at beginning of each line).


And then find:


and at the end, under

add:


result:
View attachment 87684
Congratz that its working. However I see nothing wrong with my sentence but im sorry if i offended you :)
It's just that your issue is not completely related to this (since it was using customAttributes to set those rarity names).
I gladly offered my help. I just wanted to stay on topic of item tooltip and otcv8. Also i think you would receive a lot more views and help in a new thread related to that issue (Also was just a suggestion) :D. That's it, nothing personal ;) Cheers
 
Last edited:
With some changes it works perfectly, as advertised, but for it to be completely perfect, would it be possible to display the rarity attributes, from the special attributes system created by Mkalo


1730081454097.webp
 
With some changes it works perfectly, as advertised, but for it to be completely perfect, would it be possible to display the rarity attributes, from the special attributes system created by Mkalo


View attachment 87892
Adjust that system so it would directly update item:setDescription and it should work. Now its just onLook event that is showing that last line i guess.
Take a look at this resource as reference: [TFS 1.X] Rarity Rolls & Custom Attributes Library (https://otland.net/threads/tfs-1-x-rarity-rolls-custom-attributes-library.268888/)

This resource is also working with the tooltip.
 
'I suggest you to create a new thread for this if you cant fix it youself.', lol
I mean.. Thank you for the try to help with the problem in your comment but the last sentence is... ughm. if you don't want people to comment your thread when they experience an issue related to your feature then why even bother to post it on a forum, just keep it for yourself :SSS


I had troubles making the frames work with OEN's upgrade system for a while. If you use OENs revscript version then this may help. No idea whether this works 100% fine or has some glitches or not. I didn't test it throughly.
I just know that the below makes the feature work, possibly it needs further upgrades/development.

go to data/scripts/upgradesystem/core.lua

inside

find:

and delete it (or add -- at beginning of each line).


And then find:


and at the end, under

add:


result:
View attachment 87684
nice release thanks for sharing
 
Would it be possible to change this system of frames and tags so that they do not depend on "legendary/epic/rate" but on the attribute that would be added to the item? I would like to make such a rarity with a frame, but not change the name of the item
 
Would it be possible to change this system of frames and tags so that they do not depend on "legendary/epic/rate" but on the attribute that would be added to the item? I would like to make such a rarity with a frame, but not change the name of the item
yes
 
So, you did it wrong. I tested it with the old TFS 1.3 up to the most recent 1.6, and everything is working perfectly. Look at the image; I’m using TFS 1.4.2 (1098). I implemented the rarity system about a year ago.

View attachment 87575




Do you know how to display items in color? You can use Leo's or Oen's system to show rarity colors, or you can manually add it to items.xml by setting the name. For example, an 'Epic Magic Sword' can be shown in red for epic rarity, or you can just add 'epic' to the description. It needs to match the name on the OTClient. If it's 'epic', then you set it as 'epic'. If it's 'Epic', then you set it as 'Epic'. It depends on whether the name is lowercase or uppercase.

Leo

Oen
I manged to do everything with no errors using tfs 1.5 nekiro downgrade but but now Im getting
LUA:
ERROR: Unable to send extended opcode 201, extended opcodes are not enabled on this server.
 
Back
Top