• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Lua [Talkaction] Auto-Bless command TFS 1.4.2

Galatea

Banned User
Joined
Sep 8, 2022
Messages
41
Reaction score
14
Location
Germany
Hello everyone, I heartily need some help, namely I need an auto-bless script which will enable the player to turn on / turn off function. If a player falls and has to turn on the command, it automatically after death, when he logs in, buys him blessings - cash from the bank.

I found something like this:
Lua:
local blessings = {1, 2, 3, 4, 5}
function getCost(level)
  if level <= 150 then
    return 10000 * 2 -- 2cc 1 - 150 lvl
  elseif level <= 200 then
    return 10000 * 5 -- 5cc 150 - 200 lvl
  elseif level >= 300 then
    return 10000 * 20 -- 20cc - 300+ lvl
  else
    return ((level - 20) * 100 * 5) -- based on level 200-300
  end
end

function onLogin(player)
  if not player:hasBlessing(#blessings) and player:isVip() then
      local cost = getCost(player:getLevel())
      local moneyCount = player:getMoney()
      local bankCount = player:getBankBalance()
      if cost > moneyCount + bankCount then
        player:sendCancelMessage("You need " .. cost .. " gold coins to buy all blessings.")
        return true
      end

      player:removeMoney(math.min(cost, moneyCount))
      if cost > moneyCount then
        player:setBankBalance(bankCount - math.max(cost - moneyCount, 0))
        if moneyCount == 0 then
          player:sendTextMessage(
            MESSAGE_INFO_DESCR,
            ("Paid %d gold from bank account. Your account balance is now %d gold."):format(cost, player:getBankBalance())
          )
        else
          player:sendTextMessage(
            MESSAGE_INFO_DESCR,
            ("Paid %d from inventory and %d gold from bank account. Your account balance is now %d gold."):format(
              moneyCount,
              cost - moneyCount,
              player:getBankBalance()
            )
          )
        end
      end

      for b = 1, #blessings do
        player:addBlessing(b, 1)
      end
      player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
      player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have been blessed by the gods!")
  end

  return true
end

And @Nekiro answered in this post something like this:
if not player:isVip() then
return true
end

-- switch the value
player:setStorageValue(9999, player:getStorageValue(9999) == -1 and 1 or -1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Automatic blessing buying is turned " .. (player:getStorageValue(9999) == 1 and "on" or "off"))
if player:getStorageValue(9999) == 1 then

For any help rep++ 10.98 1.4.2
 
Solution
Hello everyone, I heartily need some help, namely I need an auto-bless script which will enable the player to turn on / turn off function. If a player falls and has to turn on the command, it automatically after death, when he logs in, buys him blessings - cash from the bank.

I found something like this:
Lua:
local blessings = {1, 2, 3, 4, 5}
function getCost(level)
  if level <= 150 then
    return 10000 * 2 -- 2cc 1 - 150 lvl
  elseif level <= 200 then
    return 10000 * 5 -- 5cc 150 - 200 lvl
  elseif level >= 300 then
    return 10000 * 20 -- 20cc - 300+ lvl
  else
    return ((level - 20) * 100 * 5) -- based on level 200-300
  end
end

function onLogin(player)
  if not player:hasBlessing(#blessings) and player:isVip() then...

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,245
Solutions
545
Reaction score
4,481
Hello everyone, I heartily need some help, namely I need an auto-bless script which will enable the player to turn on / turn off function. If a player falls and has to turn on the command, it automatically after death, when he logs in, buys him blessings - cash from the bank.

I found something like this:
Lua:
local blessings = {1, 2, 3, 4, 5}
function getCost(level)
  if level <= 150 then
    return 10000 * 2 -- 2cc 1 - 150 lvl
  elseif level <= 200 then
    return 10000 * 5 -- 5cc 150 - 200 lvl
  elseif level >= 300 then
    return 10000 * 20 -- 20cc - 300+ lvl
  else
    return ((level - 20) * 100 * 5) -- based on level 200-300
  end
end

function onLogin(player)
  if not player:hasBlessing(#blessings) and player:isVip() then
      local cost = getCost(player:getLevel())
      local moneyCount = player:getMoney()
      local bankCount = player:getBankBalance()
      if cost > moneyCount + bankCount then
        player:sendCancelMessage("You need " .. cost .. " gold coins to buy all blessings.")
        return true
      end

      player:removeMoney(math.min(cost, moneyCount))
      if cost > moneyCount then
        player:setBankBalance(bankCount - math.max(cost - moneyCount, 0))
        if moneyCount == 0 then
          player:sendTextMessage(
            MESSAGE_INFO_DESCR,
            ("Paid %d gold from bank account. Your account balance is now %d gold."):format(cost, player:getBankBalance())
          )
        else
          player:sendTextMessage(
            MESSAGE_INFO_DESCR,
            ("Paid %d from inventory and %d gold from bank account. Your account balance is now %d gold."):format(
              moneyCount,
              cost - moneyCount,
              player:getBankBalance()
            )
          )
        end
      end

      for b = 1, #blessings do
        player:addBlessing(b, 1)
      end
      player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
      player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have been blessed by the gods!")
  end

  return true
end

And @Nekiro answered in this post something like this:



For any help rep++ 10.98 1.4.2
Yeah correct.

In the login function, just add a check for the storage.

so change this
Lua:
function onLogin(player)
    if not player:hasBlessing(#blessings) and player:isVip() then
        local cost = getCost(player:getLevel())
for this
Lua:
function onLogin(player)
    if player:getStorageValue(9999) ~= 1 then
        return true
    end
    if not player:hasBlessing(#blessings) and player:isVip() then
        local cost = getCost(player:getLevel())

and then make a talkaction to enable/disable it
Lua:
local talk = TalkAction("/toggleautobless", "!toggleautobless")

function talk.onSay(player, words, param)
    player:setStorageValue(9999, player:getStorageValue(9999) == -1 and 1 or -1)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Automatic blessing buying is turned " .. (player:getStorageValue(9999) == 1 and "on" or "off"))
    return false
end

talk:separator(" ")
talk:register()
 
Solution
Top