mirror of
https://github.com/ErikasKontenis/SabrehavenServer.git
synced 2025-10-13 14:24:55 +02:00
finish market system for real
This commit is contained in:
@@ -157,3 +157,59 @@ function Game.setStorageValue(key, value)
|
||||
db.query("INSERT INTO `global_storage` (`key`, `value`) VALUES (" .. key .. ", " .. value .. ");")
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local cdShort = {"d", "h", "m", "s"}
|
||||
local cdLong = {" day", " hour", " minute", " second"}
|
||||
local function getTimeUnitGrammar(amount, unitID, isLong)
|
||||
return isLong and string.format("%s%s", cdLong[unitID], amount ~= 1 and "s" or "") or cdShort[unitID]
|
||||
end
|
||||
|
||||
function Game.getCountdownString(duration, longVersion, hideZero)
|
||||
if duration < 0 then
|
||||
return "expired"
|
||||
end
|
||||
|
||||
local days = math.floor(duration / 86400)
|
||||
local hours = math.floor((duration % 86400) / 3600)
|
||||
local minutes = math.floor((duration % 3600) / 60)
|
||||
local seconds = math.floor(duration % 60)
|
||||
|
||||
local response = {}
|
||||
if hideZero then
|
||||
if days > 0 then
|
||||
response[#response + 1] = days .. getTimeUnitGrammar(days, 1, longVersion)
|
||||
end
|
||||
|
||||
if hours > 0 then
|
||||
response[#response + 1] = hours .. getTimeUnitGrammar(hours, 2, longVersion)
|
||||
end
|
||||
|
||||
if minutes > 0 then
|
||||
response[#response + 1] = minutes .. getTimeUnitGrammar(minutes, 3, longVersion)
|
||||
end
|
||||
|
||||
if seconds > 0 then
|
||||
response[#response + 1] = seconds .. getTimeUnitGrammar(seconds, 4, longVersion)
|
||||
end
|
||||
else
|
||||
if days > 0 then
|
||||
response[#response + 1] = days .. getTimeUnitGrammar(days, 1, longVersion)
|
||||
response[#response + 1] = hours .. getTimeUnitGrammar(hours, 2, longVersion)
|
||||
response[#response + 1] = minutes .. getTimeUnitGrammar(minutes, 3, longVersion)
|
||||
response[#response + 1] = seconds .. getTimeUnitGrammar(seconds, 4, longVersion)
|
||||
elseif hours > 0 then
|
||||
response[#response + 1] = hours .. getTimeUnitGrammar(hours, 2, longVersion)
|
||||
response[#response + 1] = minutes .. getTimeUnitGrammar(minutes, 3, longVersion)
|
||||
response[#response + 1] = seconds .. getTimeUnitGrammar(seconds, 4, longVersion)
|
||||
elseif minutes > 0 then
|
||||
response[#response + 1] = minutes .. getTimeUnitGrammar(minutes, 3, longVersion)
|
||||
response[#response + 1] = seconds .. getTimeUnitGrammar(seconds, 4, longVersion)
|
||||
elseif seconds >= 0 then
|
||||
response[#response + 1] = seconds .. getTimeUnitGrammar(seconds, 4, longVersion)
|
||||
end
|
||||
end
|
||||
|
||||
return table.concat(response, " ")
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user