Hello.
Im using this script, and get this error, can someone help me fix it?
Im using this script, and get this error, can someone help me fix it?
Lua:
local STORAGE = 18008
local TALKSTATE_PICK = 1
local TALKSTATE_RESET = 2
local TALKSTATE_COMPLETE = 3
local TASKSTATE_COMPLETED = 1
local TASKSTATE_BOSS = 2
local TASKSTATE_FINALIZED = 3
local tasks = {
['dragons'] = {storage = 18009, kills = 50, experience = 0, once = false, items = {{2160, 10}}},
['giant spiders'] = {storage = 18010, kills = 10, experience = 10000, once = true, items = {}},
['dragon lords'] = {storage = 18011, kills = 10, experience = 0, once = true, items = {}},
['hydras'] = {storage = 18012, kills = 50, experience = 0, once = false, items = {{2160, 25}}},
['grim reapers'] = {storage = 18013, kills = 100, experience = 2000000, once = true, items = {{2160, 30}}},
['demons'] = {storage = 18014, kills = 100, experience = 0, once = false, items = {{2160, 40}}},
['undead dragons'] = {storage = 18015, kills = 10, experience = 0, once = true, items = {}}
}
function listTasks()
local output, list = '', {}
for k, v in ipairs(tasks) do
table.insert(list, k)
end
for k, v in ipairs(list) do
if k == 1 then
output = '{'.. v .. '}'
elseif k == #list then
output = output .. ' and {'.. v ..'}'
else
output = output ..', {'.. v ..'}'
end
end
return output
end
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState, turned = {}
function onCreatureAppear(cid)
npcHandler:onCreatureAppear(cid)
end
function onCreatureDisappear(cid)
npcHandler:onCreatureDisappear(cid)
if talkState[cid] then
talkState[cid] = nil
end
end
function onCreatureSay(cid, type, msg)
npcHandler:onCreatureSay(cid, type, msg)
end
function onThink()
if not turned then
selfTurn(SOUTH)
turned = true
end
npcHandler:onThink()
end
local shop = ShopModule:new()
npcHandler:addModule(shop)
shop:addBuyableItem({'demon backpack'}, 10518, 1000, 1, 'Demon Backpack')
shop:addSellableItem({'hydra head'}, 11199, 600, 'Hydra Head')
shop:addSellableItem({'cyclops trophy'}, 7398, 500, 'Cyclops Trophy')
shop:addSellableItem({'minotaur trophy'}, 7401, 500, 'Minotaur Trophy')
shop:addSellableItem({'deer trophy'}, 7397, 1000, 'Deer Trophy')
shop:addSellableItem({'lion trophy'}, 7400, 1000, 'Lion Trophy')
shop:addSellableItem({'wolf trophy'}, 7394, 1000, 'Wolf Trophy')
shop:addSellableItem({'behemoth trophy'}, 7396, 20000, 'Behemoth Trophy')
shop:addSellableItem({'demon trophy'}, 7393, 40000, 'Demon Trophy')
shop:addSellableItem({'dragon lord trophy'}, 7399, 10000, 'Dragon Lord Trophy')
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
if msgcontains(msg, 'task') then
if getCreatureStorage(cid, STORAGE) == EMPTY_STORAGE then
local list = listTasks()
selfSay('You can start one of the following tasks: {Dragons}, {Giant Spiders}, {Dragon Lords}, {Hydras}, {Grim Reapers}, {Demons} and {Undead Dragons}.', cid)
selfSay('You can also make these: {Juggernauts}, {Hands}, {Dark Torturers} and {Phantasms}. But you can make them only once.', cid)
selfSay('To start a task, simply type one of highlighted keywords, and remember - you can\'t start more than one task at same time.', cid)
talkState[cid] = TALKSTATE_PICK
else
selfSay('You are currently assigned a task. Would you like to dismiss your current task and begin another one?', cid)
talkState[cid] = TALKSTATE_RESET
end
elseif talkState[cid] == TALKSTATE_RESET then
if msgcontains(msg, 'yes') then
doCreatureSetStorage(cid, STORAGE, EMPTY_STORAGE)
for _, v in ipairs(tasks) do
doCreatureSetStorage(cid, v.storage, EMPTY_STORAGE)
end
selfSay('Your current task has been restarted, now you can choose another one, please say {task} to see list of available tasks.', cid)
else
selfSay('No then...', cid)
end
talkState[cid] = nil
elseif talkState[cid] == TALKSTATE_PICK then
local task = tasks[msg:lower()]
if task then
if getCreatureStorage(cid, task.storage) == task.kills + TASKSTATE_FINALIZED then
selfSay('This task has been already finalized and you can\'t pick it anymore.', cid)
else
doCreatureSetStorage(cid, STORAGE, 1)
doCreatureSetStorage(cid, task.storage, 0)
selfSay('You just started the {'.. msg:lower():gsub('%a', string.upper, 1) ..'} task. You have to kill '.. task.kills ..' of '.. msg:lower() ..'. Come back and ask about {complete} when you are done.', cid)
end
else
selfSay('It does seem like you don\'t understand me, I told you to pick task from list.', cid)
end
talkState[cid] = nil
elseif msgcontains(msg, 'complete') then
if getCreatureStorage(cid, STORAGE) == EMPTY_STORAGE then
selfSay('You aren\'t doing any task at the moment, if you would like to start one - type {task}.', cid)
else
selfSay(' I forgot, which task did you just complete?', cid)
talkState[cid] = TALKSTATE_COMPLETE
end
elseif talkState[cid] == TALKSTATE_COMPLETE then
local task = tasks[msg:lower()]
if task then
local kills = getCreatureStorage(cid, task.storage)
if kills <= task.kills then
selfSay('You have to kill '.. task.kills ..' '.. msg:lower() ..' in order to complete the {'.. msg:lower() ..'} task, you have killed '.. kills ..' '.. msg:lower():gsub('%a', string.upper, 1) ..'.', cid)
elseif kills == task.kills + TASKSTATE_COMPLETED then
local msg = 'Congratulations! You have completed the {'.. msg:lower():gsub('%a', string.upper, 1) ..'} task. You receive {access to magic forcefield}'
if task.experience > 0 then
doPlayerAddExperience(cid, task.experience)
msg = msg .. ' and {'.. task.experience ..' experience points}'
end
if #task.items > 0 then
msg = msg ..' and following items'
for k, v in ipairs(task.items) do
doPlayerAddItem(cid, v[1], v[2])
if k == 1 then
msg = msg ..' {'.. getItemInfo(v[1]).name ..'}'
else
msg = msg ..', {'.. getItemInfo(v[1]).name ..'}'
end
end
end
msg = msg ..' as a reward!'
doCreatureSetStorage(cid, task.storage, task.kills + TASKSTATE_BOSS)
doSendMagicEffect(getThingPosition(cid), CONST_ME_GIFT_WRAPS)
selfSay(msg, cid)
talkState[cid] = nil
if not __achv.check(cid, 8) then
__achv.set(cid, 8, 1)
end
elseif kills == task.kills + TASKSTATE_BOSS then
selfSay('You have already reported in about that task and received access to magic forcefield, go and kill boss.', cid)
elseif kills == task.kills + TASKSTATE_FINALIZED then
selfSay('This task has been already finalized and you can\'t pick it anymore.', cid)
end
else
selfSay('There\'s no task named {'.. msg:lower() ..'}, please remind yourself what task you have started before or type {task} to see list of available tasks.', cid)
end
talkState[cid] = nil
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, 'Hello, |PLAYERNAME|! I need someone to fufill a special {task} for me. If you have completed a task, please say {complete}, then the name of the task.')
npcHandler:addModule(FocusModule:new())
Lua:
[9:54:12.369] [Error - NpcScript Interface]
[9:54:12.372] data/npc/scripts/task.lua:onCreatureSay
[9:54:12.374] Description:
[9:54:12.375] data/npc/scripts/task.lua:176: attempt to index global '__achv' (a nil value)
[9:54:12.378] stack traceback:
[9:54:12.380] data/npc/scripts/task.lua:176: in function 'callback'
[9:54:12.382] data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[9:54:12.385] data/npc/scripts/task.lua:59: in function <data/npc/scripts/task.lua:58>