• 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!

TFS 0.X NPC BLESS [0.3.7] Global Prices

Otlandserv

Member
Joined
May 22, 2023
Messages
58
Reaction score
5
Hello.
I need NPC Bless with global prices...

For players below lvl 30 - 11,000 gp.
For players between 31 and 119 - [10000 + (1000 • [<lvl> - 30])] • 1.1 gp.
For players above lvl 120 - 110,000 gp.
 
Solution
Lua:
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

function greet(cid)
    talkState[cid] = 0
    return true
end

local function getNpcName()
    return getCreatureName(getNpcId())
end

local function countReceivedBlessings(cid)
    local count = 0
    for i = 1, 5 do
        if getPlayerBlessing(cid, i) then
            count = count + 1
        end
    end...
Lua:
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

function greet(cid)
    talkState[cid] = 0
    return true
end

local function getNpcName()
    return getCreatureName(getNpcId())
end

local function countReceivedBlessings(cid)
    local count = 0
    for i = 1, 5 do
        if getPlayerBlessing(cid, i) then
            count = count + 1
        end
    end
    return count
end

local function getTotalBlessingCost(cid)
    local level = getPlayerLevel(cid)
    if level <= 30 then
        level = 30
    elseif level > 120 then
        level = 120
    end
    local blessingCost = 2000 + (200 * (level - 30)) -- per blessing
    local amountOfMissingBlessings = 5 - countReceivedBlessings(cid)
    local totalCost = amountOfMissingBlessings * blessingCost
    return totalCost
end

local function giveAllMissingBlessings(cid)
    for i = 1, 5 do
        if not getPlayerBlessing(cid, i) then
            doPlayerAddBlessing(cid, i)
        end
    end
    return
end

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
 
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
    if msgcontains(msg, "name") then
        selfSay("My name is " .. getNpcName() .. ".", cid)
        talkState[talkUser] = 0
 
    elseif msgcontains(msg, "bless") then
        local cost = getTotalBlessingCost(cid)
        if cost == 0 then
            selfSay("You already have all 5 blessings.", cid)
            talkState[talkUser] = 0
            return
        end
        selfSay("It will cost you " .. cost .. " to receive the remaining " .. (5 - countReceivedBlessings(cid)) .. " blessing(s) you do not currently have. Do you accept this cost, pilgrim?", cid)
        talkState[talkUser] = 1

    elseif talkState[talkUser] == 1 then
        if not msgcontains(msg, "yes") then
            selfSay("Some other time then.", cid)
            talkState[talkUser] = 0
            return
        end
    
        local cost = getTotalBlessingCost(cid)
        if getPlayerMoney(cid) < cost then
            selfSay("You don't appear to have brought enough gold. Some other time then.", cid)
            talkState[talkUser] = 0
            return
        end
        doPlayerRemoveMoney(cid, cost)
        giveAllMissingBlessings(cid)
        selfSay("Wonderful! Here you are!", cid)
        talkState[talkUser] = 0
 
    end
    return true
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Back
Top