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

Solved [TFS 1.2] NPC quest problem

xardas33

New Member
Joined
Jan 28, 2010
Messages
83
Reaction score
0
Hello. I have problem with my NPC. When i trying to say 'notebook', I getting console errors (same problem when saying 'backpack addon')... I don't know how to fix it.

I using TFS 1.2 under 10.98 client.

Error:
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/Amber.lua:onCreatureSay
data/npc/scripts/Amber.lua:18: attempt to index global 'player' <a nil value>
stack traceback:
     [C]: in function '___index'
     data/npc/scripts/Amber.lua:18: in function 'callback'
     data/npc/lib/npcsystem/npchandler.lua:411: in function 'onCreatureSay'
     data/npc/scripts/Amber.lua:7: in function <data/npc/scripts/Amber.lua:7>


Amber.lua
Code:
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 function creatureSayCallback(cid, type, msg)
   if not npcHandler:isFocused(cid) then
       return false
   end
   
   if msgcontains(msg, "quest") then
       npcHandler:say("I left my raft at the south-eastern shore. I forgot my private {notebook} on it. If you could return it to me, I would be very grateful.", cid)
   elseif msgcontains(msg, "notebook") then
       if player:getStorageValue(50005) <= 1 then
           npcHandler:say("Do you bring me my notebook?", cid)
           npcHandler.topic[cid] = 1
       else
           npcHandler:say("I already have my notebook.", cid)
       end
       
   elseif npcHandler.topic[cid] == 1 then
       if msgcontains(msg, "yes") then
           if player:getItemCount(cid, 1955) >= 1 then
               player:removeItem(cid, 1955, 1)
               player:addItem(cid, 2406, 1)
               player:setStorageValue(50005, 2)
               npcHandler:say("Excellent. Here, take this short sword as a reward.", cid)
               npcHandler.topic[cid] = 0
           else
               npcHandler:say("Mhm, whatever you have there, it is not my notebook", cid)
               npcHandler.topic[cid] = 0
           end
       else
           npcHandler:say("Too bad.", cid)
           npcHandler.topic[cid] = 0
       end
   end
   
   if msgcontains(msg, "backpack addon") then
       if player:getStorageValue(52000) > 1 then
           npcHandler:say("It seems you already have this addon, don't you try to mock me son!", cid)
       elseif isPremium(cid) == false then
           npcHandler:say("Sorry, but they are only for premium customers", cid)
       elseif isPremium(cid) == true then
           if player:getStorageValue(52000) < 1 then
               npcHandler:say("Ah, you noticed my new accessory? Sorry, this one is not for sale. It's handmade from rare {minotaur} {leather}.", cid)
               npcHandler.topic[cid] = 2
           elseif player:getStorageValue(52000) == 1 then
               npcHandler:say("Ah, right, almost forgot about the backpack! Have you brought me 100 pieces of minotaur leather as requested?", cid)
               npcHandler.topic[cid] = 4
           else
               npcHandler:say("It seems you already have this addon, don't you try to mock me son!", cid)
           end
       end
       
   elseif npcHandler.topic[cid] == 2 then
       if msgcontains(msg, "minotaur leather") then
           npcHandler:say("Well, if you really like this backpack, I could make one for you, but minotaur leather is hard to come by these days. Are you willing to put some work into this?", cid)
           npcHandler.topic[cid] = 3
       end
       
   elseif npcHandler.topic[cid] == 3 then
       if msgcontains(msg, "yes") then
           player:setStorageValue(52000, 1)
           npcHandler:say("Alright then, if you bring me 100 pieces of fine minotaur leather I will see what I can do for you. You probably have to kill realy many minotaurs though... so good luck!", cid)
           npcHandler.topic[cid] = 0
       else
           npcHandler:say("Well, then don't.", cid)
           npcHandler.topic[cid] = 0
       end
   
   elseif npcHandler.topic[cid] == 4 then
       if msgcontains(msg, "yes") then
           if player:getItemCount(cid, 5878) >= 100 then
               npcHandler:say("Great! Alright, I need a while to finish this backpack for you... Here you go, I hope you like it.", cid)
               player:setStorageValue(52000, 2)
               player:removeItem(cid, 5878, 100)
               player:addOutfit(cid, 136, 1)
               player:addOutfit(cid, 128, 1)
               player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
               npcHandler.topic[cid] = 0
           else
               npcHandler:say("You don't have all the required items.", cid)
               npcHandler.topic[cid] = 0
           end
       else
           npcHandler:say("Alright then. Come back when you got all neccessary items.", cid)
           npcHandler.topic[cid] = 0
       end
   end
   return true
   
end

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

npchandler.lua
Wklejka #3095069 – Wklej.org
 
Solution
Problem solved.

Just changed this part
Code:
local function creatureSayCallback(cid, type, msg)
   if not npcHandler:isFocused(cid) then
       return false
   end

