Hello everyone!
I have problem with recieving creature id on farewell and creature disappear callback in lua function.
Here is my lua code:
When I talk 'bye' to NPC , I get a bug in the console:
Only when i logged out function work fine. Why it's happedns? Maybe i not see some bug in code. Please help me. I'm using TFS 1.1 on linux.
I have problem with recieving creature id on farewell and creature disappear callback in lua function.
Here is my lua code:
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 playersQueue = {}
local actualPlayer = 0
local nextPlayer = 0
local function queueService(cid)
for k,v in pairs(playersQueue) do
if v == cid then
table.remove(playersQueue, k)
print('remove')
else
print(cid .. ' not found in queue')
end
end
if actualPlayer == cid then
actualPlayer = 0
end
if #playersQueue > 0 and actualPlayer == 0 then
nextPlayer = playersQueue[1]
table.remove(playersQueue, 1)
local player = Player(nextPlayer)
npcHandler:say("Thanks for waiting " .. player:getName() .. "!", nextPlayer)
actualPlayer = nextPlayer
nextPlayer = 0
end
return true
end
local function greetCallback(cid)
if #playersQueue < 1 and actualPlayer == 0 then
npcHandler:setMessage(MESSAGE_GREET, "Welcome |PLAYERNAME|!")
actualPlayer = cid
else
npcHandler:setMessage(MESSAGE_GREET, "Welcome |PLAYERNAME|! I'm already busy. I add you to queue. Please wait for your turn.")
table.insert(playersQueue, cid)
end
return true
end
local function creatureSayCallback(cid, type, msg)
local player = Player(cid)
if msgcontains(msg, "queueCount") then
npcHandler:say("Queue count is: " .. #playersQueue, cid)
elseif msgcontains(msg, "queueContent") then
for k,v in pairs(playersQueue) do
selfSay(k .. ' => ' .. v, cid)
end
end
end
local function farewellCallback(cid)
queueService(cid)
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye |PLAYERNAME|. See you next time!")
return true
end
local function disappearCallback(cid)
queueService(cid)
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye. See you next time!")
return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setCallback(CALLBACK_FAREWELL, farewellCallback)
npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, disappearCallback)
npcHandler:addModule(FocusModule:new())
When I talk 'bye' to NPC , I get a bug in the console:
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/TestNPC.lua:onThink
data/npc/scripts/TestNPC.lua:20: attempt to concatenate local 'cid' (a nil value)
stack traceback:
[C]: in function '__concat'
data/npc/scripts/TestNPC.lua:20: in function 'queueService'
data/npc/scripts/TestNPC.lua:64: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:335: in function 'unGreet'
data/npc/lib/npcsystem/npchandler.lua:524: in function 'onThink'
data/npc/scripts/TestNPC.lua:8: in function <data/npc/scripts/TestNPC.lua:8>
Only when i logged out function work fine. Why it's happedns? Maybe i not see some bug in code. Please help me. I'm using TFS 1.1 on linux.