nanduzenho
Member
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
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