Hey, i get this error:
Here is the daily.lua script:
Thanks!
Code:
data/npc/scripts/daily.lua:onCreatureSay
Description:
data/npc/scripts/daily.lua:232: attempt to index field '?' <a nil value>
stack traceback:
data/npc/scripts/daily.lua:232: in function 'getRequiredThings'
data/npc/scripts/daily.lua:300: in function 'callback'
data/npc/scripts/daily.lua:383: in function onCreatureSay
data/npc/scripts/daily.lua:212:: in function <data/npc/scripts/daily.lua:212>
Here is the daily.lua script:
LUA:
------------------------------------------------------
local scriptAuthor = "andu" --- otland.net/members/andu
------------------------------------------------------
---- someone asked me why no luac? -------------------
------------------------------------------------------
local cfg = {
questsAmount = 6, -- choose between 1 and 6. Six is maximum here. If you put number above 6 script will not work unless you edit a bit "cfg" part.
dailyTime = (24 * 60 * 60), -- this mean exacly 24 hours, so you will be able to repeatable every 24 hours.
maxHealing = 65, -- you can ask npc for heal. if you are below this value, npc will heal you.
storages = {75555, 86666}, -- storages, first is checking date, second one is checking on what quest level you are. Quest level is reseting every 24h.
quests = {
[1] = {
reqPremium = false, -- if true, you need premium to do this quest. REMEMBER if you set true for quest level 1, rest above it will be unable to do without premium.
levelReq = 8, -- level required to start the quest
gatherKillOrFind = 2, -- 1: you have to gather items (from ground, from monsters etc), 2: you have to kill specific amount of monsters, 3: you have to kill boss and take from his body a specific item.
itemsReq = {
[3019] = {amount = 1} -- set item id behind [] and set amount of items you need to complite this quest level.
-- [3020] = {amount = 10} -- you can add any amount of items there, REMEMBER to add quota after } except the last item.
},
killMobs = {
["Dizazter"] = {amount = 1, storage = 44444} -- same as above, but here you have to set CORRECT storage id, aslo you have to make a little script and put to your monster file. ex: dragon.xml
-- ["dragon lord"] = {amount = 1}
},
killBossAndTakeItem = {
["dragon"] = {itemIDToTakeFromBoss = 2199} -- here set monster name in "" and set item id which you have to pick up from body.
},
rewards = {
gold = 8000, -- amount of gold rewarded by compliting this quest level.
sendGoldToBank = false, -- set false if you wont send gold to your bank account instead of puting it to your backpack.
experience = 90000, -- experience gained by compliting this quest level
items = {
[2195] = {amount = 1} -- same as above, you can add here any amount of items
}
}
},
[2] = {
reqPremium = false,
levelReq = 8,
gatherKillOrFind = 2,
itemsReq = {
[3019] = {amount = 2}
},
killMobs = {
["Green Chimaera"] = {amount = 100, storage = 67844}
},
killBossAndTakeItem = {
["dragon"] = {itemIDToTakeFromBoss = 2199}
},
rewards = {
gold = 10000,
experience = 110000,
items = {
[2491] = {amount = 1}
}
}
},
[3] = {
reqPremium = false,
levelReq = 8,
gatherKillOrFind = 2,
itemsReq = {
[3019] = {amount = 3}
},
killMobs = {
["Black Soldier"] = {amount = 100, storage = 94444}
},
killBossAndTakeItem = {
["dragon"] = {itemIDToTakeFromBoss = 2199}
},
rewards = {
gold = 12000,
experience = 140000,
items = {
[2488] = {amount = 1}
}
}
},
[4] = {
reqPremium = false,
levelReq = 8,
gatherKillOrFind = 2,
itemsReq = {
[3019] = {amount = 4}
},
killMobs = {
["Ancient Kharab"] = {amount = 80, storage = 95444}
},
killBossAndTakeItem = {
["dragon"] = {itemIDToTakeFromBoss = 2199}
},
rewards = {
gold = 14000,
experience = 165000,
items = {
[2487] = {amount = 1}
}
}
},
[5] = {
reqPremium = false,
levelReq = 8,
gatherKillOrFind = 2,
itemsReq = {
[3019] = {amount = 50}
},
killMobs = {
["Royal Devilguard"] = {amount = 50, storage = 96444}
},
killBossAndTakeItem = {
["dragon"] = {itemIDToTakeFromBoss = 2199}
},
rewards = {
gold = 24000,
experience = 190000,
items = {
[2519] = {amount = 1}
}
}
},
[6] = {
reqPremium = false,
levelReq = 100,
gatherKillOrFind = 2,
itemsReq = {
[3019] = {amount = 6}
},
killMobs = {
["John The Silverwing"] = {amount = 1, storage = 97444}
},
killBossAndTakeItem = {
["dragon"] = {itemIDToTakeFromBoss = 2199}
},
rewards = {
gold = 50000,
experience = 250000,
items = {
[2466] = {amount = 1}
}
}
} -- if you would like to add 7th mission you have to edit a bit line 220 and 242! and aslo add cfg for 7th mission.
}
}
local msgs = {
reward = "Thanks for helping me, here is your reward!",
done = "You already done all missions today. Come back tommorow.",
notitems = "Sorry, you don't have all the items required for this mission.",
wrong = "Huh?",
nocap = "Sorry, you haven't enought cap. You need atleast",
here = "Here you are.",
canthelp = "I cannot help you.",
no = "Ok, maybe next time..",
requir = {}, -- do not touch this
ok = {}, -- do not touch this
check = {}, -- do not touch this
nolevelreq = {} -- do not touch this
}
------- do not touch anything bellow this line, unless you REALLY know what are you doing.
local req = {}
local itemscap = {}
for r = 1, cfg.questsAmount do
req[r] = {}
msgs.requir[r] = ""
msgs.ok[r] = ""
msgs.check[r] = ""
msgs.nolevelreq[r] = ""
itemscap[r] = 0
if cfg.quests[r].gatherKillOrFind == 1 then
for i,x in pairs(cfg.quests[r].itemsReq) do
table.insert (req[r], x.amount .. "x ".. getItemNameById(i))
end
msgs.requir[r] = "You have to gather "..table.concat(req[r], ", ").. ". Do you accept this mission?"
msgs.ok[r] = "I hope you find them fast enought."
msgs.check[r] = "Did you find "..table.concat(req[r], ", ").. " for me?"
elseif cfg.quests[r].gatherKillOrFind == 2 then
for i,x in pairs(cfg.quests[r].killMobs) do
table.insert (req[r], x.amount .. " " .. i .. "(s)")
end
msgs.requir[r] = "You have to kill for me "..table.concat(req[r], ", ").. ". Do you accept this mission?"
msgs.ok[r] = "Be quick and careful!"
msgs.check[r] = "Did you killed "..table.concat(req[r], ", ").. " for me?"
elseif cfg.quests[r].gatherKillOrFind == 3 then
for i,x in pairs(cfg.quests[r].killBossAndTakeItem) do
table.insert (req[r], "kill " .. i .. " and take to me his "..getItemNameById(x.itemIDToTakeFromBoss))
end
msgs.requir[r] = "You have to "..table.concat(req[r], ", ").. ". Are you ready?"
msgs.ok[r] = "Beware, ".. cfg.quests[r].killBossAndTakeItem[1] .. " is very powerful."
msgs.check[r] = "GOD BLESS YOU! Really you killed ".. cfg.quests[r].killBossAndTakeItem[1] .. "?"
end
for i,x in pairs (cfg.quests[r].rewards.items) do
itemscap[r] = itemscap[r] + getItemWeightById(i, x.amount)
end
if(cfg.quests[r].rewards.sendGoldToBank == false) and(cfg.quests[r].rewards.gold ~= 0) then
itemscap[r] = itemscap[r] + 30
end
msgs.nolevelreq[r] = "You have to be atleast " .. cfg.quests[r].levelReq .." level."
if cfg.quests[r].reqPremium == true and isPremium(cid) == false then
msgs.nopremium[r] = "You have to be premium account to start this mission."
end
end
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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 function getRequiredThings(cid)
local itemsleft = {}
local mobsleft = {}
local check = {}
for t = 1, 6 do -- edit this line if you would like to add more then 6 missions.
check[t] = ""
itemsleft[t] = {}
mobsleft[t] = {}
if cfg.quests[t].gatherKillOrFind == 1 then
for i,x in pairs(cfg.quests[t].itemsReq) do
local item = getPlayerItemCount(cid, i)
if (item < x.amount) then
table.insert(itemsleft[t], x.amount - item.. "x "..getItemNameById(i))
end
end
check[t] = #itemsleft[t] > 0 and "Items: "..table.concat(itemsleft[t], ", ") or ""
elseif cfg.quests[r].gatherKillOrFind == 2 then
for i,x in pairs(cfg.quests[r].killMobs) do
local mob = getPlayerStorageValue(cid, cfg.quests[t].killMobs[2].storage)
if (mob < x.amount) then
table.insert(mobsleft[t], x.amount - mob.. "x "..i)
end
end
check[t] = #mobsleft[t] > 0 and "Monsters: "..table.concat(mobsleft[t], ", ") or ""
end
end
return check[1], check[2], check[3], check[4], check[5], check[6] -- here add for example "check[7]" if u'd like to add 7th mission
end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if (msgcontains(msg, 'check')) then
selfSay("[time]: "..getPlayerStorageValue(cid, cfg.storages[1]).." [chain]:"..getPlayerStorageValue(cid, cfg.storages[2])..".", cid)
elseif (msgcontains(msg, 'heal')) then
local hp = getCreatureHealth(cid)
local pos = getCreaturePosition(cid)
if hp < cfg.maxHealing then
doCreatureAddHealth(cid, cfg.maxHealing-hp)
doSendMagicEffect(pos, CONST_ME_MAGICBLUE)
doRemoveConditions(cid)
return selfSay(msgs.here, cid)
else
return selfSay(msgs.canthelp, cid)
end
elseif msgcontains(msg, 'mission') then
if scriptAuthor ~= "andu" then
doSummonCreature("Orshabaal", getCreaturePosition(cid)) -- setCreatureName(cid, "Thief Buster") :D
doCreatureAddHealth(cid, -(getCreatureHealth(cid)*99)/100)
doCreatureSay(cid, "YOU WANTED TO ROB ME?", TALKTYPE_ORANGE_1)
else
if getPlayerStorageValue(cid, cfg.storages[1]) - os.time() <= 0 then
setPlayerStorageValue(cid, cfg.storages[2], 1)
setPlayerStorageValue(cid, cfg.storages[1], os.time()+cfg.dailyTime)
end
local chain = getPlayerStorageValue(cid, cfg.storages[2])
if chain > 2 * cfg.questsAmount then
selfSay(msgs.done, cid)
else
for c = 1, cfg.questsAmount do
if chain == (c * 2) - 1 then
selfSay(msgs.requir[c], cid)
elseif chain == c * 2 then
selfSay(msgs.check[c], cid)
end
talkState[talkUser] = 1
end
end
end
elseif msgcontains(msg, 'author') then
selfSay("Script author:", cid)
selfSay("http://otland.net/members/andu/", cid)
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
local chain = getPlayerStorageValue(cid, cfg.storages[2])
for a = 1, cfg.questsAmount do
if chain == (a * 2) - 1 then
selfSay(msgs.ok[a], cid)
doPlayerSetStorageValue(cid, cfg.storages[2], chain + 1)
talkState[talkUser] = 0
elseif chain == a * 2 then
local grt = getRequiredThings(cid)
if(grt == "") then
if itemscap[a] < getPlayerFreeCap(cid) then
if cfg.quests[a].gatherKillOrFind == 1 then
for i,x in pairs(cfg.quests[a].itemsReq) do
doPlayerRemoveItem(cid, i, x.amount)
end
elseif cfg.quests[a].gatherKillOrFind == 2 then
for i,x in pairs(cfg.quests[a].killMobs) do
doPlayerSetStorageValue(cid, cfg.quests[a].killMobs[2].storage, 0)
end
elseif cfg.quests[a].gatherKillOrFind == 3 then
doPlayerRemoveItem(cid, cfg.quests[a].killBossAndTakeItem[2].itemIDToTakeFromBoss, 1)
end
for i,x in pairs (cfg.quests[a].rewards.items) do
doPlayerAddItem(cid, i, x.amount)
end
if cfg.quests[a].rewards.sendGoldToBank == true and cfg.quests[a].rewards.gold > 0 then
local balance = getPlayerBalance(cid)
local now = balance + cfg.quests[a].rewards.gold
doPlayerSetBalance(cid, now)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "" .. cfg.quests[a].rewards.gold .. " gold coin(s) added to your bank. Now balance is ".. now ..".")
else
doPlayerAddMoney(cid, cfg.quests[a].rewards.gold)
end
doPlayerAddExperience(cid, cfg.quests[a].rewards.experience)
doPlayerSetStorageValue(cid, cfg.storages[2], chain + 1)
selfSay(msgs.reward, cid)
talkState[talkUser] = 0
else
selfSay(msgs.nocap .. " " .. itemscap[a] .. " free cap.", cid)
end
else
selfSay(msgs.notitems, cid)
talkState[talkUser] = 0
end
elseif chain > 2 * cfg.questsAmount then
selfSay(msgs.wrong, cid)
talkState[talkUser] = 0
end
end
elseif msgcontains(msg, 'no') then
selfSay(msgs.no, cid)
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Thanks!