From 898f4bcf29874a0c1a7590d7ccc19effd9383985 Mon Sep 17 00:00:00 2001 From: isRyven Date: Sun, 29 Mar 2020 13:56:07 +0300 Subject: [PATCH] fix banners should not be printed during intermission * banners are no longer printed in intermission * increased max banner count to 10 --- README.md | 2 +- banners/banners.lua | 33 +++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 36baf74..6171f8e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Reserves next cvars to configure banners: * `left` popup messages (`cpm`) * `center` center print (`cp`) * `chat` chat print (`chat`) -* `g_bannerN` (where N is a number in range of `1` to `5`) sets banner messages +* `g_bannerN` (where N is a number in range of `1` to `10`) sets banner messages All cvars should be filled before lua module gets initialized. diff --git a/banners/banners.lua b/banners/banners.lua index b0eda1e..3eeeae1 100644 --- a/banners/banners.lua +++ b/banners/banners.lua @@ -1,6 +1,6 @@ --[[ ET: Legacy - Copyright (C) 2012-2019 ET:Legacy team + Copyright (C) 2012-2020 ET:Legacy team This file is part of ET: Legacy - http://www.etlegacy.com ET: Legacy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,7 +15,7 @@ ]]-- local modname = "banners" -local version = "0.1" +local version = "0.2" -- Map Data Structure @@ -61,6 +61,7 @@ function BannerSystem(props) obj.interval = props.interval obj.command = props.command obj.banners = {} + obj.isPaused = false for _, val in ipairs(props.banners) do if string.len(val) > 0 then table.insert(obj.banners, val) @@ -71,12 +72,19 @@ function BannerSystem(props) end function BannerSystemPrototype:frame(time) - if self.nextUpdateTime > time then + if self.isPaused or self.nextUpdateTime > time then return end if #self.banners == 0 then return end + -- don't run banners in intermission + local g_gamestate = tonumber(et.trap_Cvar_Get("gamestate")) + if g_gamestate == et.GS_INTERMISSION then + self.isPaused = true + return + end + -- perform work self:update(time) self:render(time) end @@ -107,6 +115,7 @@ local DEFAULT_TIME = 5000 local DEFAULT_TIME_THRESHOLD = 2000 local DEFAULT_LOCATION = "top" local bannerSystem = nil -- BannerSystem instance global (well, local) +local MAX_BANNERS = 10 function et_InitGame(levelTime, randomSeed, restart) et.RegisterModname(modname .. " " .. version) @@ -137,16 +146,20 @@ function et_InitGame(levelTime, randomSeed, restart) g_bannerLocation = DEFAULT_LOCATION end + -- find banners by checking the g_bannerN cvars + local banners = {} + for i = 1, MAX_BANNERS do + local banner = et.trap_Cvar_Get("g_banner" .. i) + if banner == nil or banner == "" then + break + end + table.insert(banners, banner) + end + bannerSystem = BannerSystem { interval = g_bannerTime, command = locationMapping:get(g_bannerLocation), - banners = { - et.trap_Cvar_Get("g_banner1"), - et.trap_Cvar_Get("g_banner2"), - et.trap_Cvar_Get("g_banner3"), - et.trap_Cvar_Get("g_banner4"), - et.trap_Cvar_Get("g_banner5") - } + banners = banners } if bannerSystem:count() > 0 then