Npc doesn't collect items or give reward where is the problem in the script, this is a modified version of andu's script(NPC - [FIXED] NPC with daily quests, fully configurable! by andu (https://otland.net/threads/fixed-npc-with-daily-quests-fully-configurable-by-andu.158833/)).
i've stayed an hour or more, but i couldn't figure why, i think i missed something.
i've stayed an hour or more, but i couldn't figure why, i think i missed something.
Lua:
------------------------------------------------------
local scriptAuthor = "andu" --- http://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 = {55555, 66666}, -- 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 = 40, -- level required to start the quest
gatherKillOrFind = 1, -- 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 = {
[2129] = {amount = 50} -- 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.
},
rewards = {
gold = 50000, -- 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 = 20000, -- 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 = 40,
gatherKillOrFind = 1,
itemsReq = {
[5944] = {amount = 50}
},
rewards = {
gold = 50000,
experience = 30000,
items = {
[2195] = {amount = 10}
}
}
},
[3] = {
reqPremium = false,
levelReq = 40,
gatherKillOrFind = 1,
itemsReq = {
[2216] = {amount = 50}
},
rewards = {
gold = 0,
experience = 0,
items = {
[2195] = {amount = 1}
}
}
},
[4] = {
reqPremium = false,
levelReq = 40,
gatherKillOrFind = 1,
itemsReq = {
[3019] = {amount = 50}
},
rewards = {
gold = 0,
experience = 0,
items = {
[2195] = {amount = 1}
}
}
},
[5] = {
reqPremium = false,
levelReq = 40,
gatherKillOrFind = 1,
itemsReq = {
[3019] = {amount = 5}
},
rewards = {
gold = 0,
experience = 0,
items = {
[2195] = {amount = 1}
}
}
},
[6] = {
reqPremium = false,
levelReq = 40,
gatherKillOrFind = 1,
itemsReq = {
[3019] = {amount = 6}
},
rewards = {
gold = 0,
experience = 40000,
items = {
[2195] = {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?"
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 check(cid)
local check = {}
for t = 1, cfg.questsAmount do
check[t] = 0
if cfg.quests[t].gatherKillOrFind == 1 then
for i,x in pairs(cfg.quests[t].itemsReq) do
if getPlayerItemCount(cid, i) < x.amount then
check[t] = check[t] + 1
else
check[t] = check[t] + 2
end
end
end
return check[t]
end
return true
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
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())