Hello everybody,
I have this problem with all of my NPCs, and would really like to fix it. I am putting the simplest NPC I got.
The problem is as follows:
If I run the code shown below, the NPC is able to do everything specified in this code, EXCEPT for what is inside the onThinkCallback() function. So basically the NPC does not talk or say any of the two messages specified. It just waits for a player to normally greet him.
Now, if I change that function to onThink() (just removing the "Callback" part), the NPC is now able to talk and display any of the two messages, BUT now the NPC does not seem to execute the npcHandler messages for MESSAGE_WALKAWAY and MESSAGE_IDLETIMEOUT. Basically, the player can walk far away from the NPC without saying "bye", and the NPC will stay focused!!
I would really like to have both of these working, but after several trial and errors I ended up having no idea what should I do. Can anybody help me and tell me what is wrong? I would really appreciate it!
Thank you!
I am using TFS 0.2.14 (Mystic)
I have this problem with all of my NPCs, and would really like to fix it. I am putting the simplest NPC I got.
The problem is as follows:
If I run the code shown below, the NPC is able to do everything specified in this code, EXCEPT for what is inside the onThinkCallback() function. So basically the NPC does not talk or say any of the two messages specified. It just waits for a player to normally greet him.
Now, if I change that function to onThink() (just removing the "Callback" part), the NPC is now able to talk and display any of the two messages, BUT now the NPC does not seem to execute the npcHandler messages for MESSAGE_WALKAWAY and MESSAGE_IDLETIMEOUT. Basically, the player can walk far away from the NPC without saying "bye", and the NPC will stay focused!!
I would really like to have both of these working, but after several trial and errors I ended up having no idea what should I do. Can anybody help me and tell me what is wrong? I would really appreciate it!
Thank you!
I am using TFS 0.2.14 (Mystic)
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function onPlayerEndTrade(cid) npcHandler:onPlayerEndTrade(cid) end
function onPlayerCloseChannel(cid) npcHandler:onPlayerCloseChannel(cid) end
--------------------------------------------------------------------
local talk = {}
local num = 0
local messages =
{
[1] = "Que estupendo dia para pescar!",
[2] = "Espero pescar un tiburon!"
}
------------------------------------------------------------------
local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
shopModule:addBuyableItem({'fishing rod'}, 2580, 32, 'fishing rod')
shopModule:addBuyableItem({'fish'}, 2667, 8, 'fish')
------------------------------------------------------------------
npcHandler:setMessage(MESSAGE_GREET, 'Buenasss |PLAYERNAME|!!')
npcHandler:setMessage(MESSAGE_FAREWELL, 'Adios |PLAYERNAME|!!')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Mmm, adios!')
npcHandler:setMessage(MESSAGE_IDLETIMEOUT, 'Mmmm, te quedaste mudo?')
npcHandler:setMessage(MESSAGE_SENDTRADE, 'Te puedo vender una cana de pescar para que te unas a tan apasionante deporteeee! Lo que si es que te faltarian los gusanitos de carnada.. no te pienso dar los mios!')
npcHandler:setMessage(MESSAGE_ONCLOSESHOP, 'Jejeje graciasss!')
-------------------------------------------------------------------
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
talk[cid] = talk[cid] or 0
if talk[cid] == 0 and (msgcontains(msg, "info") or msgcontains(msg, "news")) then
selfSay("Esta es la playa, y mi hobbie en ella es, por supuesto, pasarmela aqui de pesca. :)", cid)
return true
end
if talk[cid] == 0 and (msgcontains(msg, "quest") or msgcontains(msg, "mission")) then
selfSay("Yo no necesito nada, gracias!", cid)
return true
end
if talk[cid] == 0 and msgcontains(msg, "job") then
selfSay("Soy un pescador apasionado!", cid)
return true
end
return true
end
------*************************************************************************************-------------
function onThinkCallback()
num = num + 1
if num >= math.random(25, 30) then
local random = math.random(1, #messages)
doCreatureSay(getNpcCid(), messages[random], TALKTYPE_SAY)
num = 0
end
return true
end
------*************************************************************************************-------------
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Last edited: