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

C++ Trade with NPC, nekiro downgrade 1.5 8.0

Bee King

Active Member
Joined
May 9, 2024
Messages
69
Reaction score
25
Here’s the translation:




I am using TFS 1.5 downgrade 8.0 from nekiro, and I want to add the NPC trade option, where the modal window opens and makes buying/selling with them easier...


I found something related here, but it’s a bit vague. If someone has already implemented this and knows the path I should follow, please help me! I've been trying for some time now.


I’m using only OTC, so I won’t have issues with debugging on the client side.
 
Last edited:
Solution
Many people asked me how to add NPC trade for TFS 1.5 7.72 and 8.0 as well. So, I decided to do it in a simple way. Here's the commit—be happy and enjoy it for the OTland community!

Just ignore the NPC XML and Lua part; I was testing and forgot to remove it before committing. So, yes, just follow the NPC modules and the rest of the CPP and H files, and your NPC trade will be working fine! :D

1741310399928.webp1741310408566.webp
Here’s the translation:




I am using TFS 1.5 downgrade 8.0 from nekiro, and I want to add the NPC trade option, where the modal window opens and makes buying/selling with them easier...


I found something related here, but it’s a bit vague. If someone has already implemented this and knows the path I should follow, please help me! I've been trying for some time now.


I’m using only OTC, so I won’t have issues with debugging on the client side.
@Bee King hey man, did you manage to do it? A little help would be very much appreciated, and im sure i have some solutions i can share with you as well.
 
i dont feel like it's c++ code, it seems more like lua/otc code
Yeah it all seems to be in the TFS 1.5 source code to be honest. Feels like npc lib files that needs to be edited, but i tried nekiro 8.6 lib files and also tfs 1.4 but no success. I can get the npc to say "Of course, browse through my wares" when I say Trade, but no modal window popping up with the items..
 
Yeah it all seems to be in the TFS 1.5 source code to be honest. Feels like npc lib files that needs to be edited, but i tried nekiro 8.6 lib files and also tfs 1.4 but no success. I can get the npc to say "Of course, browse through my wares" when I say Trade, but no modal window popping up with the items..
do your npc have those attribute?
<parameter key="module_shop" value="1" />
<parameter key="shop_buyable" value="parcel,2595,15;letter,2597,10" />


I tried it with npc Deruno (default one from tfs by nekiro, 8.6)
1740516319898.webp
Im using ot client by menah tho
 
Last edited:
data/npc/lib/npcsystem/modules.lua

Line 28/29

Change whatever you have to TRADE
LUA:
    -- Used shop mode
    SHOPMODULE_MODE = SHOPMODULE_MODE_TRADE


Yeah man thanks, i missed that! Still get nothing when writing trade though.

Any pointers towards the source code edit too? Thanks a lot man appreciate it.
And was this the only npc libs edit needed?

@Sorky yeah tfs 1.5, 8.6 version has the correct commits in source code. I am using tfs1.5, protocol 7.7 mate :)
 
Yeah man thanks, i missed that! Still get nothing when writing trade though.

Any pointers towards the source code edit too? Thanks a lot man appreciate it.
And was this the only npc libs edit needed?

@Sorky yeah tfs 1.5, 8.6 version has the correct commits in source code. I am using tfs1.5, protocol 7.7 mate :)

Perhaps change it to
LUA:
SHOPMODULE_MODE = SHOPMODULE_MODE_BOTH
 
Perhaps change it to
LUA:
SHOPMODULE_MODE = SHOPMODULE_MODE_BOTH
Tried it, doesnt work mate. But yeah that needs to be config:ed as well for sure.

I need the source edits. I saw @Error 502 posting the solution partly in another thread, i tried my very best to do what he said but I did not get it to work. :/ involves protocolgame.cpp and .h and some other source edits.
 
Many people asked me how to add NPC trade for TFS 1.5 7.72 and 8.0 as well. So, I decided to do it in a simple way. Here's the commit—be happy and enjoy it for the OTland community!

Just ignore the NPC XML and Lua part; I was testing and forgot to remove it before committing. So, yes, just follow the NPC modules and the rest of the CPP and H files, and your NPC trade will be working fine! :D

1741310399928.webp1741310408566.webp
 
Last edited:
Solution
Many people asked me how to add NPC trade for TFS 1.5 7.72 and 8.0 as well. So, I decided to do it in a simple way. Here's the commit—be happy and enjoy it for the OTland community!

Just ignore the NPC XML and Lua part; I was testing and forgot to remove it before committing. So, yes, just follow the NPC modules and the rest of the CPP and H files, and your NPC trade will be working fine! :D

View attachment 90782View attachment 90784
1741317132569.webp

I have a problem with the cap, otclient is not recognizing the correct capacity. I'm using TFS 1.5 downgrade nekiro 772!


