- 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
data\talkactions\scripts\stamina.lua
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" />
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: