• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Linux NPC trade onLoock/onTarget

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,764
Solutions
1
Reaction score
227
Location
Chile, Santiago
Hello there,

It is possible to open the trade window (if the NPC has it) when player take a look (at battle, or ingame window) or when he attacks/target the NPC?

If you got any idea, please post here to build this ;)

Would be pretty nice ;)

Bump!
 
Last edited by a moderator:
yes its possible, i assume you're using tfs 1 since you dont said what it is.
https://github.com/otland/forgottenserver/blob/master/data/events/scripts/player.lua#L5
you can try something like if isNpc(thing) then npcHandlethings.

Yeah I tried to do around there... But don't know how to make the NPC focus on you and then open the tradewindow.

Also found this function:

Code:
openShopWindow(cid, tradeItems, onBuy, onSell)

Which could help, but still no clue on how to focus the NPC by targeting/looking it.
 
Yeah I tried to do around there... But don't know how to make the NPC focus on you and then open the tradewindow.
focus and trade window are the less of your problem to this.
Code:
if isNpc(thing) then
   local npc = Npc(thing)
   npc:setFocus(self)
   npc:openShopWindow(self, {'health potion'}, buyCallback, sellCallback)
end
your problem is figure out the npcHandle and make it work, i'd start with npcHandler:eek:nCreatureSay().
 
Maybe player could self say hi, then trade.... Would be a nasty idea but would work.

---
Tested this idea with self:say("hi", TALKTYPE_SAY) and works... Now looking for a way to say trade on the NPC channel.

Found this:

Code:
registerEnum(TALKTYPE_SAY)
registerEnum(TALKTYPE_WHISPER)
registerEnum(TALKTYPE_YELL)
registerEnum(TALKTYPE_PRIVATE_FROM)
registerEnum(TALKTYPE_PRIVATE_TO)
registerEnum(TALKTYPE_CHANNEL_Y)
registerEnum(TALKTYPE_CHANNEL_O)
registerEnum(TALKTYPE_PRIVATE_NP)
registerEnum(TALKTYPE_PRIVATE_PN)
registerEnum(TALKTYPE_BROADCAST)
registerEnum(TALKTYPE_CHANNEL_R1)
registerEnum(TALKTYPE_PRIVATE_RED_FROM)
registerEnum(TALKTYPE_PRIVATE_RED_TO)
registerEnum(TALKTYPE_MONSTER_SAY)
registerEnum(TALKTYPE_MONSTER_YELL)
registerEnum(TALKTYPE_CHANNEL_R2)

Made this work:

Code:
function Player:onLook(thing, position, distance)

    if isNpc(thing) then
      local npc = Npc(thing)
      if distance <= 3 then
        self:say("hi", TALKTYPE_SAY)
       
        --self:say("trade", ????)
      end

...
end

So the question would be how to make the player say "trade" at NPC channel?
 
Last edited by a moderator:
self:channelSay(speaker, type, text, channelId)

Actually managed to use this code:

Code:
self:say("hi", TALKTYPE_PRIVATE_NP)

But I think it should wait a few moments till he says trade again. How could add like a "sleep" value? Tried to add an event with the function, but didn't work.
 
Actually managed to use this code:

Code:
self:say("hi", TALKTYPE_PRIVATE_NP)

But I think it should wait a few moments till he says trade again. How could add like a "sleep" value? Tried to add an event with the function, but didn't work.
show how you tried to use addevent
 
addEvent(self.say, 500, 'trade', TALKTYPE_PRIVATE_NP)
pretty sure you cant use the : in addevent cause it expects arguments for the method right after

Somehow doesn't work too... Btw it shouldn't be a problem the "sleep" time since if you say "hi trade" and then "hi trade" it will still work and open trade window (as people do on RL).
 
Somehow doesn't work too... Btw it shouldn't be a problem the "sleep" time since if you say "hi trade" and then "hi trade" it will still work and open trade window (as people do on RL).
you could try that chat metable that i said, another elegant way to solve this also is using NetworkMessage, so players wouldnt see the text messages.
 
use this way instead of others:
Code:
addEvent(doCreatureSay, 500, self:getId(), "trade", TALKTYPE_PRIVATE_NP)
because sending userdata as parameters with addevent is unsafe
 
you could try that chat metable that i said, another elegant way to solve this also is using NetworkMessage, so players wouldnt see the text messages.

Could you post your solution? Cause it is just working with the hi, the trade word is not being answered by the NPC.
 
Could you post your solution? Cause it is just working with the hi, the trade word is not being answered by the NPC.
i dont have any solution was just a idea, if you want to do that you need to figure out and try out a replica of this peices to lua
https://github.com/otland/forgottenserver/blob/master/src/protocolgame.cpp#L1458-L1473
https://github.com/otland/forgottenserver/blob/master/src/protocolgame.cpp#L3013-L3028
client perspective
https://github.com/edubart/otclient/blob/master/src/client/protocolgameparse.cpp#L948-L978
 
Last edited:
For some reason, just the hi works:

Code:
18:41 GM Joan: hi
18:41 Nahlesar: Greetings, GM Joan.
18:41 GM Joan: trade

Using actually:

Code:
    if isNpc(thing) then
      local npc = Npc(thing)
      if distance <= 3 then
        self:say("hi", TALKTYPE_PRIVATE_NP)
        addEvent(doCreatureSay, 1500, self:getId(), "trade", TALKTYPE_PRIVATE_NP)
       
    end
 
then change in npc/lib/npcsystem/npchandler.lua
"if self:isFocused(cid) and msgtype == TALKTYPE_PRIVATE_PN or not self:isFocused(cid) then"
for
"if self:isFocused(cid) and (msgtype == TALKTYPE_PRIVATE_PN or msgtype == TALKTYPE_PRIVATE_NP) or not self:isFocused(cid) then"
and it should work for TALKTYPE_PRIVATE_NP
 
Back
Top