diff --git a/data-canary/scripts/globalevents/save_interval.lua b/data-canary/scripts/globalevents/save_interval.lua index 3e1c16326e4..5de9123ef17 100644 --- a/data-canary/scripts/globalevents/save_interval.lua +++ b/data-canary/scripts/globalevents/save_interval.lua @@ -1,3 +1,14 @@ +local SAVE_INTERVAL_TYPE = configManager.getString(configKeys.SAVE_INTERVAL_TYPE) +local SAVE_INTERVAL_CONFIG_TIME = configManager.getNumber(configKeys.SAVE_INTERVAL_TIME) +local SAVE_INTERVAL_TIME = 0 +if SAVE_INTERVAL_TYPE == "second" then + SAVE_INTERVAL_TIME = 1000 +elseif SAVE_INTERVAL_TYPE == "minute" then + SAVE_INTERVAL_TIME = 60 * 1000 +elseif SAVE_INTERVAL_TYPE == "hour" then + SAVE_INTERVAL_TIME = 60 * 60 * 1000 +end + local function serverSave(interval) if configManager.getBoolean(configKeys.TOGGLE_SAVE_INTERVAL_CLEAN_MAP) then cleanMap() diff --git a/data-otservbr-global/scripts/globalevents/customs/save_interval.lua b/data-otservbr-global/scripts/globalevents/customs/save_interval.lua index 6e24bc53edc..d6c616034ab 100644 --- a/data-otservbr-global/scripts/globalevents/customs/save_interval.lua +++ b/data-otservbr-global/scripts/globalevents/customs/save_interval.lua @@ -1,3 +1,14 @@ +local SAVE_INTERVAL_TYPE = configManager.getString(configKeys.SAVE_INTERVAL_TYPE) +local SAVE_INTERVAL_CONFIG_TIME = configManager.getNumber(configKeys.SAVE_INTERVAL_TIME) +local SAVE_INTERVAL_TIME = 0 +if SAVE_INTERVAL_TYPE == "second" then + SAVE_INTERVAL_TIME = 1000 +elseif SAVE_INTERVAL_TYPE == "minute" then + SAVE_INTERVAL_TIME = 60 * 1000 +elseif SAVE_INTERVAL_TYPE == "hour" then + SAVE_INTERVAL_TIME = 60 * 60 * 1000 +end + local function serverSave(interval) if configManager.getBoolean(configKeys.TOGGLE_SAVE_INTERVAL_CLEAN_MAP) then cleanMap() diff --git a/data/global.lua b/data/global.lua index 04a8ff78fe9..8bd85010494 100644 --- a/data/global.lua +++ b/data/global.lua @@ -109,27 +109,6 @@ if not _G.PlayerDelayPotion then _G.PlayerDelayPotion = {} end -table.contains = function(array, value) - for _, targetColumn in pairs(array) do - if targetColumn == value then - return true - end - end - return false -end - --- for use of: data\scripts\globalevents\customs\save_interval.lua -SAVE_INTERVAL_TYPE = configManager.getString(configKeys.SAVE_INTERVAL_TYPE) -SAVE_INTERVAL_CONFIG_TIME = configManager.getNumber(configKeys.SAVE_INTERVAL_TIME) -SAVE_INTERVAL_TIME = 0 -if SAVE_INTERVAL_TYPE == "second" then - SAVE_INTERVAL_TIME = 1000 -elseif SAVE_INTERVAL_TYPE == "minute" then - SAVE_INTERVAL_TIME = 60 * 1000 -elseif SAVE_INTERVAL_TYPE == "hour" then - SAVE_INTERVAL_TIME = 60 * 60 * 1000 -end - -- Increase Stamina when Attacking Trainer staminaBonus = { target = "Training Machine", @@ -138,68 +117,3 @@ staminaBonus = { eventsTrainer = {}, -- stamina in trainers eventsPz = {}, -- stamina in Pz } - -FAMILIARSNAME = { - "sorcerer familiar", - "knight familiar", - "druid familiar", - "paladin familiar", -} - -function addStamina(playerId, ...) - -- Creature:onTargetCombat - if playerId then - local player = Player(playerId) - if configManager.getBoolean(configKeys.STAMINA_TRAINER) then - if not player then - staminaBonus.eventsTrainer[playerId] = nil - else - local target = player:getTarget() - if not target or target:getName() ~= staminaBonus.target then - staminaBonus.eventsTrainer[playerId] = nil - else - player:setStamina(player:getStamina() + staminaBonus.bonus) - player:sendTextMessage(MESSAGE_STATUS, string.format("%i of stamina has been refilled.", configManager.getNumber(configKeys.STAMINA_TRAINER_GAIN))) - staminaBonus.eventsTrainer[playerId] = addEvent(addStamina, staminaBonus.period, playerId) - end - end - end - return not configManager.getBoolean(configKeys.STAMINA_TRAINER) - end - - -- Player:onChangeZone - local localPlayerId, delay = ... - - if localPlayerId and delay then - if not staminaBonus.eventsPz[localPlayerId] then - return false - end - stopEvent(staminaBonus.eventsPz[localPlayerId]) - - local player = Player(localPlayerId) - if not player then - staminaBonus.eventsPz[localPlayerId] = nil - return false - end - - local actualStamina = player:getStamina() - - if actualStamina > 2400 and actualStamina < 2520 then - delay = configManager.getNumber(configKeys.STAMINA_GREEN_DELAY) * 60 * 1000 -- Stamina Green 12 min. - elseif actualStamina == 2520 then - player:sendTextMessage( - MESSAGE_STATUS, - "You are no longer refilling stamina, \z - because your stamina is already full." - ) - staminaBonus.eventsPz[localPlayerId] = nil - return false - end - - player:setStamina(player:getStamina() + configManager.getNumber(configKeys.STAMINA_PZ_GAIN)) - player:sendTextMessage(MESSAGE_STATUS, string.format("%i of stamina has been refilled.", configManager.getNumber(configKeys.STAMINA_PZ_GAIN))) - staminaBonus.eventsPz[localPlayerId] = addEvent(addStamina, delay, nil, localPlayerId, delay) - return true - end - return false -end diff --git a/data/libs/functions/functions.lua b/data/libs/functions/functions.lua index 95e6ccb3e3a..88315a237bf 100644 --- a/data/libs/functions/functions.lua +++ b/data/libs/functions/functions.lua @@ -1167,3 +1167,70 @@ function toboolean(value) return false end end + +function addStamina(playerId, ...) + -- Creature:onTargetCombat + if playerId then + local player = Player(playerId) + if configManager.getBoolean(configKeys.STAMINA_TRAINER) then + if not player then + staminaBonus.eventsTrainer[playerId] = nil + else + local target = player:getTarget() + if not target or target:getName() ~= staminaBonus.target then + staminaBonus.eventsTrainer[playerId] = nil + else + player:setStamina(player:getStamina() + staminaBonus.bonus) + player:sendTextMessage(MESSAGE_STATUS, string.format("%i of stamina has been refilled.", configManager.getNumber(configKeys.STAMINA_TRAINER_GAIN))) + staminaBonus.eventsTrainer[playerId] = addEvent(addStamina, staminaBonus.period, playerId) + end + end + end + return not configManager.getBoolean(configKeys.STAMINA_TRAINER) + end + + -- Player:onChangeZone + local localPlayerId, delay = ... + + if localPlayerId and delay then + if not staminaBonus.eventsPz[localPlayerId] then + return false + end + stopEvent(staminaBonus.eventsPz[localPlayerId]) + + local player = Player(localPlayerId) + if not player then + staminaBonus.eventsPz[localPlayerId] = nil + return false + end + + local actualStamina = player:getStamina() + + if actualStamina > 2400 and actualStamina < 2520 then + delay = configManager.getNumber(configKeys.STAMINA_GREEN_DELAY) * 60 * 1000 -- Stamina Green 12 min. + elseif actualStamina == 2520 then + player:sendTextMessage( + MESSAGE_STATUS, + "You are no longer refilling stamina, \z + because your stamina is already full." + ) + staminaBonus.eventsPz[localPlayerId] = nil + return false + end + + player:setStamina(player:getStamina() + configManager.getNumber(configKeys.STAMINA_PZ_GAIN)) + player:sendTextMessage(MESSAGE_STATUS, string.format("%i of stamina has been refilled.", configManager.getNumber(configKeys.STAMINA_PZ_GAIN))) + staminaBonus.eventsPz[localPlayerId] = addEvent(addStamina, delay, nil, localPlayerId, delay) + return true + end + return false +end + +table.contains = function(array, value) + for _, targetColumn in pairs(array) do + if targetColumn == value then + return true + end + end + return false +end