OTClientv8/invetory.lua
LUA:
function onFreeCapacityChange(player, freeCapacity)
  if not freeCapacity then return end
  if freeCapacity > 99 then
    freeCapacity = math.floor(freeCapacity * 10) / 10
  end
  if freeCapacity > 999 then
    freeCapacity = math.floor(freeCapacity)
  end
  if freeCapacity > 99999 then
    freeCapacity = math.min(9999, math.floor(freeCapacity/1000)) .. "k"
  end
  capLabel:setText(tr('Cap') .. ':\n' .. freeCapacity * 100)
end

protocolgame.cpp
C++:
    msg.add<uint16_t>(player->getFreeCapacity() / 100);
 
View attachment 90786

I have a problem with the cap, otclient is not recognizing the correct capacity. I'm using TFS 1.5 downgrade nekiro 772!


OTClientv8/invetory.lua
LUA:
function onFreeCapacityChange(player, freeCapacity)
  if not freeCapacity then return end
  if freeCapacity > 99 then
    freeCapacity = math.floor(freeCapacity * 10) / 10
  end
  if freeCapacity > 999 then
    freeCapacity = math.floor(freeCapacity)
  end
  if freeCapacity > 99999 then
    freeCapacity = math.min(9999, math.floor(freeCapacity/1000)) .. "k"
  end
  capLabel:setText(tr('Cap') .. ':\n' .. freeCapacity * 100)
end

protocolgame.cpp
C++:
    msg.add<uint16_t>(player->getFreeCapacity() / 100);
this if if if statements is kidna wierd because with 100k cap it will go throught each of them
It will divide in first, go to second and then to third to add k.
LUA:
  if freeCapacity > 99999 then
    freeCapacity = math.min(9999, math.floor(freeCapacity / 1000)) .. "k"
  elseif freeCapacity > 999 then
    freeCapacity = math.floor(freeCapacity)
  elseif freeCapacity > 99 then
    freeCapacity = math.floor(freeCapacity * 10) / 10
  end
replace with it
 
this if if if statements is kidna wierd because with 100k cap it will go throught each of them
It will divide in first, go to second and then to third to add k.
LUA:
  if freeCapacity > 99999 then
    freeCapacity = math.min(9999, math.floor(freeCapacity / 1000)) .. "k"
  elseif freeCapacity > 999 then
    freeCapacity = math.floor(freeCapacity)
  elseif freeCapacity > 99 then
    freeCapacity = math.floor(freeCapacity * 10) / 10
  end
replace with it
This is the default form of OTClientv8, I don't know why to write the code this way. My problem is how the trade module is "reading" the cap information. It is not in the correct form of the player's capacity :(
 
this if if if statements is kidna wierd because with 100k cap it will go throught each of them
It will divide in first, go to second and then to third to add k.
LUA:
  if freeCapacity > 99999 then
    freeCapacity = math.min(9999, math.floor(freeCapacity / 1000)) .. "k"
  elseif freeCapacity > 999 then
    freeCapacity = math.floor(freeCapacity)
  elseif freeCapacity > 99 then
    freeCapacity = math.floor(freeCapacity * 10) / 10
  end
replace with it
Not work

LUA:
function onFreeCapacityChange(player, freeCapacity)
  if not freeCapacity then return end
  if freeCapacity > 99999 then
    freeCapacity = math.min(9999, math.floor(freeCapacity / 1000)) .. "k"
  elseif freeCapacity > 999 then
    freeCapacity = math.floor(freeCapacity)
  elseif freeCapacity > 99 then
    freeCapacity = math.floor(freeCapacity * 10) / 10
  end
  capLabel:setText(tr('Cap') .. ':\n' .. freeCapacity * 100)
end

I think the problem is in npctrade.lua
 
Last edited:
Not work

LUA:
function onFreeCapacityChange(player, freeCapacity)
  if not freeCapacity then return end
  if freeCapacity > 99999 then
    freeCapacity = math.min(9999, math.floor(freeCapacity / 1000)) .. "k"
  elseif freeCapacity > 999 then
    freeCapacity = math.floor(freeCapacity)
  elseif freeCapacity > 99 then
    freeCapacity = math.floor(freeCapacity * 10) / 10
  end
  capLabel:setText(tr('Cap') .. ':\n' .. freeCapacity * 100)
end

I think the problem is in npctrade.lua
you need to share it, i don't have your scripts :D
 
Our friend Mateus Roberto will fix this soon... but let's be patient, after all, it's help without financial return hahaha. When he has some free time, he will definitely do it, don't worry, my friend... in the meantime, tell the players to select the "ignored cap" option in the trade modal.
 
Many people asked me how to add NPC trade for TFS 1.5 7.72 and 8.0 as well. So, I decided to do it in a simple way. Here's the commit—be happy and enjoy it for the OTland community!

Just ignore the NPC XML and Lua part; I was testing and forgot to remove it before committing. So, yes, just follow the NPC modules and the rest of the CPP and H files, and your NPC trade will be working fine! :D

View attachment 90782View attachment 90784

actual legend.. it works. thanks!!!
 
Back
Top