-- j2b2's Hurry Up! local countdownstart = 0 local CV_Fractions = { ["3/4"]=0, ["1"]=1, ["1/2"]=2, ["1/3"]=3, ["1/4"]=4, ["2/3"]=5 } local cvCountdown = CV_FindVar("countdowntime") local cvHurryPlayers = CV_RegisterVar({name="hurry_players",defaultvalue="2/3",flags=CV_NETVAR | CV_SHOWMODIF,PossibleValue=CV_Fractions}) local cvHurryTimeLimit = CV_RegisterVar({name="hurry_timelimit",defaultvalue=0,flags=CV_NETVAR | CV_SHOWMODIF,PossibleValue=CV_Unsigned}) local comStartCountdown = COM_AddCommand("hurry_startcountdown",function(player,time) time = tonumber(time) if time == nil then countdownstart = leveltime else time = max(min(time,9999999),0) countdownstart = leveltime+time*TICRATE-cvCountdown.value*TICRATE end S_StartSound(nil,sfx_dwnind) end,COM_ADMIN) local function IsValid(a) if a ~= nil then return a.valid end return false end local function ShouldHurry() return multiplayer and gametyperules & GTR_ALLOWEXIT and gametyperules & GTR_RACE == 0 and titlemapinaction == false end addHook("NetVars",function(network) countdownstart = network(countdownstart) end) addHook("MapChange",function() countdownstart = 0 end) addHook("ThinkFrame",function() if ShouldHurry() then if countdownstart == 0 then if cvHurryTimeLimit.value ~= 0 and leveltime+cvCountdown.value*TICRATE >= cvHurryTimeLimit.value*TICRATE*60 then countdownstart = leveltime S_StartSound(nil,sfx_dwnind) else local totalCount = 0 local finishedCount = 0 for player in players.iterate() do if IsValid(player) then if player.pflags & PF_FINISHED then finishedCount = finishedCount+1 end if player.lives > 0 then totalCount = totalCount+1 end end end local requiredForFinish if cvHurryPlayers.value == 0 then requiredForFinish = max(FixedCeil(FixedDiv(totalCount*3*FRACUNIT,4*FRACUNIT))/FRACUNIT,1) elseif cvHurryPlayers.value == 1 then requiredForFinish = 1 elseif cvHurryPlayers.value == 5 then requiredForFinish = max(FixedCeil(FixedDiv(totalCount*2*FRACUNIT,3*FRACUNIT))/FRACUNIT,1) else requiredForFinish = max(FixedCeil(FixedDiv(totalCount*FRACUNIT,cvHurryPlayers.value*FRACUNIT))/FRACUNIT,1) end if finishedCount >= requiredForFinish and finishedCount ~= totalCount then countdownstart = leveltime S_StartSound(nil,sfx_dwnind) end end else if countdownstart+cvCountdown.value*TICRATE <= leveltime then print("Times up! Exiting level...") G_ExitLevel() end end end end) local HUD_TEXT_Y = 168 local HUD_NUMBER_Y = HUD_TEXT_Y+10 local HUD_FLASH_TIME = TICRATE/2 hud.add(function(v,stplyr) local countdownEnd = countdownstart+cvCountdown.value*TICRATE if ShouldHurry() then if countdownstart ~= 0 and countdownEnd > leveltime and stplyr.exiting == 0 then local time = leveltime/HUD_FLASH_TIME local videoFlags = V_SNAPTOBOTTOM | V_PERPLAYER if time%2 then videoFlags = videoFlags | V_YELLOWMAP end if stplyr.pflags & PF_FINISHED then v.drawString(160, HUD_TEXT_Y, "LEVEL ENDS IN", V_SNAPTOBOTTOM | V_PERPLAYER, "center") else v.drawString(160, HUD_TEXT_Y, "HURRY UP!", videoFlags, "center") end v.drawString(160, HUD_NUMBER_Y, (countdownEnd-leveltime)/TICRATE, V_SNAPTOBOTTOM | V_PERPLAYER, "center") end end end,"game") -- j2b2's Hurry Up!