• 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 1.2 Trainer stamina regen.

paweleq2000

New Member
Joined
Feb 18, 2011
Messages
161
Reaction score
4
Hello,
I need that script, so if we skill on trainers we get 1 minute of stamina where we are training 3 minutes i saw this system on a few ots but i cant find it.
 
Try it
in events creature.lua
Lua:
 -- HERE TRAINER ONLINE
local staminaBonus = {
    target ='TRAINER NAME',
    period = 180000, -- Period in milliseconds
    bonus = 1, -- gain stamina
    events = {}
}

local function addStamina(name)
    local player = Player(name)
    if not player then
        staminaBonus.events[name] = nil
    else
        local target = player:getTarget()
        if not target or target:getName() ~= staminaBonus.target then
            staminaBonus.events[name] = nil
        else
            player:setStamina(player:getStamina() + staminaBonus.bonus)
            staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
        end
    end
end

in the function
Lua:
Creature:onTargetCombat(target)
under the last return true
Lua:
 if self:isPlayer() then
        if target and target:getName() == staminaBonus.target then
            local name = self:getName()
            if not staminaBonus.events[name] then
                staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
            end
        end
       end
 
Last edited:
Try it
in events creature.lua
Lua:
 -- HERE TRAINER ONLINE
local staminaBonus = {
    target ='TRAINER NAME',
    period = 180000, -- Period in milliseconds
    bonus = 1, -- gain stamina
    events = {}
}

local function addStamina(name)
    local player = Player(name)
    if not player then
        staminaBonus.events[name] = nil
    else
        local target = player:getTarget()
        if not target or target:getName() ~= staminaBonus.target then
            staminaBonus.events[name] = nil
        else
            player:setStamina(player:getStamina() + staminaBonus.bonus)
            staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
        end
    end
end

in the function
Lua:
Creature:onTargetCombat(target)
under the last return true
Lua:
 if self:isPlayer() then
        if target and target:getName() == staminaBonus.target then
            local name = self:getName()
            if not staminaBonus.events[name] then
                staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
            end
        end
       end



add where?

Lua:
Creature:onTargetCombat(target)

Lua:
 if self:isPlayer() then
        if target and target:getName() == staminaBonus.target then
            local name = self:getName()
            if not staminaBonus.events[name] then
                staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
            end
        end
       end






Code:
function Creature:onTargetCombat(target)
    if not self then
        if self:isPlayer() then
        if target and target:getName() == staminaBonus.target then
            local name = self:getName()
            if not staminaBonus.events[name] then
                staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
            end
        end
       end
        return true
    end
?
 
Last edited:
@leandroluck @adrianootavares
You can use this as a moveevent aswell, just set action id to a tile and when you step in is going to start charging your stamina

XML:
 <movevent event="StepIn" actionid="XXXXX" script="others/stamina_tile.lua" />
<movevent event="StepOut" actionid="XXXXX" script="others/stamina_tile.lua" />

Lua:
staminaEvents = {}
local config = {
    timeToAdd = 5,
    addTime = 1,
}

