I have saved my OT server for quite a while and now I started it again. I have transferred several NPC's from an old OT to a newer one. I have fixed most problems but one problem remains:
I have an NPC that you can ask questions.
He will answer either yes or no. (The answer is random.)
When I start the OT the npc works fine, but after an hour he won't respond any longer.
The error i recieve in the server log is this:
If you scroll through the log you will notice that I have marked out line 40. I guess "GetCreatureName" should be replaced with something else, but what?
Here is the script for him:
I have an NPC that you can ask questions.
He will answer either yes or no. (The answer is random.)
When I start the OT the npc works fine, but after an hour he won't respond any longer.
The error i recieve in the server log is this:
[04/02/2009 17:14:01] Lua Script Error: [Npc interface]
[04/02/2009 17:14:01] data/npc/scripts/truth.luanCreatureSay
[04/02/2009 17:14:01] data/npc/scripts/truth.lua:40: attempt to call global 'GetCreatureName' (a nil value)
[04/02/2009 17:14:01] stack traceback:
[04/02/2009 17:14:01] data/npc/scripts/truth.lua:40: in function <data/npc/scripts/truth.lua:36>
If you scroll through the log you will notice that I have marked out line 40. I guess "GetCreatureName" should be replaced with something else, but what?
Here is the script for him:
local focus = 0
local talk_start = 0
local target = 0
local following = false
local attacking = false
function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
if focus == cid then
selfSay('Good bye then.')
focus = 0
talk_start = 0
end
end
function onCreatureTurn(creature)
end
function msgcontains(txt, str)
return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end
function onCreatureSay(cid, type, msg)
msg = string.lower(msg)
if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
selfSay('Hello ' .. GetCreatureName(cid) .. '. Do you want me to answer you a yes/no question?') <--- LINE 40.
focus = cid
talk_start = os.clock()
elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
selfSay('Sorry, ' .. GetCreatureName(cid) .. '! I talk to you in a minute.')
elseif focus == cid then
talk_start = os.clock()
if msgcontains(msg, 'yes') then
selfSay('Ask your question!')
talk_state = 1
end
if talk_state == 1 and string.find(msg, '(%a*)?(%a*)') then
if math.random(1,2) == 1 then
selfSay('Yes.')
elseif math.random(1,2) == 2 then
selfSay('No.')
talk_state = 1
end
elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
selfSay('Good bye, ' .. GetCreatureName(cid) .. '!')
focus = 0
talk_start = 0
end
end
end
function onThink()
if (os.clock() - talk_start) > 15 then
if focus > 0 then
selfSay('The Gods will decide your faith...')
end
focus = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 2 then
selfSay('Good bye then.')
focus = 0
end
end
end