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 storage = 98534
local spells = {"Light Healing", "Intense Healing", "Ultimate Healing", "Divine Healing", "Wound Cleansing"}
local text = ""
for x = 1, #spells do
local c = ", "
if x == 1 then
c = ""
elseif x == #spells then
c = " and "
end
text = text .. c
text = text .. spells[x]
end
function creatureSayCallback(cid, type, msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if not npcHandler:isFocused(cid) then
if msg == "hi" or msg == "hello" then
if getPlayerStorageValue(cid, storage) == -1 then
selfSay("Hello dear "..getCreatureName(cid)..", I can teach you some interesting {spells}, but remember you can't learn it all.", cid)
talkState[talkUser] = 1
else
selfSay("Hello, hope you're doing well with your new spells.", cid)
end
npcHandler:addFocus(cid)
else
return false
end
end
if msgcontains(msg, "spells") and talkState[talkUser] == 1 then
selfSay("I can teach you spells: "..text..". But remember, you can choose only 2 spells to learn from my list, other spells will be pernament not available to you.", cid)
selfSay("So which spells do you choose?", cid)
talkState[talkUser] = 2
elseif msgcontains(msg, "bye") then
selfSay("Bye.", cid)
npcHandler:releaseFocus(cid)
elseif talkState[talkUser] == 2 then
if isInArray(spells, msg) then
if getPlayerStorageValue(cid, storage) < 1 then
selfSay(getPlayerStorageValue(cid, storage) == -1 and "You have now learned the spell "..msg..", you can choose 1 more spell." or "So "..msg.." will be your second spell, good luck with both spells.", cid)
doPlayerLearnInstantSpell(cid, msg)
setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) + 1)
else
selfSay("Sorry, you already learned 2 spells from me.", cid)
talkState[talkUser] = 0
end
else
selfSay(msg.." is not a spell you can learn from me, you can choose "..text..".", cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)