ralke
(҂ ͠❛ ෴ ͡❛)ᕤ
Hi! I use TFS 1.4 downgraded by nekiro (8.60) and I want to create a blessings NPC based on Henricus formula (getBlessingsCost(player:getLevel()) * 5 * 1.1). For this I took the lines related to blessings and made the following:
The thing is that I didn't made it well and I have this error, i'm not sure what i'm missing or if the npcHandler.topic structure is well applied. Can someone help me understanding what is wrong here? Thanks in advance!
Solved
Lua:
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 function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
local totalBlessPrice = getBlessingsCost(player:getLevel()) * 5 * 1.1
if msgcontains(msg, "blessing") or msgcontains(msg, "bless") then
npcHandler:say("Do you want to receive the blessing of the inquisition - which means all five available blessings - for " .. totalBlessPrice .. " gold?", cid)
npcHandler.topic[cid] = 1
else
npcHandler:say("You cannot get this blessing unless you have completed The Inquisition Quest.", cid)
npcHandler.topic[cid] = 0
end
if msgcontains(msg, "yes") then
elseif npcHandler.topic[cid] == 1 then
if player:getBlessings() == 5 then
npcHandler:say("You already have been blessed!", cid)
elseif player:removeMoney(totalBlessPrice) then
npcHandler:say("You have been blessed by all of five gods!, |PLAYERNAME|.", cid)
for b = 1, 5 do
player:addBlessing(b)
end
player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
else
npcHandler:say("Come back when you have enough money.", cid)
end
end
npcHandler.topic[cid] = 0
elseif msgcontains(msg, "no") then
if npcHandler.topic[cid] > 0 then
npcHandler:say("Then no.", cid)
npcHandler.topic[cid] = 0
end
end
npcHandler:setMessage(MESSAGE_GREET, "Greetings, fellow {believer} |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Always be on guard, |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "This ungraceful haste is most suspicious!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
The thing is that I didn't made it well and I have this error, i'm not sure what i'm missing or if the npcHandler.topic structure is well applied. Can someone help me understanding what is wrong here? Thanks in advance!
Post automatically merged:
Solved
Lua:
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 function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
local totalBlessPrice = getBlessingsCost(player:getLevel()) * 5 * 1.5
if npcHandler.topic[cid] == 0 then
if msgcontains(msg, "blessing") or msgcontains(msg, "bless") then
local inquisitionComplete = true
if inquisitionComplete then
npcHandler:say("Do you want to receive the common blessings - which means all five available blessings - for " .. totalBlessPrice .. " (1.5% extra gold)?", cid)
npcHandler.topic[cid] = 1
else
npcHandler:say("Fine. You are free to decline my offer.", cid)
npcHandler.topic[cid] = 0
end
end
elseif npcHandler.topic[cid] == 1 then
if msgcontains(msg, "yes") then
if player:getBlessings() == 5 then -- should probably check how many blessings in order to determine totalBlessPrice
npcHandler:say("You already have been blessed!", cid)
elseif player:removeMoney(totalBlessPrice) then
npcHandler:say("You have been blessed by all of five gods!, |PLAYERNAME|.", cid)
for b = 1, 5 do
player:addBlessing(b)
end
player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
else
npcHandler:say("Come back when you have enough money.", cid)
end
elseif msgcontains(msg, "no") then
npcHandler:say("Then no.", cid)
end
npcHandler.topic[cid] = 0
end
end
keywordHandler:addKeyword({'mission'}, StdModule.say, {npcHandler = npcHandler, text = 'Go see Henricus to begin The Inquisition Quest, I have no mission for you, child.'})
keywordHandler:addKeyword({'inquisitor'}, StdModule.say, {npcHandler = npcHandler, text = 'Henricus is able to offer blessing of the inquisition for those who complete {The Inquisition Quest} (1.0% extra gold).'})
keywordHandler:addKeyword({'inquisition quest'}, StdModule.say, {npcHandler = npcHandler, text = 'Go see Henricus to begin The Inquisition Quest, I have no mission for you, child.'})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, text = 'I\'m Jassu, a Kilika monk.'})
keywordHandler:addKeyword({'believer'}, StdModule.say, {npcHandler = npcHandler, text = 'Belive on the gods and they {inquisitors} will show you the path.'})
npcHandler:setMessage(MESSAGE_GREET, "Greetings fellow {believer}, would you like to receive {blessings} protection |PLAYERNAME|?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Always be on guard, |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "This ungraceful haste is most suspicious!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Last edited: