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

CreatureEvent onLook Interact with NPC

Joe Rod

Discord: joerod1
Joined
Mar 16, 2011
Messages
499
Solutions
2
Reaction score
172
GitHub
joerod1
Hi guys, with this you would greet the npc and open its shop (if has)
It works on directly look and look on battlelist
This is really simple, but someone could find it useful



data/events/scripts/player.lua

at the beginning of file paste this
Code:
local minDist = 5 --this will be the min distance required to interact

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

paste this below that:
Code:
    if (thing:isCreature() and thing:isNpc() and distance <= minDist) then
       self:say("hi", TALKTYPE_PRIVATE_PN, false, thing)
       self:say("trade", TALKTYPE_PRIVATE_PN, false, thing)
       return false   
   end


find
Code:
function Player:onLookInBattleList(creature, distance)

paste this below that:
Code:
    if (creature:isNpc() and distance <= minDist) then
       self:say("hi", TALKTYPE_PRIVATE_PN, false, creature)
       self:say("trade", TALKTYPE_PRIVATE_PN, false, creature)
       return false   
   end

tested on OTX, it will work on TFS 1.x i guess
 
It would be pretty cool if, your 6 tiles away, and you look at NPC it says "You ese NPC. Get closer to talk to NPC"
 
It would be pretty cool if, your 6 tiles away, and you look at NPC it says "You ese NPC. Get closer to talk to NPC"
idk why i can't edit main post :/


replace
Code:
if (thing:isCreature() and thing:isNpc() and distance <= minDist) then

to
Code:
if (thing:isCreature() and thing:isNpc()) then
       if (distance > minDist) then
           self:sendTextMessage(MESSAGE_STATUS_SMALL, "Get closer to talk to NPC.")
           return false
       end

now replace
Code:
if (creature:isNpc() and distance <= minDist) then

to
Code:
if (creature:isNpc()) then
       if (distance > minDist) then
           self:sendTextMessage(MESSAGE_STATUS_SMALL, "Get closer to talk to NPC.")
           return false
       end
 
Wrong board but thanks for the release anyways.
 
Because this post belongs here C++ Codes

****SMACKS FACE*****

I'm sorry man. I guess I just assumed without reading that you implemented this the same way you did your onTarget interact with NPC. For that I apologize. This is exactly where this code belongs!

Thanks for the great release! And never mind me...
 
Back
Top