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

TFS 1.X+ NPC system tfs 1.4 doNpcTalkAlot

Itutorial

Excellent OT User
Joined
Dec 23, 2014
Messages
2,307
Solutions
68
Reaction score
982
So this cannot be used in a greetcallback function. It has to be used in only the creatureSayCallback is there a way to fix that? I will look at it later but I am working now. Hoping someone has a quick solution. Thanks.


Doesn't work.
Lua:
local function greetCallback(cid)
      npcHandler:doNPCTalkALot(msg, 6000, cid)
end

Works
Lua:
local function creatureSayCallback(cid, type, msg)
     npcHandler:doNPCTalkALot(msg, 6000, cid)
end

I am assuming its because the npcHandler isnt created until after the greetcallback is executed.
 
Its not useless if you know how the npc system works I would imagine.

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

local voices = { {text = "Best weapons in Noob'Vale. Come check them out!"} }
npcHandler:addModule(VoiceModule:new(voices))

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

local ratMsg = {
    "Rats have infested the town's water supply. They are jumping down the well just south of my shop.",
    "They are contaminating everything and have even destroyed some of my supplies. Go deal with the pests and I will reward you with some coin."
}

local function greetCallback(cid)
    local player = Player(cid)
    if not player then return true end
  
    local pQuest = player:getStorageValue(STORAGE_MAINQUEST)
  
    if pQuest < 2 then
        selfSay('Hello there, what brings you to my shop today? {trade}, {quest}', cid)
    elseif pQuest == 2 then
        selfSay("Please help me, they have taken my daughter! {who}", cid)
    elseif pQuest == 3 then
        selfSay("Any news on where my daughter is or do you need a {trade}?", cid)
    end
  
    return true
end

keywordHandler:addKeyword({'stuff'}, StdModule.say, {npcHandler = npcHandler, text = 'Just ask me for a {trade} to see my offers.'})
keywordHandler:addAliasKeyword({'wares'})
keywordHandler:addAliasKeyword({'offer'})

shopModule:addBuyableItem({'sword', 'sword'}, 2376, 20, 'sword')
shopModule:addBuyableItem({'hatchet', 'hatchet'}, 2388, 20, 'hatchet')
shopModule:addBuyableItem({'dagger', 'dagger'}, 2379, 10, 'dagger')
shopModule:addBuyableItem({'naginata', 'naginata'}, 2426, 30, 'naginata')
shopModule:addBuyableItem({'spear', 'spear'}, 2389, 20, 'spear')
shopModule:addBuyableItem({'sabre', 'sabre'}, 2385, 45, 'sabre')

-- shopModule:addSellableItem({'wand of vortex', 'vortex'}, 2190, 250, 'wand of vortex')

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    if not player then return true end
  
    if msg == "quest" then
        local pQuest = player:getStorageValue(STORAGE_MAINQUEST)
      
        if pQuest == -1 then
            player:setStorageValue(STORAGE_MAINQUEST, 0)
        end
      
        if pQuest == 0 then
            npcHandler:doNPCTalkALot(ratMsg, 4000, cid)
            player:setStorageValue(STORAGE_MAINQUEST, pQuest + 1)
            return true
        elseif pQuest == 1 then
            selfSay("Kill some rats in the draw well located just south of my shop. Your quest log will be updated when you have finished.", cid)
            return true
        elseif pQuest == 2 then
            selfSay("Please help me, they have taken my daughter! {who}", cid)
            player:setStorageValue(STORAGE_MAINQUEST, pQuest + 1)
            return true
        elseif pQuest == 3 then
            selfSay("You should talk to some of the people around town to see if they saw anything.", cid)
            return true
        end
      
    elseif msg == "who" then
        local pQuest = player:getStorageValue(STORAGE_MAINQUEST)
        if pQuest == 2 then
            player:addMoney(35)
            selfSay("First, here is some money for killing those rats. You should try {talk}ing {to Suzie}. Her balcony oversees the city.", cid)
            player:setStorageValue(STORAGE_MAINQUEST, pQuest + 1)
        elseif pQuest > 2 and pQuest < 4 then
            selfSay("You should talk to some of the people around town to see if they saw anything.", cid)
            return true
        end
      
      
      
      
    end
    return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

The main part it:
Lua:
local function greetCallback(cid)
    local player = Player(cid)
    if not player then return true end
  
    local pQuest = player:getStorageValue(STORAGE_MAINQUEST)
  
    if pQuest < 2 then
        selfSay('Hello there, what brings you to my shop today? {trade}, {quest}', cid)
    elseif pQuest == 2 then
        selfSay("Please help me, they have taken my daughter! {who}", cid)
    elseif pQuest == 3 then
        selfSay("Any news on where my daughter is or do you need a {trade}?", cid)
    end
  
    return true
end

doTalkAlot doesn't work in the greetCallBack. The NPC wont say anything but selfSay() works.

Lua:
function creatureSayCallback(cid, type, msg)

In the creatureSayCallback doTalkAlot does work. So I am assuming the npcHandler isn't created until after the greetCallback is executed.

That is all the information there is.

It seems like local npcHandler = NpcHandler:new(keywordHandler) should create the npcHandler before the player ever even talks to the npc. It should generate it at server start up but still doTalkAlot doesn't work in the greetCallback.
 
NpcHandler is handling greet callback so... There can't be situation where NpcHandler is not available inside that callback.
 
Yeah, just the same as the rest of the code which works fine.

Lua:
npcHandler:doNPCTalkALot(stringTable, interval, cid)
 
Back
Top