Polarbear72
Member
I'm trying to make blessing NPC sell all 5 blessings at once for a flat 50k. Currently its not working the second code in this post is the error I getting on server log whenever I try to purchase blessings in game. Any help is appreciated. Any script will work as no matter how basic as long as I can purchase all 5 blessings at once from NPC.
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 = 50000
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())
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/bless.lua:onCreatureSay
data/npc/scripts/bless.lua:30: attempt to call method 'getBlessings' (a nil value)
stack traceback:
[C]: in function 'getBlessings'
data/npc/scripts/bless.lua:30: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:411: in function 'onCreatureSay'
data/npc/scripts/bless.lua:7: in function <data/npc/scripts/bless.lua:7>