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

OTClient Item::getId() in OTCV8 returns different id than the server

kuhi

Premium User
Premium User
Joined
Aug 26, 2012
Messages
200
Solutions
1
Reaction score
81
Location
x64dbg
GitHub
Kuhicop
Hey :)

I'm using this code trying to get the item id like in the server (meat == 2666) but I get id 3577 instead:
Lua:
for i, container in pairs(g_game.getContainers()) do    
    local container_items = container:getItems()
    for j, item in pairs(container_items) do  
        print("Fond item in container: " .. item.getId())
    end
end

For the name I'm calling getName() but it prints an empty string.
I don't really want to query everytime I check an item to the server, even building a cache it's something I don't really like...

If I check with cheat engine, and I inspect an item pointer, I can see the correct itemid in the offset 0x2C, aswell as the count in the offset 0x30 and that is for almost every otclient, so that's a proof that the real item id is already cached in the client...

If I check with the GM, I can confirm the correct id for the item is 2666:
09:28 You see meat.
It weighs 52.00 oz.
Item ID: 2666
Position: 95, 124, 7

Trying to print(json.encode(item)) the Item object to see which properties or members I can use I'm getting this error:
ERROR: lua function callback failed: /modules/corelib/json.lua:148: unexpected type 'userdata'

Can someone throw directions?

Thanks <3
 
Last edited:
check if you have a function in your tfs

Lua:
itemtype:getClientId()

usage:
Lua:
local itemType = ItemType(itemid)
local clientId = itemType:getClientId()
 
Hi, thanks for your reply.

It is otclient, not tfs

Based on the code I will get the same results:
C++:
uint32 getId() { return m_clientId; }
uint16 getClientId() { return m_clientId; }

Tested to confirm:
Lua:
local itemType = ItemType(food:getId())
local clientId = itemType:getClientId()

Results:
ERROR: lua function callback failed: autoeat.lua:40: attempt to call global 'ItemType' (a table value)

Looks like I cannot invoke an ItemType with that freestyle :(

Testing it with item object:
Lua:
local clientId = food:getClientId()

attempt to call method 'getClientId' (a nil value)

And as I got to the conclusion that I had to use getId() by checking the client code, I just checked by website (I thought I did this already) and I can see that meat has itemid 3577 so the client already had the correct itemid.

The problem is on the server that it's displaying another itemid... and as I'm doing an OTCV8 module I don't care about the server :)
 
Yes but I don't want the server id I want the "official" item id that everyone can find online: Item ID List (https://tibiaitemid.blogspot.com/2010/10/item-id-list.html)

That's why... :)

I would use getServerId() function instead for the server id (which returns empty like getName() and it's not the case)

Now I can save a copy of all ids + name and build my getName() function :)

Be careful with creating a list. This serverid vs. clientid may change and your module would not be compatible, working only on a specific server.
This may change due items.otb from server side, and then your module is not going to work on some server that had editted it (very commom to happen).

By getting the message from your error, I can understand that you are doing an autoeat for a bot module. If this is the case, you should make an easy way to the player fill this information. vBot did that by dragging and drop the item from the game to the module, this way the module can grab the clientId and search for it later.

By any way that you grab the item client id, you will need to search on player inventory/map, then after the search and if it founds the item, it will also have all the items references (which basically is the item location) and then send the packet "use the item from location x, y, z)" to server.

Client has no use for serverId, thats why it does not have it there
 
Be careful with creating a list. This serverid vs. clientid may change and your module would not be compatible, working only on a specific server.
This may change due items.otb from server side, and then your module is not going to work on some server that had editted it (very commom to happen).

By getting the message from your error, I can understand that you are doing an autoeat for a bot module. If this is the case, you should make an easy way to the player fill this information. vBot did that by dragging and drop the item from the game to the module, this way the module can grab the clientId and search for it later.

By any way that you grab the item client id, you will need to search on player inventory/map, then after the search and if it founds the item, it will also have all the items references (which basically is the item location) and then send the packet "use the item from location x, y, z)" to server.

Client has no use for serverId, thats why it does not have it there
Hi, you're right it's a bot module

If they change it in server side I don't really care because I'm on client side, and I'm dealing with client ids not server ids, I guess that's inside tibia.dat file

I already have Item ui "code handlers" taken from the hotkeys panel in the select/clear item section. So I can select items, render and stuff...

It's a nice idea as an extra tool, but my idea is to have a settings file which comes with a predefined table of configs, in this case the food items.
So if the client doesn't change it works by default without any setup required. If the food id changes because of the client version, I can always edit the settings.json and even select a custom settings.json on runtime. And as a player I won't need to loot the item to be able to setup the bot.

You gave me a good idea, I will implement a little panel to select an item and view the id for custom ots so I can edit the settings fast ;)

PS: I would like to make clear that I will not be releasing this bot, I made several bots using different methods: memory, packets, lua
There is a lot of those in my github
This is just another trainning session to learn new things trying new methods :)
 
Last edited:
Back
Top