• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Blessings NPC not working

Polarbear72

Member
Joined
Mar 3, 2013
Messages
63
Solutions
1
Reaction score
5
Location
USA
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>
 
Solution
It has this error is server log and the NPC isn't loaded in game at all

Lua:
[Warning - NpcScript::NpcScript] Can not load script: bless.lua
data/npc/scripts/bless.lua:1: '(' expected near '.'
[Warning : Tyoric] NpcSystem:   Parameter(s) missing for item:     modified crossbow    8849    nil
[Warning - NpcScript::NpcScript] Can not load script: bless.lua
data/npc/scripts/bless.lua:1: '(' expected near '.'
[Warning - NpcScript::NpcScript] Can not load script: bless.lua
data/npc/scripts/bless.lua:1: '(' expected near '.'
Tried to do the fancy method, but I still suck at scripting I guess lmao

Try this
Lua:
local function countMissingBless(playerId)
    local player = Player(playerId)
    if not player then
        return 0...
Try this

Lua:
local function Player.countMissingBless(self)
    local count = 0
    for i = 1, 5 do
        if not player:hasBlessing(i) then
            count = count + 1
        end
    end
    return count
end

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 blessPricePer = 10000
    
    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, "blessing") or msgcontains(msg, "bless") then
            local inquisitionComplete = true
            if inquisitionComplete then
                local missingBlessCount = player:countMissingBless()
                if missingBlessCount > 0 then
                    npcHandler:say("Would you like to receive all missing common blessings for " .. blessPricePer .. " each? (Total:" .. (blessPricePer *  missingBlessCount) .. ")", cid)
                    npcHandler.topic[cid] = 1
                else
                    npcHandler:say("I only offer common blessings, which you already have in abundance.", cid)
                    npcHandler.topic[cid] = 0
                end
            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:removeMoney(blessPricePer * player:countMissingBless()) 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())
 
It has this error is server log and the NPC isn't loaded in game at all

Lua:
[Warning - NpcScript::NpcScript] Can not load script: bless.lua
data/npc/scripts/bless.lua:1: '(' expected near '.'
[Warning : Tyoric] NpcSystem:   Parameter(s) missing for item:     modified crossbow    8849    nil
[Warning - NpcScript::NpcScript] Can not load script: bless.lua
data/npc/scripts/bless.lua:1: '(' expected near '.'
[Warning - NpcScript::NpcScript] Can not load script: bless.lua
data/npc/scripts/bless.lua:1: '(' expected near '.'
 
It has this error is server log and the NPC isn't loaded in game at all

Lua:
[Warning - NpcScript::NpcScript] Can not load script: bless.lua
data/npc/scripts/bless.lua:1: '(' expected near '.'
[Warning : Tyoric] NpcSystem:   Parameter(s) missing for item:     modified crossbow    8849    nil
[Warning - NpcScript::NpcScript] Can not load script: bless.lua
data/npc/scripts/bless.lua:1: '(' expected near '.'
[Warning - NpcScript::NpcScript] Can not load script: bless.lua
data/npc/scripts/bless.lua:1: '(' expected near '.'
Tried to do the fancy method, but I still suck at scripting I guess lmao

Try this
Lua:
local function countMissingBless(playerId)
    local player = Player(playerId)
    if not player then
        return 0
    end
    local count = 0
    for i = 1, 5 do
        if not player:hasBlessing(i) then
            count = count + 1
        end
    end
    return count
end

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 blessPricePer = 10000
    
    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, "blessing") or msgcontains(msg, "bless") then
            local inquisitionComplete = true
            if inquisitionComplete then
                local missingBlessCount = countMissingBless(player:getId())
                if missingBlessCount > 0 then
                    npcHandler:say("Would you like to receive all missing common blessings for " .. blessPricePer .. " each? (Total:" .. (blessPricePer *  missingBlessCount) .. ")", cid)
                    npcHandler.topic[cid] = 1
                else
                    npcHandler:say("I only offer common blessings, which you already have in abundance.", cid)
                    npcHandler.topic[cid] = 0
                end
            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:removeMoney(blessPricePer * countMissingBless(player:getId()))) 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())
 
Solution
server code has this error with that code still not working

Lua:
[Warning - NpcScript::NpcScript] Can not load script: bless.lua
data/npc/scripts/bless.lua:50: 'then' expected near ')'
 
IT WORKS! thank you so much. The only issue i'm having now is that instead of actually saying player name it says " |PLAYERNAME| "

Lua:
npcHandler:say("You have been blessed by all of five gods!, |PLAYERNAME|.", cid)
 
IT WORKS! thank you so much. The only issue i'm having now is that instead of actually saying player name it says " |PLAYERNAME| "
Lua:
npcHandler:say("You have been blessed by all of five gods!, " .. player:getName() .. ".", cid)
 
how do i do if i have this issue but it's in npcs . xml?
Lua:
parameter key="message_walkaway" value="It was a pleasure to help you |PLAYERNAME|."/


solved problem was in npchanlder.lua inside onfarewell function
 
Last edited:
Back
Top