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

Lua [TFS 1.2] Buying all (5) bless by click on item

Xedoxo

Member
Joined
Oct 24, 2010
Messages
131
Reaction score
19
Hi

I looking for a script like in title thread - when player click to item (on map) example any statue with ID xxx/uniqueidxxxx he gain all (5) bless for xxx amount of gold. Can be scale with level, but not necessery. Thank you.
 
Solution
F
@Xedoxo
Make sure to use his script its cleaner and better
Just in case if you ever make it possible to get one bless only, his script will avoid problems later
For servers that have single blessings available, it should calculate what blessings are first missing, then have a price per blessing

they should use something like this:

LUA:
local config = {
    pricePerBlessing = 1000,
    maxBlessings = 5
}

function onUse(player, item, fromPos, target, toPos, isHotkey)
    local inactive = {}
    for i = 1, config.maxBlessings do
        if not player:hasBlessing(i) then
            table.insert(inactive, i)
        end
    end

    if next(inactive) == nil then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You already...
LUA:
local money = 1000
local blessings = {1, 2, 3, 4, 5}

function onUse(player, item, fromPos, target, toPos, isHotkey)
    if not player then
        return true
    end
    for i = 1, #blessings do
        if player:hasBlessing(blessings[i]) then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'You alredy got all blessings')
            return true
        end
    end
    if player:removeMoney(money) then
        for i = 1, #blessings do
            player:addBlessing(blessings[i])
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You received all blessings')
        end
    end
    return true
end

Try this, not tested
 
LUA:
local money = 1000
local blessings = {1, 2, 3, 4, 5}

function onUse(player, item, fromPos, target, toPos, isHotkey)
    if not player then
        return true
    end
    for i = 1, #blessings do
        if player:hasBlessing(blessings[i]) then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'You alredy got all blessings')
            return true
        end
    end
    if player:removeMoney(money) then
        for i = 1, #blessings do
            player:addBlessing(blessings[i])
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You received all blessings')
        end
    end
    return true
end

Try this, not tested
If the player only has blessing 1, but not 2, 3, 4 and 5 it will still say they have all blessings...
 
There no will be any other option to buy bless, so nobody will have 1 bless or something. Just 0 or all.

Going to test it and i'll back here with info.
In that case, use this:
LUA:
local config = {
    price = 1000,
    maxBlessings = 5
}

function onUse(player, item, fromPos, target, toPos, isHotkey)
    if player:hasBlessing(1) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You already have all blessings")
        return true
    end
 
    if not player:removeMoney(config.price) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have enough money")
        return true
    end
 
    for i = 1, config.maxBlessings do
        if not player:hasBlessing(i) then
            player:addBlessing(i)
        end
    end
 
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You received all blessings")
    return true
end
 
@Xedoxo
Make sure to use his script its cleaner and better
Just in case if you ever make it possible to get one bless only, his script will avoid problems later
 
@Xedoxo
Make sure to use his script its cleaner and better
Just in case if you ever make it possible to get one bless only, his script will avoid problems later
For servers that have single blessings available, it should calculate what blessings are first missing, then have a price per blessing

they should use something like this:

LUA:
local config = {
    pricePerBlessing = 1000,
    maxBlessings = 5
}

function onUse(player, item, fromPos, target, toPos, isHotkey)
    local inactive = {}
    for i = 1, config.maxBlessings do
        if not player:hasBlessing(i) then
            table.insert(inactive, i)
        end
    end

    if next(inactive) == nil then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You already have all blessings")
        return true
    end
 
    if not player:removeMoney(config.pricePerBlessing * #inactive) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have enough money")
        return true
    end
 
    for _, blessingId in ipairs(inactive) do
        player:addBlessing(blessingId)
    end
 
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You received all blessings")
    return true
end
 
Solution
Back
Top