• Vote in May Mapping Competition to select a winner!
  • 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!

[Suggestion] Lua-Generated Item Descriptions

GOOD?


  • Total voters
    25

Infernum

Asshole
Support Team
Joined
Feb 14, 2015
Messages
5,450
Best answers
540
Reaction score
3,290
Code: infernumx/forgottenserver (https://github.com/infernumx/forgottenserver/compare/master...infernumx:lua-item-desc)

There's still some room for improvement. I'm thinking about combining the "hasX" functions into one that returns the table with all the item type "flags" on it (boolean flags), would probably make it cleaner in the source code.

I tried to test a large chunk of items and compare them to the original description generated from Item::getDescription, I've found no discrepancies thus far between the two, it should perfectly mimic the exact same description you get from the original.

Obviously, I'll have to alter more of the code to make it like the original (support ItemType descriptions and utilize the Lua-generated description in playerOnLookInShop).

Pros:
  • Flexible for new custom attributes
  • Ability to easily alter the structure, order & layout of the text
  • Shorter code (I combined the generic attributes/abilities that were added on weapons/armor into 1 function, in C++ you had to manually edit both to add a new attribute to parse)
Cons:
  • Anybody who's added new attributes in Item::getDescription will have to re-do it (maybe make it configurable?)

What do you guys think?
 
Last edited:

Animera

* * * * *
Joined
Dec 9, 2008
Messages
2,360
Best answers
5
Reaction score
530
Location
ANIMERA.ONLINE
Really great job :), these days having a upgrade system(or other system that influences items) is like the standard for every OT. it makes no sense to mess with item descriptions to check if item has x description to get y condition...

These days we should have these functions by default in tfs. Even if it is just the sake of expanding the possibilities of features we can provide as game developers...

No need for the poll if you ask me!

Just out of curiousity how much slower is it? and why (i'm trying to learn more about performance efficienty)? sounds more logical that it is faster as it saves a lot of string manipulations/calculations? Or just thrown some benchmarks?

Might implement some day when i have the time, it will make my codes much cleaner XD.

Animera
 

zxmatzx

Intermediate OT User
Joined
Dec 1, 2010
Messages
263
Best answers
22
Reaction score
105
Nice release. I watched you write this code, I was thinking if you would release the code, as Animera said, with this, the upgrade systems will be much more cleaner. Thanks for sharing, your job here in Otland is great!
 
OP
Infernum

Infernum

Asshole
Support Team
Joined
Feb 14, 2015
Messages
5,450
Best answers
540
Reaction score
3,290
Really great job :), these days having a upgrade system(or other system that influences items) is like the standard for every OT. it makes no sense to mess with item descriptions to check if item has x description to get y condition...

These days we should have these functions by default in tfs. Even if it is just the sake of expanding the possibilities of features we can provide as game developers...

No need for the poll if you ask me!

Just out of curiousity how much slower is it? and why (i'm trying to learn more about performance efficienty)? sounds more logical that it is faster as it saves a lot of string manipulations/calculations? Or just thrown some benchmarks?

Might implement some day when i have the time, it will make my codes much cleaner XD.

Animera
It's more just basic experience being able to tell that this would be slightly slower. For example, I wrote a my own "StringStream" to make it easier to add strings to the description & build it, which is basically just a mask for string.format. Real string streams in C++ are faster and each value is manually concatenated rather than formatted using specifiers. I don't have a percentage for how much faster/slower it would be, like I said it's just that I can pretty much tell when something will be slightly more costly in terms of performance.

Nice release. I watched you write this code, I was thinking if you would release the code, as Animera said, with this, the upgrade systems will be much more cleaner. Thanks for sharing, your job here in Otland is great!
Yeah, most of it was written that day (took me 8 hours), the rest of this time I was just lazy to clean up, but eventually I did and made this thread.
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,718
Best answers
7
Reaction score
1,678
Location
Poland
if you manage to push needed getters into official tfs repo, I can help you doing the lua part
 

Yamaken

Pro OpenTibia Developer
Joined
Jul 27, 2013
Messages
495
Best answers
3
Reaction score
362
I think if we are able to move things to lua without huge hacks its always a improvement in the sense that its easier to read, fix, improve and most important customize the items descriptions. The only reason to keep it at engine/c++ was the easiness to read the item properties but then its not a excuse since the lua interface should have everything.
 

Evil Puncker

its just a flu
TFS Developer
Premium User
Joined
May 30, 2009
Messages
6,553
Best answers
73
Reaction score
2,258
awesome idea as usual
 
OP
Infernum

Infernum

Asshole
Support Team
Joined
Feb 14, 2015
Messages
5,450
Best answers
540
Reaction score
3,290
Added support for ItemType descriptions, removed the default support for onLookInShop and replaced it with the Lua-written description. The entirety of this should be finished, other than cleaning up some leftover unused C++ functions in favor of Lua, or maybe making it configurable and cleaning it up somehow to make it fitting for a PR.

Would be greatly appreciated if people could test this as well with me, I'm very skeptical that I made perfect code cause that almost never happens, I'm sure there has to be some item that has some error in formatting. All you gotta do is download the branch & compile and just look at a shit ton of different types of items to see if the description is screwed up or not.
 
OP
Infernum

Infernum

Asshole
Support Team
Joined
Feb 14, 2015
Messages
5,450
Best answers
540
Reaction score
3,290
Wrote a code snippet to parse every single item in items.xml and compare original + Lua-generated descriptions, every single item in the game is a confirmed match regardless of lookDistance. Updated the repo with the fixes.
 

Leo32

Getting back into it...
Premium User
Joined
Sep 21, 2007
Messages
950
Best answers
14
Reaction score
389
Wrote a code snippet to parse every single item in items.xml and compare original + Lua-generated descriptions, every single item in the game is a confirmed match regardless of lookDistance. Updated the repo with the fixes.
You happy enough with it to submit PR?
 

zxmatzx

Intermediate OT User
Joined
Dec 1, 2010
Messages
263
Best answers
22
Reaction score
105
You happy enough with it to submit PR?
I checked now, and don't found a PR to this and for sure its not merged, what has the problem? It will be not added to TFS? 🤔 😭
 
OP
Infernum

Infernum

Asshole
Support Team
Joined
Feb 14, 2015
Messages
5,450
Best answers
540
Reaction score
3,290
My problem is packaging it in a way that fits TFS currently for the current lib system.
 

Nemphis

Advanced OT User
Joined
Jun 22, 2009
Messages
471
Best answers
0
Reaction score
183
Location
Sweden
would be cool to use item sprites like outfits so you can make 10 different weapons that looks like spike sword with different attributes just like you can make 10000 monsters with the same face.
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,718
Best answers
7
Reaction score
1,678
Location
Poland
would be cool to use item sprites like outfits so you can make 10 different weapons that looks like spike sword with different attributes just like you can make 10000 monsters with the same face.
As long as they obey dat structure, it should be possible to do.
 

Nemphis

Advanced OT User
Joined
Jun 22, 2009
Messages
471
Best answers
0
Reaction score
183
Location
Sweden
yea. I mean.. you have items.xml right like normal, but then there could be a folder just like Monsters and you could make a lua for each weapon OR just have one additional .lua inside weapons folder and ypu can just add all normal stats a weapon has, like weight, attack, bonus defences, name and of course which weapon it should look like.
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,718
Best answers
7
Reaction score
1,678
Location
Poland
I opened an issue on github regarding that.
We might see something like that in distant future because it's a lot to rework and there are other big reworks going on already.
 
Top