to
Code:
local function creatureSayCallback(cid, type, msg)
   local player = Player(cid)
   if not npcHandler:isFocused(cid) then
       return false
   end

Since the function can canceld in the if statment above, it's better to put it below, like this;
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)...
Problem solved.

Just changed this part
Code:
local function creatureSayCallback(cid, type, msg)
   if not npcHandler:isFocused(cid) then
       return false
   end

to
Code:
local function creatureSayCallback(cid, type, msg)
   local player = Player(cid)
   if not npcHandler:isFocused(cid) then
       return false
   end
 
Problem solved.

Just changed this part
Code:
local function creatureSayCallback(cid, type, msg)
   if not npcHandler:isFocused(cid) then
       return false
   end

to
Code:
local function creatureSayCallback(cid, type, msg)
   local player = Player(cid)
   if not npcHandler:isFocused(cid) then
       return false
   end

Since the function can canceld in the if statment above, it's better to put it below, like this;
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 function creatureSayCallback(cid, type, msg)
   if not npcHandler:isFocused(cid) then
       return false
   end
   
   local player = Player(cid)
   if msgcontains(msg, "quest") then
       npcHandler:say("I left my raft at the south-eastern shore. I forgot my private {notebook} on it. If you could return it to me, I would be very grateful.", cid)
   elseif msgcontains(msg, "notebook") then
       if player:getStorageValue(50005) <= 1 then
           npcHandler:say("Do you bring me my notebook?", cid)
           npcHandler.topic[cid] = 1
       else
           npcHandler:say("I already have my notebook.", cid)
       end
       
   elseif npcHandler.topic[cid] == 1 then
       if msgcontains(msg, "yes") then
           if player:getItemCount(cid, 1955) >= 1 then
               player:removeItem(cid, 1955, 1)
               player:addItem(cid, 2406, 1)
               player:setStorageValue(50005, 2)
               npcHandler:say("Excellent. Here, take this short sword as a reward.", cid)
               npcHandler.topic[cid] = 0
           else
               npcHandler:say("Mhm, whatever you have there, it is not my notebook", cid)
               npcHandler.topic[cid] = 0
           end
       else
           npcHandler:say("Too bad.", cid)
           npcHandler.topic[cid] = 0
       end
   end
   
   if msgcontains(msg, "backpack addon") then
       if player:getStorageValue(52000) > 1 then
           npcHandler:say("It seems you already have this addon, don't you try to mock me son!", cid)
       elseif isPremium(cid) == false then
           npcHandler:say("Sorry, but they are only for premium customers", cid)
       elseif isPremium(cid) == true then
           if player:getStorageValue(52000) < 1 then
               npcHandler:say("Ah, you noticed my new accessory? Sorry, this one is not for sale. It's handmade from rare {minotaur} {leather}.", cid)
               npcHandler.topic[cid] = 2
           elseif player:getStorageValue(52000) == 1 then
               npcHandler:say("Ah, right, almost forgot about the backpack! Have you brought me 100 pieces of minotaur leather as requested?", cid)
               npcHandler.topic[cid] = 4
           else
               npcHandler:say("It seems you already have this addon, don't you try to mock me son!", cid)
           end
       end
       
   elseif npcHandler.topic[cid] == 2 then
       if msgcontains(msg, "minotaur leather") then
           npcHandler:say("Well, if you really like this backpack, I could make one for you, but minotaur leather is hard to come by these days. Are you willing to put some work into this?", cid)
           npcHandler.topic[cid] = 3
       end
       
   elseif npcHandler.topic[cid] == 3 then
       if msgcontains(msg, "yes") then
           player:setStorageValue(52000, 1)
           npcHandler:say("Alright then, if you bring me 100 pieces of fine minotaur leather I will see what I can do for you. You probably have to kill realy many minotaurs though... so good luck!", cid)
           npcHandler.topic[cid] = 0
       else
           npcHandler:say("Well, then don't.", cid)
           npcHandler.topic[cid] = 0
       end
   
   elseif npcHandler.topic[cid] == 4 then
       if msgcontains(msg, "yes") then
           if player:getItemCount(cid, 5878) >= 100 then
               npcHandler:say("Great! Alright, I need a while to finish this backpack for you... Here you go, I hope you like it.", cid)
               player:setStorageValue(52000, 2)
               player:removeItem(cid, 5878, 100)
               player:addOutfit(cid, 136, 1)
               player:addOutfit(cid, 128, 1)
               player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
               npcHandler.topic[cid] = 0
           else
               npcHandler:say("You don't have all the required items.", cid)
               npcHandler.topic[cid] = 0
           end
       else
           npcHandler:say("Alright then. Come back when you got all neccessary items.", cid)
           npcHandler.topic[cid] = 0
       end
   end
   return true
   
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Back
Top