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

heitorzinhotc

Viva la Vida!
Joined
Aug 8, 2008
Messages
107
Reaction score
8
I am using script below in the movements, in the tile from the coaches.
But when the player leaves the tile, he continues to receive stamina.

Can you help me? I would like you to stop raising the stamina when the player leaves the tile.

TFS 1.3, version 12.

Lua:
eventsId = {}

local function rechargeStamina(cid)
    local player = Player(cid)

    if not player then
        eventsId[cid] = nil
        return
    end

    player:setStamina(player:getStamina() + 1)

    eventsId[cid] = addEvent(rechargeStamina, 180000, cid)
end

function onStepIn(creature, item, position, fromPosition)
    if creature:isPlayer() then
        local cid = creature:getId()
        eventsId[cid] = addEvent(rechargeStamina, 180000, cid)
    end

    return true
end

function onStepOut(creature, item, pos, fromPosition)
    if creature:isPlayer() then
        local cid = creature:getId()
        stopEvent(eventsId[cid])
        eventsId[cid] = nil
    end

    return true
end
 
I am using script below in the movements, in the tile from the coaches.
But when the player leaves the tile, he continues to receive stamina.

Can you help me? I would like you to stop raising the stamina when the player leaves the tile.

TFS 1.3, version 12.

Lua:
eventsId = {}

local function rechargeStamina(cid)
    local player = Player(cid)

    if not player then
        eventsId[cid] = nil
        return
    end

    player:setStamina(player:getStamina() + 1)

    eventsId[cid] = addEvent(rechargeStamina, 180000, cid)
end

function onStepIn(creature, item, position, fromPosition)
    if creature:isPlayer() then
        local cid = creature:getId()
        eventsId[cid] = addEvent(rechargeStamina, 180000, cid)
    end

    return true
end

function onStepOut(creature, item, pos, fromPosition)
    if creature:isPlayer() then
        local cid = creature:getId()
        stopEvent(eventsId[cid])
        eventsId[cid] = nil
    end

    return true
end
Code:
local function Stamina(playerId, seconds)
    local player = Player(playerId)
    if seconds > 0 and player then
            player:setStamina(player:getStamina() + 1)
        addEvent(Stamina, 1000, playerId, seconds - 1)
    end
end

local coolDownStorageID = 666711
local coolDownSeconds = 10

function onStepIn(player, item, position, fromPosition)
    if player:getStorageValue(coolDownStorageID) <= os.time() then
        player:setStorageValue(coolDownStorageID, os.time() + (coolDownSeconds - 1))
        return Stamina(player:getId(), coolDownSeconds)
    end
    return not player:sendCancelMessage("You are exhausted.")
end

Cooldown, after 10 seconds from stepout its will stoped
@edit, fixed
 
Last edited:
Code:
local function Stamina(playerId, seconds)
    local player = Player(playerId)
    if seconds > 0 and player then
            player:setStamina(player:getStamina() + 1)
        addEvent(Stamina, 1000, playerId, seconds - 1)
    end
end

local coolDownStorageID = 666711
local coolDownSeconds = 10

function onStepIn(player, item, position, fromPosition)
    if player:getStorageValue(coolDownStorageID) <= os.time() then
        player:setStorageValue(coolDownStorageID, os.time() + (coolDownSeconds - 1))
        return Stamina(player:getId(), coolDownSeconds)
    end
    return not player:sendCancelMessage("You are exhausted.")
end

end

Cooldown, after 10 seconds from stepout its will stoped


Error:

[Warning - Event::checkScript] Can not load script: scripts/empireot/stamina.lua
data/movements/scripts/empireot/stamina.lua:20: '<eof>' expected near 'end'
 
I removed the last "end" to correct the error.

Now it's going up without stopping for 3 minutes.
And the resistance goes up even when it comes out of the tile.
Post automatically merged:

is going up without stopping and without being on the tile.
 
Last edited:
I removed the last "end" to correct the error.

Now it's going up without stopping for 3 minutes.
And the resistance goes up even when it comes out of the tile.
Post automatically merged:

is going up without stopping and without being on the tile.
I removed the last "end" to correct the error.

Now it's going up without stopping for 3 minutes.
And the resistance goes up even when it comes out of the tile.
Post automatically merged:

is going up without stopping and without being on the tile.
"Cooldown, after 10 seconds from stepout its will stoped"
"Cooldown, after 10 seconds from stepout its will stoped"


Check if it stoped after 10 sec when you step out...
 
post the events.xml pleasse
It's an onStepIn script, so you just the regular movements.xml line

example using actionid
Lua:
<movevent event="StepIn" actionid="45001" script="staminaTile.lua" />
 
Back
Top