error in npc
i tried convert script 0.4 for tfs 1.2
Npc.lua
i tried convert script 0.4 for tfs 1.2
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/novicespells.lua:onCreatureSay
data/npc/scripts/novicespells.lua:44: attempt to index global 'talkState' (a nil value)
stack traceback:
[C]: in function '__index'
data/npc/scripts/novicespells.lua:44: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:411: in function 'onCreatureSay'
data/npc/scripts/novicespells.lua:7: in function <data/npc/scripts/novicespells.lua:7>
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
npcHandler:addModule(FocusModule:new())
local storage = 98534
local spells = {"Light Healing", "Recovery"}
local text = ""
for x = 1, #spells do
local c = ", "
if x == 1 then
c = ""
elseif x == #spells then
c = " and "
end
text = text .. c
text = text .. spells[x]
end
function creatureSayCallback(cid, type, msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if not npcHandler:isFocused(cid) then
if msg == "hi" or msg == "hello" then
if player:getStorageValue(config.storage) == -1 then
npcHandler:say("Hello dear "..getCreatureName(cid)..", I can teach you some interesting {spells}, but remember you can't learn it all.", cid)
talkState[talkUser] = 1
else
npcHandler:say("Hello, hope you're doing well with your new spells.", cid)
end
npcHandler:addFocus(cid)
else
return false
end
end
if msgcontains(msg, "spells") and talkState[talkUser] == 1 then
npcHandler:say("I can teach you spells: "..text..". But remember, you can choose only 2 spells to learn from my list, other spells will be pernament not available to you.", cid)
npcHandler:say("So which spells do you choose?", cid)
talkState[talkUser] = 2
elseif msgcontains(msg, "bye") then
npcHandler:say("Bye.", cid)
npcHandler:releaseFocus(cid)
elseif talkState[talkUser] == 2 then
if isInArray(spells, msg) then
if player:getStorageValue(config.storage) < 1 then
npcHandler:say(player:getStorageValue(config.storage) == -1 and "You have now learned the spell "..msg..", you can choose 1 more spell." or "So "..msg.." will be your second spell, good luck with both spells.", cid)
player:learnInstantSpell(msg)
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
player:setStorageValue(config.storage, player:getStorageValue(config.storage) + 1)
npcHandler.topic[cid] = 0
else
npcHandler:say("Sorry, you already learned 2 spells from me.", cid)
npcHandler.topic[cid] = 0
end
else
npcHandler:say(msg.." is not a spell you can learn from me, you can choose "..text..".", cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)