local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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 cfg = {
[0] = {spellName = "spellname0"}, -- basic spell
[1] = {spellName = "spellname1", level = 10, cost = 1000}, -- spell up 1
[2] = {spellName = "spellname2", level = 50, cost = 5000}, -- spell up 2
unlearnOldSpell = true, -- remove old spell?
greetCallback = 'Welcome |PLAYERNAME|! Do you want to {upgrade} your '..cfg[0].spellName..' spell?' -- welcome message
}
npcHandler:setMessage(MESSAGE_GREET, cfg.greetCallback)
local function upgrade(cid, level)
if getPlayerLevel(cid) < cfg[level].level then
if doPlayerRemoveMoney(cid, cfg[level].cost) == true then
playerLearnInstantSpell(cid, cfg[level].spellName)
selfSay('Ok, listen... [Your spell '..cfg[level-1].spellName..' advanced to '..cfg[level].spellName..']', cid)
if cfg.unlearnOldSpell == true then
doPlayerUnlearnInstantSpell(cid, cfg[level-1].spellName)
end
else
selfSay('Poor guy... You think I upgrade it for free? Bring me 'cfg[level].cost' gold coins then I teach you how to use this spell better!', cid)
end
else
selfSay('Doh, this upgrade required '..cfg[level].spellName..'level. Get some exp!', cid)
end
end
function creatureSayCallback(cid, type, msg)
if msgcontains(msg, 'upgrade') then
if getPlayerLearnedInstantSpell(cid, cfg[2].spellName) == true then
selfSay('You already have all upgrades.', cid)
elseif getPlayerLearnedInstantSpell(cid, cfg[1].spellName) == true then
selfSay('Do You want to upgrade your '..cfg[1].spellName.." to " ..cfg[2].spellName.." for "..cfg[2].cost.." gold coins?", cid)
npcHandler.topic[cid] == 2
elseif getPlayerLearnedInstantSpell(cid, cfg[0].spellName) == true then
selfSay('Do You want to upgrade your '..cfg[0].spellName.." to " ..cfg[1].spellName.." for "..cfg[1].cost.." gold coins?", cid)
npcHandler.topic[cid] == 1
else
selfSay('First learn '..cfg[0].spellName..' spell.', cid)
end
elseif msgcontains(msg, 'yes') then
if npcHandler.topic[cid] == 1 then
upgrade(cid, 1)
elseif npcHandler.topic[cid] == 2 then
upgrade(cid, 2)
end
npcHandler.topic[cid] = 0 -- reset anyway
elseif msgcontains(msg, 'no') and (npcHandler.topic[cid] == 1 or npcHandler.topic[cid] == 2) then
selfSay('Ok then.', cid)
npcHandler.topic[cid] = 0
end
return true
end
npcHandler:addModule(FocusModule:new())