local function addStamina(cid)
    local player = Player(cid)
    if not player then
        stopEvent(staminaEvents[cid])
        staminaEvents[cid] = nil
        return true
    end
    player:setStamina(player:getStamina() + config.addTime)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You received "..config.addTime.." minutes of stamina.")
    staminaEvents[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
end

function onStepIn(creature)
    if creature:isPlayer() then
        creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You will receive "..config.addTime.." minute of stamina every "..config.timeToAdd.." minutes.")
        staminaEvents[creature:getId()] = addEvent(addStamina, config.timeToAdd * 60 * 1000, creature:getId())
    end
    return true
end

function onStepOut(creature)
    if creature:isPlayer() then
        stopEvent(staminaEvents[creature:getId()])
        staminaEvents[creature:getId()] = nil
    end
    return true
end
 
@leandroluck @adrianootavares
You can use this as a moveevent aswell, just set action id to a tile and when you step in is going to start charging your stamina

XML:
 <movevent event="StepIn" actionid="XXXXX" script="others/stamina_tile.lua" />
<movevent event="StepOut" actionid="XXXXX" script="others/stamina_tile.lua" />

Lua:
staminaEvents = {}
local config = {
    timeToAdd = 5,
    addTime = 1,
}

local function addStamina(cid)
    local player = Player(cid)
    if not player then
        stopEvent(staminaEvents[cid])
        staminaEvents[cid] = nil
        return true
    end
    player:setStamina(player:getStamina() + config.addTime)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You received "..config.addTime.." minutes of stamina.")
    staminaEvents[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
end

function onStepIn(creature)
    if creature:isPlayer() then
        creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You will receive "..config.addTime.." minute of stamina every "..config.timeToAdd.." minutes.")
        staminaEvents[creature:getId()] = addEvent(addStamina, config.timeToAdd * 60 * 1000, creature:getId())
    end
    return true
end

function onStepOut(creature)
    if creature:isPlayer() then
        stopEvent(staminaEvents[creature:getId()])
        staminaEvents[creature:getId()] = nil
    end
    return true
end

Bro this run in OTX 2?

The scrypt is 100% or i need edit ?
 
Bro this run in OTX 2?

The scrypt is 100% or i need edit ?

You need to use OTX 3 to run the quoted script, OTX 2 is based on 0.3.7 and the one you need is based on 1.3.
If you still need an stamina script for OTX 2 this one will work good [Request] Stamina Refiller TFS 0.4 (https://otland.net/threads/request-stamina-refiller-tfs-0-4.242238/#post-2345516) or try this moveevent (not tested)

Lua:
addSta = {}
local config = {
timeToAdd = 3, -- intervalo de tempo para adicionar.
addTime = 5, -- quanto vai adicionar.
}

local function addStamina(cid, check)
    if not isPlayer(cid) then
        addSta[cid] = nil
    return true
    end
   
    if check then return true end
   
    doPlayerSetStamina(cid, getPlayerStamina(cid) + config.addTime)
    doPlayerSendTextMessage(cid, 25, "Você recebeu "..config.addTime.." minutos de stamina.")
    addSta[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid, false)
end

function onStepIn(cid)
    if isPlayer(cid) then
        addSta[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid, false)
    end
return true
end

function onStepOut(cid)
    if isPlayer(cid) then
        stopEvent(addSta[cid])
        addSta[cid] = nil
        addStamina (cid, true)
    end
return true
end
 
add where?

Script ?
Try it
in events creature.lua
Lua:
 -- HERE TRAINER ONLINE
local staminaBonus = {
    target ='TRAINER NAME',
    period = 180000, -- Period in milliseconds
    bonus = 1, -- gain stamina
    events = {}
}

local function addStamina(name)
    local player = Player(name)
    if not player then
        staminaBonus.events[name] = nil
    else
        local target = player:getTarget()
        if not target or target:getName() ~= staminaBonus.target then
            staminaBonus.events[name] = nil
        else
            player:setStamina(player:getStamina() + staminaBonus.bonus)
            staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
        end
    end
end

in the function
Lua:
Creature:onTargetCombat(target)
under the last return true
Lua:
if self:isPlayer() then
        if target and target:getName() == staminaBonus.target then
            local name = self:getName()
            if not staminaBonus.events[name] then
                staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
            end
        end
       end
 
data/events/scripts/creature.lua

Thank you.

So, the code will be:


-- HERE TRAINER ONLINE
local staminaBonus = {
target ='Training Machine',
period = 60000, -- Period in milliseconds
bonus = 2, -- gain stamina
events = {}
}

local function addStamina(name)
local player = Player(name)
if not player then
staminaBonus.events[name] = nil
else
local target = player:getTarget()
if not target or target:getName() ~= staminaBonus.target then
staminaBonus.events[name] = nil
else
player:setStamina(player:getStamina() + staminaBonus.bonus)
staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)

Creature:eek:nTargetCombat(target)

end
end
end


Is that ?
 
pergher said:
Does anybody knows how to add mana regeneration while training?

Here is an option by using globalevents, this is for 0.4, you just need to register which tiles will give regeneation by position
Lua:
local positions = {
{ x = 123, y = 123, z = 7},
{ x = 124, y = 124, z = 7},
{ x = 125, y = 125, z = 9}
}
function onThink(cid, interval, lastExecution)
for _, pos in ipairs(positions) do
pl = getTopCreature(pos)
doSendMagicEffect(pos, 12)
if pl.itemid == 1 then
doCreatureAddMana(pl.uid, math.random(1,7))
end
end
return TRUE
end

For 1.3 try by using
Lua:
player:addMana(player:getMaxMana())
and
Code:
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)

instead of
Lua:
doCreatureAddMana(pl.uid, math.random(1,7))
and
Lua:
doSendMagicEffect(pos, 12)

another way could be start converting the script on the top of the thread like this...
Lua:
local function addMana(cid)
    local player = Player(cid)
    if not player then
        stopEvent(manaEvents[cid])
        manaEvents[cid] = nil
        return true
    end
    player:addMana(player:getMaxMana())
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You received mana.")

with this you can start with something, good luck!
 
Back
Top