Fixed banners calculation (fixes #98)

* added checks for available banners
This commit is contained in:
Timo Smit 2019-02-04 12:20:06 +01:00
parent 311f4877c7
commit f835d8c6ec
1 changed files with 13 additions and 7 deletions

View File

@ -39,18 +39,26 @@ function banners.print(clientId, banner)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..target.." \"^dbanner: ^9"..banner["text"].."\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..target.." \"^dbanner: ^9"..banner["text"].."\";")
end end
function banners.autoprint() function banners.nextBanner(random)
if bits.hasbit(settings.get("g_bannerRandomize"), banners.RANDOM_ALL) then if #infoBanners == 0 then
nextBannerId = 0
elseif random then
nextBannerId = math.random(#infoBanners) nextBannerId = math.random(#infoBanners)
elseif nextBannerId ~= #infoBanners then elseif nextBannerId ~= #infoBanners then
nextBannerId = nextBannerId + 1 nextBannerId = nextBannerId + 1
else else
nextBannerId = 0 nextBannerId = 1
end
end end
function banners.autoprint()
if nextBannerId ~= 0 and infoBanners[nextBannerId] then
banners.print(nil, infoBanners[nextBannerId]) banners.print(nil, infoBanners[nextBannerId])
end end
banners.nextBanner(bits.hasbit(settings.get("g_bannerRandomize"), banners.RANDOM_ALL))
end
function banners.load() function banners.load()
local fileName = settings.get("g_fileBanners") local fileName = settings.get("g_fileBanners")
@ -105,9 +113,7 @@ events.handle("onPlayerReady", banners.onPlayerReady)
function banners.onGameInit(levelTime, randomSeed, restartMap) function banners.onGameInit(levelTime, randomSeed, restartMap)
banners.load() banners.load()
if bits.hasbit(settings.get("g_bannerRandomize"), banners.RANDOM_START) then banners.nextBanner(bits.hasbit(settings.get("g_bannerRandomize"), banners.RANDOM_START))
nextBannerId = math.random(#infoBanners)
end
bannerTimer = timers.add(banners.autoprint, settings.get("g_bannerInterval") * 1000, 0) bannerTimer = timers.add(banners.autoprint, settings.get("g_bannerInterval") * 1000, 0)
end end