Skip to content

Commit

Permalink
Merge pull request #36 from fluffy-servers/propfuncs
Browse files Browse the repository at this point in the history
Property functions
  • Loading branch information
rafraser committed Feb 11, 2021
2 parents c89c855 + c2ec23d commit 48b361b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
19 changes: 10 additions & 9 deletions gamemodes/fluffy_mg_base/gamemode/cl_round_state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,23 @@ local TIME_ICON = Material("fluffy/time.png", "noclamp smooth")

-- COMPONENTS
function GM:GetRoundTimeRemaining()
local RoundTime = GetGlobalFloat("RoundStart")
if not RoundTime then return end
local RoundMax = GAMEMODE.RoundTime or 60
local startTime = GetGlobalFloat("RoundStart")
if not startTime then return end

local roundMax = isfunction(GAMEMODE.RoundTime) and GAMEMODE.RoundTime() or GAMEMODE.RoundTime or 60
if GAMEMODE:GetRoundState() == "PreRound" then
RoundMax = GAMEMODE.RoundCooldown or 5
roundMax = GAMEMODE.RoundCooldown or 5
end

return math.max(RoundMax - (CurTime() - RoundTime), 0), RoundMax
return math.max(roundMax - (CurTime() - startTime), 0), roundMax
end

function GM:GetGameTimeRemaining()
local GameTime = GetGlobalFloat("GameStartTime")
if not GameTime then return end
local startTime = GetGlobalFloat("GameStartTime")
if not startTime then return end

return (GameTime + GAMEMODE.GameTime) - CurTime()
local gameTime = isfunction(GAMEMODE.GameTime) and GAMEMODE.GameTime() or GAMEMODE.GameTime
return (startTime + gameTime) - CurTime()
end

function GM:GetGameTimeRemainingFormatted()
Expand All @@ -63,7 +64,7 @@ end

function GM:GetRoundInfo()
local round = GAMEMODE:GetRoundNumber()
local rmax = GAMEMODE.RoundNumber or 5
local rmax = isfunction(GAMEMODE.RoundNumber) and GAMEMODE.RoundNumber() or GAMEMODE.RoundNumber or 5
local round_message = "Round " .. round .. " / " .. rmax

if round == rmax then
Expand Down
8 changes: 5 additions & 3 deletions gamemodes/fluffy_mg_base/gamemode/sv_round.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ function GM:PreStartRound()
-- Different gamemode round types have different logic
if GAMEMODE.RoundType == "default" then
-- End the game once all the rounds have been played
if round >= GAMEMODE.RoundNumber then
local rmax = isfunction(GAMEMODE.RoundNumber) and GAMEMODE.RoundNumber() or GAMEMODE.RoundNumber
if round >= rmax then
GAMEMODE:EndGame()

return
Expand Down Expand Up @@ -170,8 +171,9 @@ function GM:StartRound()

-- End the round after a certain time
-- Does not apply to endless round types
if GAMEMODE.RoundType ~= "timed_endless" and GAMEMODE.RoundTime > 0 then
timer.Create("GamemodeTimer", GAMEMODE.RoundTime, 0, function()
local roundTime = isfunction(GAMEMODE.RoundTime) and GAMEMODE.RoundTime() or GAMEMODE.RoundTime
if GAMEMODE.RoundType ~= "timed_endless" and roundTime > 0 then
timer.Create("GamemodeTimer", roundTime, 0, function()
GAMEMODE:EndRound("TimeEnd")
end)
end
Expand Down

0 comments on commit 48b361b

Please sign in to comment.