--------------------- -- CAMPAIGN SWITCHER --------------------- -- This script will monitor the number of players on your server and will switch campaign/campaign rotation -- depending on traffic levels. The player number test is done on et_ShutdownGame, i.e. map changes and -- restarts. Only "nextcampaign" is changed with player number, the current campaign is always played out. -- There is also an option as to whether or not spectators are counted towards player number. -- NOTE: The use of b_campaignfile is STRONGLY recommended for use with this script. -- GhosT:McSteve -- www.ghostworks.co.uk -- #ghostworks, #pbbans @quakenet -- Version 1, 16/2/07 ----------------------------------------------------- -- Enter your campaigns here. -- (if you only have 2 traffic levels, use camps_1 and camps_2 and leave camps_3 empty) camps_1 = {"cmpgn_quietcamp1" ; "cmpgn_quietcamp2" ; "cmpgn_quietcamp3"} camps_2 = {"cmpgn_busycamp1" ; "cmpgn_busycamp2" ; "cmpgn_busycamp3"} camps_3 = {} -- Enter the playercount limits for the switch here. -- (if you only have 2 traffic levels, set limit_2 to a number higher than sv_maxclients) limit_1 = 10 limit_2 = 100 -- Shall spectators be counted in the playercount? (1/0 = yes/no) includespecs = 1 ----------------------------------------------------- -- TABLE SHOWING LOGIC OF CAMPAIGN SWITCHING ----------------------------------------------------- -- playercount (x) campaign rotation ----------------------------------------------------- -- x < limit_1 camps_1 -- limit_1 <= x < limit_2 camps_2 -- limit_2 <= x camps_3 ----------------------------------------------------- ----------------------------------------------------------------------------------- ---------------------- DO NOT MODIFY BELOW THIS LINE ---------------------------- ----------------------------------------------------------------------------------- -- find the number of campaigns in each rotation n_camps_1 = table.getn(camps_1) n_camps_2 = table.getn(camps_2) n_camps_3 = table.getn(camps_3) -- on game initialise function et_InitGame( levelTime, randomSeed, restart ) --called on game initialise maxclients = tonumber( et.trap_Cvar_Get( "sv_maxClients" ) ) --gets the maxclients end function et_ShutdownGame( restart ) local playercount = 0 local nextcampindex = 1 -- COUNT THE NUMBER OF PLAYERS ON THE SERVER if includespecs == 1 then for i = 0, (maxclients - 1) do if et.gentity_get(i, "sess.sessionTeam") ~= 0 then --et.trap_SendConsoleCommand(et.EXEC_APPEND, "qsay \"^3sessionteam " .. i .. " " .. et.gentity_get(i, "sess.sessionTeam") .. "\"\n") playercount = playercount + 1 end end elseif includespecs == 0 then for i = 0, (maxclients - 1) do if (tonumber(et.gentity_get(i, "sess.sessionTeam")) == 1) or (tonumber(et.gentity_get(i, "sess.sessionTeam")) == 2) then playercount = playercount + 1 end end end --et.trap_SendConsoleCommand(et.EXEC_APPEND, "qsay \"^3playercount " .. playercount .. "\"\n") -- GET THE NAME OF THE CURRENT CAMP local currentcamp = et.trap_Cvar_Get( "g_currentcampaign" ) local nextcamp = et.trap_Cvar_Get( "nextcampaign" ) --et.trap_SendConsoleCommand(et.EXEC_APPEND, "qsay \"^3pre-switch, currentcamp: " .. currentcamp .. " nextcamp: " .. nextcamp .. "\"\n") -- SET THE CAMPAIGN ACCORDING TO PLAYERCOUNT -- enter camps_1 rotation if playercount < limit_1 if (playercount < limit_1) then -- find out the next camp in the rotation -- if the currentcamp is in the camps_1 rotation, then the search will always be nil, hence nextcampindex is initialised to 1 above for j = 1, n_camps_1 do -- search the array of camps until we have a match, at which point j will be index of current camp if string.find(camps_1[j], currentcamp) ~= nil then if j == n_camps_1 then nextcampindex = 1 else nextcampindex = j + 1 end end end -- set the next camp et.trap_Cvar_Set( "nextcampaign", "campaign " .. camps_1[nextcampindex] ) --et.trap_SendConsoleCommand(et.EXEC_APPEND, "qsay \"^3runtime\"\n") elseif (playercount >= limit_1) and (playercount < limit_2) then for j = 1, n_camps_2 do if string.find(camps_2[j], currentcamp) ~= nil then if j == n_camps_2 then nextcampindex = 1 else nextcampindex = j + 1 end end end et.trap_Cvar_Set( "nextcampaign", "campaign " .. camps_2[nextcampindex] ) elseif (playercount >= limit_2) then for j = 1, n_camps_3 do if string.find(camps_3[j], currentcamp) ~= nil then if j == n_camps_3 then nextcampindex = 1 else nextcampindex = j + 1 end end end et.trap_Cvar_Set( "nextcampaign", "campaign " .. camps_3[nextcampindex] ) end --local nextcamp = et.trap_Cvar_Get( "nextcampaign" ) --et.trap_SendConsoleCommand(et.EXEC_APPEND, "qsay \"^3post-switch, currentcamp: " .. currentcamp .. " nextcamp: " .. nextcamp .. "\"\n") end