• 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+ Add Greet Massage to NPC

kibo433

Member
Joined
Sep 6, 2010
Messages
34
Solutions
1
Reaction score
14
Hi. I use TFS 1.5 downgrade by Nekiro to 8.0. I would like to add new greet and farewell keyword to npc like elves (ashari, asha thrazi). This is my npc.lua
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



keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, text = 'Have you moved to a new home? I\'m the specialist for equipping it.'})
keywordHandler:addKeyword({'offer'}, StdModule.say, {npcHandler = npcHandler, text = 'I sell statues, tables, chairs, flowers, pillows, pottery, instruments, decorations, tapestries, and containers.'})

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

shopModule:addBuyableItem({"heart pillow"}, 1685, 30, "heart pillow")


local focusModule = FocusModule:new()
focusModule:addGreetMessage({'hi', 'hello', 'ashari'})
focusModule:addFarewellMessage({'bye', 'farewell', 'asha thrazi'})
npcHandler:addModule(focusModule)


npcHandler:setMessage(MESSAGE_GREET, "Ashari, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_FAREWELL, "Asha Thrazi.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Asha Thrazi.")
npcHandler:setMessage(MESSAGE_DECLINE, "Hmm, but next time.")

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())


NPC is not loaded when starting the engine. This error appears:
Lua Script Error: [Npc interface]
data/npc/scripts/ukea.lua
data/npc/scripts/ukea.lua:22: attempt to call method 'addGreetMessage' (a nil value)
stack traceback:
[C]: in function 'addGreetMessage'
data/npc/scripts/ukea.lua:22: in main chunk
[Warning - NpcScript::NpcScript] Can not load script: ukea.lua

When I used downgrade version to 8.6, it worked ok. I was trying to do it with this method:
Code:
keywordHandler:addGreetKeyword({'charach'}, {npcHandler = npcHandler, text = 'Ikem Charach maruk.'})
keywordHandler:addFarewellKeyword({'futchi'}, {npcHandler = npcHandler, text = 'Futchi!'})
but also to no avail.

Secondly, any of my NPCs react to DECLINE message changes. All other message changes like GREET, FAREWELL, WALKAWAY etc work fine, except this one.
 
OK. I solved it. I didn't notice that I have pasted to modules.lua this fragment of code in my TFS 1.5 downgrade to 8.6 :D. If we want to change greet message and farewell message our npc like a post above, we must paste it in our modules.lua
LUA:
    -- Set custom greeting messages
    function FocusModule:addGreetMessage(message)
        if not self.greetWords then
            self.greetWords = {}
        end

        if type(message) == 'string' then
            table.insert(self.greetWords, message)
        else
            for i = 1, #message do
                table.insert(self.greetWords, message[i])
            end
        end
    end

    -- Set custom farewell messages
    function FocusModule:addFarewellMessage(message)
        if not self.farewellWords then
            self.farewellWords = {}
        end

        if type(message) == 'string' then
            table.insert(self.farewellWords, message)
        else
            for i = 1, #message do
                table.insert(self.farewellWords, message[i])
            end
        end
    end

    -- Set custom greeting callback
    function FocusModule:setGreetCallback(callback)
        self.greetCallback = callback
    end

    -- Set custom farewell callback
    function FocusModule:setFarewellCallback(callback)
        self.farewellCallback = callback
    end

As for the DECLINE message, we need to change in our modules.lua in
function ShopModule.onDecline from this:

LUA:
        local msg = module.npcHandler:parseMessage(module.noText, parseInfo)
        module.npcHandler:say(msg, cid)
        module.npcHandler:resetNpc(cid)
        return true

to this:

LUA:
        local msg = module.npcHandler:getMessage(MESSAGE_DECLINE)
        msg = module.npcHandler:parseMessage(msg, parseInfo)
        module.npcHandler:say(msg, cid)
        module.npcHandler:resetNpc(cid)
        return true
 

Similar threads

Back
Top