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

Nil value

Sibbeon

New Member
Joined
Feb 4, 2009
Messages
8
Reaction score
0
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:
[04/02/2009 17:14:01] Lua Script Error: [Npc interface]
[04/02/2009 17:14:01] data/npc/scripts/truth.lua:eek:nCreatureSay

[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
 
getCreatureName(cid) not GetCreatureName(cid)
Thankyou, it now works like a charm.

Perhaps you could answer another question so I won't have to create an all new thread..

All characters start with a set of eq, including a Crystal Coin in the backpack. I do not want characters to start with this due to abuse.

In config.lua:
-- New Player Items
newPlayerBackPack = 2000 --red backpack
newPlayerHelmet = 2457 --steel helmet
newPlayerArmor = 2464 --chain armor
newPlayerLegs = 2648 --plate legs
newPlayerBoots = 3982 --crocodile boots
newPlayerShield = 2525 --tortoise shield
newPlayerAmulet = 2173 --aol
--Items for each especific vocation
newPlayerDruidRod = 2182 --first rod
newPlayerSorcererWand = 2190 --first wand
newPlayerPaladinAmmo = 2455 --crossbow
newPlayerPaladinAmmonation = 2543 --bolt
newPlayerKnightSword = 8602 --jagged sword
newPlayerKnightAxe = 8601 --steel axe

There is no crystal coin ID there, or anything that says that the character should start with a crystal coin. Where could I change this? Thanks for your time!
 
Back
Top