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

Stamina Regen on trainer TFS 1.3 8.60

nanduzenho

Member
Joined
Mar 21, 2021
Messages
187
Solutions
1
Reaction score
15
GitHub
nanduzenho
Good morning, I have this script that recovers stamina in the trainer. I would like it to work like this:
When the stamina is full, the message appears stating that it is full.
I managed to make the message appear, but only when the player enters the trainer with full stamina

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

local function addStamina(cid)
    local player = Player(cid)
    if not player then
        stopEvent(staminaEvents[cid])
        staminaEvents[cid] = nil
        return false
    end
    
    local actualStamina = player:getStamina()

    if actualStamina > 2400 and actualStamina < 2520 then
        delay = 12 * 60 * 1000 -- Stamina verde 12 mins
    elseif actualStamina == 2520 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are no longer refilling stamina, because your stamina is already full.")
        stopEvent(event)
        staminaEvents[cid] = nil
        return false
    end   
    
    player:setStamina(player:getStamina() + config.addTime)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You received "..config.addTime.." minute 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
 
Solution
You must add the stamina first and then do the check
Lua:
staminaEvents = {}
local config = {
    timeToAdd = 3,
    addTime = 1,
    fullStamina = 42*60
}

local function addStamina(cid)
    local player = Player(cid)
    if not player then
        stopEvent(staminaEvents[cid])
        staminaEvents[cid] = nil
        return false
    end
    -- first add
    player:setStamina(player:getStamina() + config.addTime)
    -- then check
    if player:getStamina() >= config.fullStamina then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are no longer refilling stamina, because your stamina is already full.")
        stopEvent(event)
        staminaEvents[cid] = nil
        return false
    end...
You must add the stamina first and then do the check
Lua:
staminaEvents = {}
local config = {
    timeToAdd = 3,
    addTime = 1,
    fullStamina = 42*60
}

local function addStamina(cid)
    local player = Player(cid)
    if not player then
        stopEvent(staminaEvents[cid])
        staminaEvents[cid] = nil
        return false
    end
    -- first add
    player:setStamina(player:getStamina() + config.addTime)
    -- then check
    if player:getStamina() >= config.fullStamina then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are no longer refilling stamina, because your stamina is already full.")
        stopEvent(event)
        staminaEvents[cid] = nil
        return false
    end
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You received "..config.addTime.." minute of stamina.")
    staminaEvents[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
end

function onStepIn(creature)
    if creature:isPlayer() then
        -- also a new check is required
        if creature:getStamina() >= config.fullStamina then
            return creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are no longer refilling stamina, because your stamina is already full.")
        end
        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
 
Last edited:
Solution
You must add the stamina first and then do the check
Lua:
staminaEvents = {}
local config = {
    timeToAdd = 3,
    addTime = 1,
    fullStamina = 42*60
}

local function addStamina(cid)
    local player = Player(cid)
    if not player then
        stopEvent(staminaEvents[cid])
        staminaEvents[cid] = nil
        return false
    end
    -- first add
    player:setStamina(player:getStamina() + config.addTime)
    -- then check
    if player:getStamina() >= config.fullStamina then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are no longer refilling stamina, because your stamina is already full.")
        stopEvent(event)
        staminaEvents[cid] = nil
        return false
    end
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You received "..config.addTime.." minute of stamina.")
    staminaEvents[cid] = addEvent(addStamina, config.timeToAdd * 60 * 1000, cid)
end

function onStepIn(creature)
    if creature:isPlayer() then
        -- also a new check is required
        if creature:getStamina() >= config.fullStamina then
            return creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are no longer refilling stamina, because your stamina is already full.")
        end
        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
thanks bro, it worked =@
 
Back
Top