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

TalkAction [TFS 1.3] !stamina n -- buy stamina for gold!

Michael Orsino

Premium User
Premium User
Support Team
Joined
Nov 15, 2007
Messages
854
Solutions
10
Reaction score
389
Location
Santiago, Chile (Australian)
Hi guys

Here is a simple talkaction that allows players to buy stamina for gold.
You can easily configure how much 1 minute of stamina costs, and how much stamina players are allowed to buy up to.
I suggest you do not allow players to buy up to and including bonus hours.

data\talkactions\talkactions.xml
XML:
<talkaction words="!stamina" separator=" " script="stamina.lua" />
data\talkactions\scripts\stamina.lua
Lua:
function onSay(player, words, param)

  local goldMultiplier = 100 --this is the price for 1 minute of regular stamina
  local maxBuyStamina = 2400 --maximum amount of minutes you can have (40 hours = 2400 mintes) this restricts the buying of bonus stamina (or not)

  local count = tonumber(param)

  if count == nil then
    player:sendCancelMessage("You must specify a number of minutes you want to buy")
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
  end
  if player:getStamina() >= maxBuyStamina then
    player:sendCancelMessage("You already have enough stamina, you can only buy up to " .. math.floor(maxBuyStamina/60) .." hours.")
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
  end
  if player:getStamina() + count > maxBuyStamina then
    excess = math.floor(player:getStamina() + count - 2520 + (2520 - maxBuyStamina))
    else
    excess = 0
  end

  local price = math.floor((count - excess) * goldMultiplier)
  if player:removeMoney(price) then
    player:setStamina(player:getStamina() + count - excess)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have bought " .. count - excess .. " minute(s) of stamina.")
    return true
    else
    player:sendCancelMessage("You don't have enough money, " .. count - excess .. " minute(s) of stamina costs " .. price .. " gold coins.")
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
  end
end
 
Last edited:
Hello, nice script :)

Just a small thing:

player:setStamina(player:getStamina() - 1000)

The player is losing 16.6h just for not typing the parameter. I believe you should remove it.
Best regards
 
Back
Top