• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Npc Bless

xLosT

Member
Joined
Jan 11, 2010
Messages
1,021
Reaction score
13
Location
Brasil, Rio Grande do Sul
i have one npc to sell bless, in tfs 1.0 the calculation does not work, he always takes the minimum value regardless of the level

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talktopic, amount, playerLevel = {}, {}, {}
local str = ""

--Config
local highLevelPrice = 15000 --(Real Tibia Price: 20000) price for players level 120+, per blessing
local lowLevelPrice = 1000 --(Real Tibia Price: 2000) price for players level 30 and lower, per blessing
local pricePerLevel = 75 --(Real Tibia Price: 200) this price only applies to players between level 30 & 120, formula=((pricePerLevel*playerLevel)+lowLevelPrice)
--Text
local text = "Do you want to buy all five blessings for " --leave this unfinished (it will add the price to the end)
local thankyou = "You have bought all 5 of my blessings for " --leave this unfinished (it will add the price to the end)
local help = "I can give all of you my {blessings} for free. Blessings will protect you from losing items on death and reduce the amount of levels you lose when you die."
local already = "You already have my blessings."
local nomoney = "You don\'t have enough money for all five blessings."

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

function greetCallback(cid)
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    talktopic[talkUser], amount[talkUser], playerLevel[talkUser] = 0, 0, 0
    return true
end

function creatureSayCallback(cid, type, msg)

talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if(not npcHandler:isFocused(cid)) then
        return false
    end
   
playerLevel[talkUser] = getPlayerLevel(cid)
amount[talkUser] = 0

    if (getPlayerBlessing(cid,1)
        and getPlayerBlessing(cid,2)
            and getPlayerBlessing(cid,3)
                and getPlayerBlessing(cid,4)
                    and getPlayerBlessing(cid,5)) then
                npcHandler:say(already, cid)
                return false
    else
        if playerLevel[talkUser] < 75 then
         amount[talkUser] = lowLevelPrice*5
         str = "{"..amount[talkUser].."}gp?"
            elseif playerLevel[talkUser] > 75 and playerLevel[talkUser] < 150 then
                amount[talkUser] = (((playerLevel[talkUser]-30)*pricePerLevel)+lowLevelPrice)*5
                str = "{"..amount[talkUser].."}gp?"
                    elseif playerLevel[talkUser] >= 150 then
                        amount[talkUser] = highLevelPrice*5
                        str = "{"..amount[talkUser].."}gp?"
        end
    end
   
    str = text..str
   
        if (msgcontains(msg, "help") or msgcontains(msg, "job")) then
            talktopic[talkUser] = 0
            npcHandler:say(help, cid)
   
        elseif talktopic[talkUser] == 0 and (msgcontains(msg, "yes") or msgcontains(msg, "blessings") or msgcontains(msg, "blessing")) then
            talktopic[talkUser] = 1
            npcHandler:say(str, cid)
           
        elseif talktopic[talkUser] == 1 and (msgcontains(msg, "yes") or msgcontains(msg, "ok")) then
            talktopic[talkUser] = 2
                if doPlayerRemoveMoney(cid, amount[talkUser]) then
                    for i = 1,5 do
                    doPlayerAddBlessing(cid,i)
                    end
                    npcHandler:say(thankyou.."{"..amount[talkUser].."}", cid)
                else
                 npcHandler:say(nomoney, cid)
                 return false
                end
        end
    return true
end

npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. Do you want my {blessings}?")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Please visit again. You never know when you may need my blessings!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Please visit again |PLAYERNAME|")

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
this one works
Code:
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

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local player = Player(cid)

    if player:getLevel() < 75 then
        blessprize = 1000*5
    elseif player:getLevel() >= 75 and player:getLevel() <= 150 then
        blessprize = (((player:getLevel()-30)*75)+1000)*5
    elseif player:getLevel() > 150 then
        blessprize = 15000*5
    end


    if(msgcontains(msg, "blessing") or msgcontains(msg, "bless")) then
            npcHandler:say("Do you want to receive all blessings for "..blessprize.." gold?", cid)
            npcHandler.topic[cid] = 1
    end
    if(msgcontains(msg, "yes")) then
        if(npcHandler.topic[cid] == 1) then
            if player:hasBlessing(1) or player:hasBlessing(2) or player:hasBlessing(3) or player:hasBlessing(4) or player:hasBlessing(5) then
                npcHandler:say("You already have been blessed!", cid)
            else
                if player:removeMoney(blessprize) then
                    npcHandler:say("You have been blessed by all of five gods!, " .. player:getName() .. ".", cid)
                    player:addBlessing(1)
                    player:addBlessing(2)
                    player:addBlessing(3)
                    player:addBlessing(4)
                    player:addBlessing(5)
                    player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
                    npcHandler.topic[cid] = 0
                else
                    npcHandler:say("Come back when you have enough money.", cid)
                    npcHandler.topic[cid] = 0
                end
            end
        end
    end
    if(msgcontains(msg, "no")) then
        if(npcHandler.topic[cid] > 0) then
            npcHandler:say("Then no.", cid)
            npcHandler.topic[cid] = 0
        end
    end
    return true
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())
 
Code:
function getBlessingsCost(level)
    if level <= 30 then
        return 2000
    elseif level >= 120 then
        return 20000
    else
        return ((level - 20) * 200)
    end
end

function getPvpBlessingCost(level)
    if level <= 30 then
        return 2000
    elseif level >= 270 then
        return 50000
    else
        return ((level - 20) * 200)
    end
end
https://github.com/otland/forgottenserver/blob/master/data/global.lua

;o
 
Back
Top