mirror of
https://github.com/ErikasKontenis/SabrehavenServer.git
synced 2025-11-28 15:46:49 +01:00
finish fully working stamina system for 56h with 2 hours of happy time for premium players
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<creaturescripts>
|
||||
<event type="login" name="PlayerLogin" script="login.lua"/>
|
||||
<event type="logout" name="PlayerLogout" script="logout.lua" />
|
||||
<event type="login" name="FirstItems" script="firstitems.lua"/>
|
||||
<event type="login" name="RegenerateStamina" script="regeneratestamina.lua" />
|
||||
<event type="death" name="PlayerDeath" script="playerdeath.lua"/>
|
||||
</creaturescripts>
|
||||
|
||||
@@ -11,7 +11,10 @@ function onLogin(player)
|
||||
loginStr = string.format("Your last visit on " .. configManager.getString(configKeys.SERVER_NAME) .. ": %s.", os.date("%a %b %d %X %Y", player:getLastLoginSaved()))
|
||||
end
|
||||
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
|
||||
|
||||
|
||||
-- Stamina
|
||||
nextUseStaminaTime[player.uid] = 0
|
||||
|
||||
-- Promotion
|
||||
if player:isPremium() then
|
||||
if player:getVocation():getId() ~= 0 and player:getVocation():getId() < 5 and player:getStorageValue(30018) == 1 then
|
||||
|
||||
7
data/creaturescripts/scripts/logout.lua
Normal file
7
data/creaturescripts/scripts/logout.lua
Normal file
@@ -0,0 +1,7 @@
|
||||
function onLogout(player)
|
||||
local playerId = player:getId()
|
||||
if nextUseStaminaTime[playerId] then
|
||||
nextUseStaminaTime[playerId] = nil
|
||||
end
|
||||
return true
|
||||
end
|
||||
@@ -3,7 +3,10 @@ local maxDeathRecords = 50
|
||||
|
||||
function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
|
||||
local playerId = player:getId()
|
||||
|
||||
if nextUseStaminaTime[playerId] then
|
||||
nextUseStaminaTime[playerId] = nil
|
||||
end
|
||||
|
||||
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are dead.")
|
||||
|
||||
-- restart blessings values
|
||||
|
||||
27
data/creaturescripts/scripts/regeneratestamina.lua
Normal file
27
data/creaturescripts/scripts/regeneratestamina.lua
Normal file
@@ -0,0 +1,27 @@
|
||||
function onLogin(player)
|
||||
if not configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
|
||||
return true
|
||||
end
|
||||
|
||||
local lastLogout = player:getLastLogout()
|
||||
local offlineTime = lastLogout ~= 0 and math.min(os.time() - lastLogout, 86400 * 21) or 0
|
||||
offlineTime = offlineTime - 600
|
||||
|
||||
if offlineTime < 180 then
|
||||
return true
|
||||
end
|
||||
|
||||
local staminaMinutes = player:getStamina()
|
||||
local maxNormalStaminaRegen = 3240 - math.min(3240, staminaMinutes)
|
||||
|
||||
local regainStaminaMinutes = offlineTime / 180
|
||||
if regainStaminaMinutes > maxNormalStaminaRegen then
|
||||
local happyHourStaminaRegen = (offlineTime - (maxNormalStaminaRegen * 180)) / 600
|
||||
staminaMinutes = math.min(3360, math.max(3240, staminaMinutes) + happyHourStaminaRegen)
|
||||
else
|
||||
staminaMinutes = staminaMinutes + regainStaminaMinutes
|
||||
end
|
||||
|
||||
player:setStamina(staminaMinutes)
|
||||
return true
|
||||
end
|
||||
Reference in New Issue
Block a user