Grillo1995
New Member
Hello, I need help with this script.
I made the changes in the source to add onChangeZone and so far so good.
However these scripts are bug, he add more stamina after leaving the protect zone does not stop adding! It does not end the event of adding stamina!
There is no mistake, only the player is gaining stamina.
data/global.lua
events/scripts/player.lua
When I left the protection zone I got the message in the game: You are no longer refilling stamina, since you left a regeneration zone.
However, he continues to gain stamina.
How to solve? Thank you and I'm waiting!
I made the changes in the source to add onChangeZone and so far so good.
However these scripts are bug, he add more stamina after leaving the protect zone does not stop adding! It does not end the event of adding stamina!
There is no mistake, only the player is gaining stamina.
data/global.lua
Code:
function addStamina(id, amountStamina, delay)
local staminaRegen = {}
local event = staminaRegen[id]
local player = Player(id)
if not player then
stopEvent(event)
staminaRegen[id] = 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_STATUS_SMALL, "You are no longer refilling stamina, because your stamina is already full.")
stopEvent(event)
staminaRegen[id] = nil
return false
end
player:setStamina(actualStamina + 1)
player:sendTextMessage(MESSAGE_STATUS_SMALL, "One minute of stamina has been refilled.")
stopEvent(event)
staminaRegen[id] = addEvent(addStamina, delay, id, amountStamina, delay)
return true
end
events/scripts/player.lua
Code:
function Player:onChangeZone(zone)
if not self:isPremium() then
return false
end
local staminaRegen = {}
local event = staminaRegen[self:getId()]
if zone == ZONE_PROTECTION then
if self:getStamina() < 2520 then
if not event then
local delay = 2
if self:getStamina() > 2400 and self:getStamina() <= 2520 then
delay = 8
end
staminaRegen[self:getId()] = addEvent(addStamina, delay * 60 * 1000, self:getId(), 1, delay * 60 * 1000)
end
end
else
if zone ~= ZONE_PROTECTION then
self:sendTextMessage(MESSAGE_STATUS_SMALL, "You are no longer refilling stamina, since you left a regeneration zone.")
stopEvent(event)
stopEvent(staminaRegen[self:getId()])
staminaRegen[self:getId()] = nil
return false
end
end
end
When I left the protection zone I got the message in the game: You are no longer refilling stamina, since you left a regeneration zone.
However, he continues to gain stamina.
How to solve? Thank you and I'm waiting!
Last edited: