ETMods.net

N!tmod, a Wolfenstein: Enemy Territory Modification!

You are not logged in.

Announcement

You can donate to help us keeping services online.

#1 10-Mar-15 18:02:11

N!trox*
Administrator
Registered: 30-Mar-10
Posts: 1,090

[UPDATE]Random Next Map LUA v0.4

Hi,

Exagone313 and myself have been working on a Random Nextmap LUA.

He came here with the original idea and a first version of his LUA, and we have worked together to improve it and adapt it for public use.

You can download it here

Changelog:

-- v0.4 -- March 10th 2015
-- Added: Automatic nextmap announce in the server chat
-- Added: Possibility to disable banners (see 'useBanners')

-- v0.3 -- March 3rd 2015:
-- Added: messages templates
-- Added: Parse maplist from an external map list file, containing one map name per line
-- Added: Some code comments
-- Added: Register mod and mod version

-- v0.2 -- March 2nd 2015
-- Fixed: Don't pick a different map during warmup and after a map_restart
-- Added: Next map can now automatically be displayed to players through banners

-- v0.1 -- February 25th 2015
-- Fixed: Don't pick the current map or the last played map 

---- Initial release (v0.003):
-- Added support of randomseed for map randomization
-- Added a command to show the next map for both client and server
-- Get array size automatically with table.getn(maps)

To use it, you have to create a map list file that contains all the names of the maps you want to run on your server.
Then, modify the mapListFile variable inside the module configuration block:
Here is an example of maplist file:

battery
radar
oasis
goldrush
railgun
fueldump

Make sure that all the map names are correct, and that the maps exist on your server.

To configure this LUA, you only have to edit this block:

---------------------------------
---    MODULE CONFIGURATION   ---
---------------------------------

mapListFile = "/home/server/nitmod/maplist.txt" 	-- Absolute path to the map list file
shownextcmd = "?next" 					-- Command that will be used to print the next map
chatInterval = 5 					-- Delay, in minutes, between every automatic nextmap announce in the server chat
useBanners = 1 						-- If set to 1, enable nextmap announce in server banners (i.e: 'bannerCvar' will be set to 'bannerMsg')
bannerCvar = "g_msg1" 					-- Define which banner will hold the "next map is ..." message
bannerMsg = "^9Next map is ^2%s^9."		 	-- Banner message template (%s will be replaced by the name of the next map)
chatMsg = 	"^9Next map is ^2%s^9." 		-- Chat message template (%s will be replaced by the name of the next map)
CHATCMD = "chat" 					-- Chat command (use "b 8" to run this script on ETPro)

The rest doesn't need to be modified, it is the "core" code of this LUA, and modifying it may cause the LUA to stop working.

Modify it only if you know what you're doing, or request changes in this topic if you want us to update the official version.

We hope you enjoy it smile


iluvnitmod.png

Offline

#2 10-Mar-15 22:47:35

Exagone313
BETA Tester
Registered: 23-Feb-15
Posts: 45

Re: [UPDATE]Random Next Map LUA v0.4

Nice presentation smile

Offline

#3 11-Mar-15 14:49:36

Gauki
BETA Tester
From: Germany
Registered: 30-Aug-12
Posts: 114
Website

Re: [UPDATE]Random Next Map LUA v0.4

also possible to use it if mapvotecycle is also active? Announce makes no sence here O.o


DooC_sigbanner.gif

Offline

#4 11-Mar-15 16:58:35

maras
Member
Registered: 09-May-14
Posts: 23

Re: [UPDATE]Random Next Map LUA v0.4

hello, I added this script on my server. it's nice, but when I play, on a banner is "Nextmap is supplypro", but in objectivecycle.cfg is another map after that on which just play. How fix this? I generated maplist.txt file, and in it is the correct sequence.

Offline

#5 11-Mar-15 17:17:33

N!trox*
Administrator
Registered: 30-Mar-10
Posts: 1,090

Re: [UPDATE]Random Next Map LUA v0.4

Gauki wrote:

also possible to use it if mapvotecycle is also active? Announce makes no sence here O.o

You can use it with map voting gametype too, it will set nextmap in case no votes are made during intermissions.

Announces can be disabled this way:

chatInterval = 0
useBanners = 0 	

iluvnitmod.png

Offline

#6 11-Mar-15 17:22:56

N!trox*
Administrator
Registered: 30-Mar-10
Posts: 1,090

Re: [UPDATE]Random Next Map LUA v0.4

maras wrote:

hello, I added this script on my server. it's nice, but when I play, on a banner is "Nextmap is supplypro", but in objectivecycle.cfg is another map after that on which just play. How fix this? I generated maplist.txt file, and in it is the correct sequence.

I'm not sure I understood correctly, do you think the LUA will modify the objectivecycle.cfg ? If yes, it's not how it works.
objectivecycle.cfg is not used when running this LUA (except maybe when the server starts and needs to load its first map).


iluvnitmod.png

Offline

#7 22-Mar-15 17:58:17

jay1110
BETA Tester
Registered: 01-Sep-12
Posts: 208
Website

Re: [UPDATE]Random Next Map LUA v0.4

can you add current map too?

example:
chatMsg =     "^dRandom-Map is running. Current map is ^2Oasis. ^dNext map is ^2goldrush."

Last edited by jay1110 (22-Mar-15 18:05:23)

Offline

#8 30-Mar-15 21:29:06

purple
Member
Registered: 30-Mar-15
Posts: 1

Re: [UPDATE]Random Next Map LUA v0.4

This should work for current map..

---------------------------------
----- Random Next Map LUA -------
---------------------------------
-- Authors: Exagone313 and N!trox*
---- Exagone313:
-- Website: [url]http://elou.world[/url]
-- Server: et.elou.world:27960
---- N!trox*:
-- Website: [url]http://etmods.net[/url]
-- Server: etmods.net:27960
---------------------------------
-- Changelog:
-- v0.5 March 30th 2015
-- Added: Current map into chat
-- Purple.

-- v0.4 -- March 10th 2015
-- Added: Automatic nextmap announce in the server chat
-- Added: Possibility to disable banners (see 'useBanners')

-- v0.3 -- March 3rd 2015:
-- Added: messages templates
-- Added: Parse maplist from an external map list file, containing one map name per line
-- Added: Some code comments
-- Added: Register mod and mod version

-- v0.2 -- March 2nd 2015
-- Fixed: Don't pick a different map during warmup and after a map_restart
-- Added: Next map can now automatically be displayed to players through banners

-- v0.1 -- February 25th 2015
-- Fixed: Don't pick the current map or the last played map

---- Initial release (v0.003):
-- Added support of randomseed for map randomization
-- Added a command to show the next map for both client and server
-- Get array size automatically with table.getn(maps)

---------------------------------
---    MODULE CONFIGURATION   ---
---------------------------------

mapListFile = "/home/server/nitmod/maplist.txt" -- Absolute path to the map list file
shownextcmd = "?next" 					-- Command that will be used to print the next map
chatInterval = 5 						-- Delay, in minutes, between every automatic nextmap announce in the server chat
useBanners = 1 							-- If set to 1, enable nextmap announce in server banners (i.e: 'bannerCvar' will be set to 'bannerMsg')
bannerCvar = "g_msg1" 					-- Define which banner will hold the "next map is ..." message
bannerMsg = "^9Next map is ^2%s^9." 	-- Banner message template (%s will be replaced by the name of the next map)
chatMsg = 	"^9Next map is ^2%s^9." 	-- Chat message template (%s will be replaced by the name of the next map)
CHATCMD = "chat" 						-- Chat command (use "b 8" to run this script on ETPro)

---------------------------------
--  YOU DON'T NEED TO CHANGE  ---
--  ANYTHING BELOW THIS LINE  ---
---------------------------------

MODNAME = "Random Map"
MODVERSION = "0.4"
maps = {} 								-- This array will contain the map list
nextmap = "none" 						-- This variable will contain the randomly selected next map
curmap = et.trap_Cvar_Get("mapname") 	-- Name of the current map
lastmap = et.trap_Cvar_Get("lastmap") 	-- Name of the last played map
msgSent = 0
msgTime = chatInterval * 60000 - 1
-- Parse the map list file into the "maps" array
function ParseMapFile()
	local file = io.open(mapListFile, "r")
	for line in file:lines() do
		table.insert (maps, line);
	end
end

function msgSend()
	et.trap_SendServerCommand(-1, "" .. CHATCMD .. " \"" .. string.format(chatMsg, nextmap).. "\" Current map is "..curmap..".")
end

function et_InitGame(levelTime,randomSeed,restart)
	local regModStr = string.format("%s v%s", MODNAME, MODVERSION)
	et.RegisterModname(regModStr) -- Register the LUA module
	ParseMapFile() -- Parse the map list now
	et.trap_Cvar_Set(bannerCvar, "") -- Clear banner
	et.trap_Cvar_Set("lastmap", curmap) -- Set "lastmap" to avoid map loops
	luanm = et.trap_Cvar_Get("lua_nextmap") -- Get the previously selected random map
	if( curmap == luanm or luanm == "" or (curmap ~= lastmap and curmap ~= luanm) ) then -- If we've moved to the selected nextmap, to another map, or if it has not yet been set, pick another random map
		while (1) do
			nextmap = maps[math.random(table.getn(maps))]
			if ((nextmap ~= curmap) and (nextmap ~= lastmap)) then
				break
			end
		end
	else -- If we're didn't switch to the random map yet, or to another map, don't change it.
		nextmap = luanm
	end
	et.trap_Cvar_Set("lua_nextmap", nextmap) -- Store the random map in a cvar to track it later
	et.trap_Cvar_Set("nextmap", "map " .. nextmap) -- Set the nextmap vstr
	if (useBanners == 1) then
		et.trap_Cvar_Set(bannerCvar, string.format(bannerMsg, nextmap)) -- Set the banner
	end
end

function et_RunFrame( levelTime )
	if( (chatInterval > 0) and ((msgSent + msgTime) < levelTime)) then
		msgSent = levelTime
		msgSend()
	end
end

function et_ClientCommand(clientNum, command)
    local arg0 = string.lower(et.trap_Argv(0))
    local arg1 = string.lower(et.trap_Argv(1))
    if ((arg0 == shownextcmd) or ((arg0 == "say") and (arg1 == shownextcmd)))then
        et.trap_SendServerCommand(clientNum, "" .. CHATCMD .. " \"" .. string.format(chatMsg, nextmap).. "\" Current map is "..curmap..".")
        return 1
    end
end

function et_ConsoleCommand(command)
    if (command == shownextcmd) then
        et.G_Print("Next map is " .. nextmap .. ". Current map is "..curmap..".\n")
        return 1
    end
end

Last edited by purple (30-Mar-15 21:30:15)

Offline

#9 31-Mar-15 17:22:19

jay1110
BETA Tester
Registered: 01-Sep-12
Posts: 208
Website

Re: [UPDATE]Random Next Map LUA v0.4

forgot to post it sry, it has been allready done. But thanks for your work.

---------------------------------
----- Random Next Map LUA -------
---------------------------------
-- Authors: Exagone313 and N!trox*
---- Exagone313:
-- Website: http://elou.world
-- Server: et.elou.world:27960
---- N!trox*:
-- Website: http://etmods.net
-- Server: etmods.net:27960
---------------------------------
-- Changelog: 

-- v0.5 -- March 23th 2015
-- Added: current map

-- v0.4 -- March 10th 2015
-- Added: Automatic nextmap announce in the server chat
-- Added: Possibility to disable banners (see 'useBanners')

-- v0.3 -- March 3rd 2015:
-- Added: messages templates
-- Added: Parse maplist from an external map list file, containing one map name per line
-- Added: Some code comments
-- Added: Register mod and mod version

-- v0.2 -- March 2nd 2015
-- Fixed: Don't pick a different map during warmup and after a map_restart
-- Added: Next map can now automatically be displayed to players through banners

-- v0.1 -- February 25th 2015
-- Fixed: Don't pick the current map or the last played map 

---- Initial release (v0.003):
-- Added support of randomseed for map randomization
-- Added a command to show the next map for both client and server
-- Get array size automatically with table.getn(maps)

---------------------------------
---    MODULE CONFIGURATION   ---
---------------------------------

mapListFile = "/home/servera/nitmod/maplist.txt" -- Absolute path to the map list file
shownextcmd = "?next" 					-- Command that will be used to print the next map
chatInterval = 2 						-- Delay, in minutes, between every automatic nextmap announce in the server chat
useBanners = 1 							-- If set to 1, enable nextmap announce in server banners (i.e: 'bannerCvar' will be set to 'bannerMsg')
bannerCvar = "g_msg1" 					-- Define which banner will hold the "next map is ..." message
bannerMsg = "^dRandom-Map is running. Current map is ^2%s. ^dNext map is ^2%s." 	-- Banner message template (%s will be replaced by the name of the next map)
chatMsg = 	"^dRandom-Map is running. Current map is ^2%s. ^dNext map is ^2%s." -- Chat message template (%s will be replaced by the name of the next map)
CHATCMD = "chat" 						-- Chat command (use "b 8" to run this script on ETPro)

---------------------------------
--  YOU DON'T NEED TO CHANGE  ---
--  ANYTHING BELOW THIS LINE  ---
---------------------------------

MODNAME = "Random Map"
MODVERSION = "0.5"
maps = {} 								-- This array will contain the map list
nextmap = "none" 						-- This variable will contain the randomly selected next map
curmap = et.trap_Cvar_Get("mapname") 	-- Name of the current map
lastmap = et.trap_Cvar_Get("lastmap") 	-- Name of the last played map
msgSent = 0
msgTime = chatInterval * 60000 - 1
-- Parse the map list file into the "maps" array
function ParseMapFile()
	local file = io.open(mapListFile, "r")
	for line in file:lines() do
		table.insert (maps, line);
	end
end

function msgSend(clientNum)
	et.trap_SendServerCommand(clientNum, "" .. CHATCMD .. " \"" .. string.format(chatMsg, curmap, nextmap).. "\"")
end

function et_InitGame(levelTime,randomSeed,restart)
	local regModStr = string.format("%s v%s", MODNAME, MODVERSION)
	et.RegisterModname(regModStr) -- Register the LUA module
	ParseMapFile() -- Parse the map list now
	et.trap_Cvar_Set(bannerCvar, "") -- Clear banner
	et.trap_Cvar_Set("lastmap", curmap) -- Set "lastmap" to avoid map loops
	luanm = et.trap_Cvar_Get("lua_nextmap") -- Get the previously selected random map
	if( curmap == luanm or luanm == "" or (curmap ~= lastmap and curmap ~= luanm) ) then -- If we've moved to the selected nextmap, to another map, or if it has not yet been set, pick another random map
		while (1) do
			nextmap = maps[math.random(table.getn(maps))]
			if ((nextmap ~= curmap) and (nextmap ~= lastmap)) then
				break
			end
		end
	else -- If we're didn't switch to the random map yet, or to another map, don't change it.
		nextmap = luanm
	end
	et.trap_Cvar_Set("lua_nextmap", nextmap) -- Store the random map in a cvar to track it later
	et.trap_Cvar_Set("nextmap", "map " .. nextmap) -- Set the nextmap vstr
	if (useBanners == 1) then
		et.trap_Cvar_Set(bannerCvar, string.format(bannerMsg, nextmap)) -- Set the banner
	end
end

function et_RunFrame( levelTime )
	if( (chatInterval > 0) and ((msgSent + msgTime) < levelTime)) then
		msgSent = levelTime
		msgSend(-1)
	end
end

function et_ClientCommand(clientNum, command)
    local arg0 = string.lower(et.trap_Argv(0))
    local arg1 = string.lower(et.trap_Argv(1))
    if ((arg0 == shownextcmd) or ((arg0 == "say") and (arg1 == shownextcmd)))then
		msgSend(clientNum)
        return 1
    end
end

function et_ConsoleCommand(command)
    if (command == shownextcmd) then
        et.G_Print("" .. string.format(chatMsg, curmap, nextmap) .. "\n")
        return 1
    end
end

Offline

#10 04-Aug-15 09:47:56

Dennis92NL
Member
Registered: 04-Aug-15
Posts: 18

Re: [UPDATE]Random Next Map LUA v0.4

Hi N!trox*,

So what gametype i need to pick if this don't work with objectivecycle.cfg. I have a small rotation from maps in gametype 2 and sometimes it will pick the same map 4 times after each other. Anyone know what i,m doing wrong?

Regards,
Dennis

Last edited by Dennis92NL (04-Aug-15 09:48:10)

Offline

#11 05-Oct-15 21:21:24

Exagone313
BETA Tester
Registered: 23-Feb-15
Posts: 45

Re: [UPDATE]Random Next Map LUA v0.4

I have an idea, to separate maps in categories/sub-categories and give a specific percent chance to get a map in this category. But I don't know how to store the data to make it easy to parse in Lua. How do I do?
For example, a category for desert maps, and a sub-category with different "oasis" versions.

EDIT: Note that it should support an actual list, i.e. one map per line.

Last edited by Exagone313 (05-Oct-15 22:13:43)

Offline

#12 05-Jan-16 13:50:15

jay1110
BETA Tester
Registered: 01-Sep-12
Posts: 208
Website

Re: [UPDATE]Random Next Map LUA v0.4

its not working for windows server or? i set the path
mapListFile = "C:\Users\user\server\nitmod\maplist.txt"

the lua runs. But when i do ?next it shows
Mode: Random Map. Current map goldrush. Next map none.

Offline

#13 05-Jan-16 23:04:38

jay1110
BETA Tester
Registered: 01-Sep-12
Posts: 208
Website

Re: [UPDATE]Random Next Map LUA v0.4

if you use a windows and have this as path

mapListFile = "C:\Users\user\server\nitmod\maplist.txt"

change it to "

mapListFile = C:\\Users\\user\\server\\nitmod\\maplist.txt"

just the \ to \\

thanks to exagone for that little fix.

Last edited by jay1110 (05-Jan-16 23:06:07)

Offline

#14 10-Apr-16 23:11:58

Exagone313
BETA Tester
Registered: 23-Feb-15
Posts: 45

Re: [UPDATE]Random Next Map LUA v0.4

---------------------------------
----- Random Next Map LUA -------
---------------------------------
-- Authors: Exagone313 and N!trox*
---- Exagone313:
-- Website: http://elou.world
-- Server: et.elou.world:27960 & et.clan-etc.de:27960
---- N!trox*:
-- Website: http://etmods.net
-- Server: etmods.net:27960
---------------------------------
-- Changelog:

-- v0.8 -- April 10th 2016
-- Added: Set oasis if too much fails to load map

-- v0.7 -- March 19th 2016
-- Added: command to show map list

-- v0.6 -- September 27th 2015
-- Fixed: current map

-- v0.5 -- March 23th 2015
-- Added: current map

-- v0.4 -- March 10th 2015
-- Added: Automatic nextmap announce in the server chat
-- Added: Possibility to disable banners (see 'useBanners')

-- v0.3 -- March 3rd 2015:
-- Added: messages templates
-- Added: Parse maplist from an external map list file, containing one map name per line
-- Added: Some code comments
-- Added: Register mod and mod version

-- v0.2 -- March 2nd 2015
-- Fixed: Don't pick a different map during warmup and after a map_restart
-- Added: Next map can now automatically be displayed to players through banners

-- v0.1 -- February 25th 2015
-- Fixed: Don't pick the current map or the last played map

---- Initial release (v0.003):
-- Added support of randomseed for map randomization
-- Added a command to show the next map for both client and server
-- Get array size automatically with table.getn(maps)

---------------------------------
---    MODULE CONFIGURATION   ---
---------------------------------

mapListFile = "/home/jay/etserv/servera/nitmod/maplist.txt" -- Absolute path to the map list file
shownextcmd = "?next"                                   -- Command that will be used to print the next map
showmapscmd = "?maps"                                   -- Command that will be used to print the map list
mapListPreCmd = "Map list:"                             -- Message displayed before the map list
mapsPerLine = 6                                         -- Number of map to be displayed per line in the list
chatInterval = 2                                                -- Delay, in minutes, between every automatic nextmap announce in the server chat
useBanners = 1                                                  -- If set to 1, enable nextmap announce in server banners (i.e: 'bannerCvar' will be set to 'bannerMsg')
bannerCvar = "g_msg1"                                   -- Define which banner will hold the "next map is ..." message
bannerMsg = "^dMode: ^3Random Map^d. Current map ^2%s^d. ^dNext map ^2%s^d."   -- Banner message template (%s will be replaced by the name of the next map)
chatMsg =   "^dMode: ^3Random Map^d. Current map ^2%s^d. ^dNext map ^2%s^d." -- Chat message template (%s will be replaced by the name of the next map)
CHATCMD = "chat"                                                -- Chat command (use "b 8" to run this script on ETPro)

---------------------------------
--  YOU DON'T NEED TO CHANGE  ---
--  ANYTHING BELOW THIS LINE  ---
---------------------------------

MODNAME = "Random Map"
MODVERSION = "0.6"
maps = {}                                                               -- This array will contain the map list
nextmap = "none"                                                -- This variable will contain the randomly selected next map
curmap = et.trap_Cvar_Get("mapname")    -- Name of the current map
lastmap_a = et.trap_Cvar_Get("lastmap_a")       -- Name of the last played maps
lastmap_b = et.trap_Cvar_Get("lastmap_b")
lastmap_c = et.trap_Cvar_Get("lastmap_c")
lastmap_d = et.trap_Cvar_Get("lastmap_d")
msgSent = 0
msgTime = chatInterval * 60000 - 1
-- Parse the map list file into the "maps" array
function ParseMapFile()
        local file = io.open(mapListFile, "r")
        for line in file:lines() do
                table.insert (maps, line);
        end
end

function nextMsgSend(clientNum)
        et.trap_SendServerCommand(clientNum, "" .. CHATCMD .. " \"" .. string.format(chatMsg, curmap, nextmap).. "\"")
end

function mapListMsgSend(clientNum)
    et.trap_SendServerCommand(clientNum, "" .. CHATCMD .. " \"" .. mapListPreCmd .. "\"")
    local color = 1
    local n = 1
    local line = ""
    for id, map in ipairs(maps) do
        if (n < mapsPerLine) then
            line = line .. "^" .. color .. map .. " "
            n = n + 1
        else
            et.trap_SendServerCommand(clientNum, "" .. CHATCMD .. " \"" .. line .. "^" .. color .. map .. "\"")
            n = 1
            line = ""
        end
        if(color < 9) then
            color = color + 1
                if(color == 4) then color = 5 end -- skip color 4 not goodly viewable
        else
            color = 1
        end
    end
end

function et_InitGame(levelTime,randomSeed,restart)
        local regModStr = string.format("%s v%s", MODNAME, MODVERSION)
        et.RegisterModname(regModStr) -- Register the LUA module
        ParseMapFile() -- Parse the map list now
        et.trap_Cvar_Set(bannerCvar, "") -- Clear banner
        et.trap_Cvar_Set("lastmap_d", et.trap_Cvar_Get("lastmap_c")) -- Set lastmap variables to avoid map loops
        et.trap_Cvar_Set("lastmap_c", et.trap_Cvar_Get("lastmap_b"))
        et.trap_Cvar_Set("lastmap_b", et.trap_Cvar_Get("lastmap_a"))
        et.trap_Cvar_Set("lastmap_a", curmap)
        luanm = et.trap_Cvar_Get("lua_nextmap") -- Get the previously selected random map
        if( curmap == luanm or luanm == "" or (curmap ~= lastmap_a and curmap ~= luanm) ) then -- If we've moved to the selected nextmap, to another map, or if it has not yet been set, pick another random map
                local i = 0
                while (1) do
                        nextmap = maps[math.random(table.getn(maps))]
                        if ((nextmap ~= curmap) and (nextmap ~= lastmap_a and nextmap ~= lastmap_b and nextmap ~= lastmap_c and nextmap ~= lastmap_d)) then -- loop again if you get one of the last 4 maps
                                break
                        end
                        if (i > 10) then
                                nextmap = "oasis"
                                break
                        end
                        i = i + 1
                end
        else -- If we're didn't switch to the random map yet, or to another map, don't change it.
                nextmap = luanm
        end
        et.trap_Cvar_Set("lua_nextmap", nextmap) -- Store the random map in a cvar to track it later
        et.trap_Cvar_Set("nextmap", "map " .. nextmap) -- Set the nextmap vstr
        if (useBanners == 1) then
                et.trap_Cvar_Set(bannerCvar, string.format(bannerMsg, curmap, nextmap)) -- Set the banner
        end
end

function et_RunFrame( levelTime )
        if( (chatInterval > 0) and ((msgSent + msgTime) < levelTime)) then
                msgSent = levelTime
                nextMsgSend(-1)
        end
end

function et_ClientCommand(clientNum, command)
    local arg0 = string.lower(et.trap_Argv(0))
    local arg1 = string.lower(et.trap_Argv(1))
    if ((arg0 == shownextcmd) or ((arg0 == "say") and (arg1 == shownextcmd))) then
        nextMsgSend(clientNum)
        return 1
    end
    if ((arg0 == showmapscmd) or ((arg0 == "say") and (arg1 == showmapscmd))) then
        mapListMsgSend(clientNum)
        return 1
    end
end

function et_ConsoleCommand(command)
    if (command == shownextcmd) then
        et.G_Print("" .. string.format(chatMsg, curmap, nextmap) .. "\n")
        return 1
    end
end

TODO:
- replace "map_full_name" with "Fancy Map Name" in Next Map message
- group some maps like goldrush and goldrush-ga to do not have these maps to be followed
- command (level based or using commands.db) to set next map

Last edited by Exagone313 (10-Apr-16 23:35:53)

Offline

#15 10-May-16 21:55:09

Exagone313
BETA Tester
Registered: 23-Feb-15
Posts: 45

Re: [UPDATE]Random Next Map LUA v0.4

Added: set next map command.

---------------------------------
----- Random Next Map LUA -------
---------------------------------
-- Authors: Exagone313 and N!trox*
---- Exagone313:
-- Website: http://elou.world
-- Server: et.elou.world:27960
---- N!trox*:
-- Website: http://etmods.net
-- Server: etmods.net:27960
---------------------------------
-- Changelog:

-- v0.9b -- May 11th 2016
-- Added: Set next map on Console (can be added in a custom nitmod command)
-- Added: Force lower case map names

-- v0.8 -- April 10th 2016
-- Added: Set oasis if too much fails to load map

-- v0.7 -- March 19th 2016
-- Added: command to show map list

-- v0.6 -- September 27th 2015
-- Fixed: current map

-- v0.5 -- March 23th 2015
-- Added: current map

-- v0.4 -- March 10th 2015
-- Added: Automatic nextmap announce in the server chat
-- Added: Possibility to disable banners (see 'useBanners')

-- v0.3 -- March 3rd 2015:
-- Added: messages templates
-- Added: Parse maplist from an external map list file, containing one map name per line
-- Added: Some code comments
-- Added: Register mod and mod version

-- v0.2 -- March 2nd 2015
-- Fixed: Don't pick a different map during warmup and after a map_restart
-- Added: Next map can now automatically be displayed to players through banners

-- v0.1 -- February 25th 2015
-- Fixed: Don't pick the current map or the last played map

---- Initial release (v0.003):
-- Added support of randomseed for map randomization
-- Added a command to show the next map for both client and server
-- Get array size automatically with table.getn(maps)

---------------------------------
---     MODULE CONFIGURATION   ---
---------------------------------

mapListFile = "/home/jay/etserv/servera/nitmod/maplist.txt" -- Absolute path to the map list file
shownextcmd = "?next"                                   -- Command that will be used to print the next map
showmapscmd = "?maps"                                                             -- Command that will be used to print the map list
setnextmapclcmd = "setnextmap"                                            -- Command used on the server console
mapListPreCmd = "Map list:"                                                     -- Message displayed before the map list
mapsPerLine = 6                                                                 -- Number of map to be displayed per line in the list
chatInterval = 2                                                -- Delay, in minutes, between every automatic nextmap announce in the server chat
useBanners = 1                                                  -- If set to 1, enable nextmap announce in server banners (i.e: 'bannerCvar' will be set to 'bannerMsg')
bannerCvar = "g_msg1"                                   -- Define which banner will hold the "next map is ..." message
bannerMsg = "^dMode: ^3Random Map^d. Current map ^2%s^d. ^dNext map ^2%s^d."   -- Banner message template (%s will be replaced by the name of the next map)
chatMsg =   "^dMode: ^3Random Map^d. Current map ^2%s^d. ^dNext map ^2%s^d." -- Chat message template (%s will be replaced by the name of the next map)
CHATCMD = "chat"                                                -- Chat command (use "b 8" to run this script on ETPro)

---------------------------------
--  YOU DON'T NEED TO CHANGE  ---
--  ANYTHING BELOW THIS LINE  ---
---------------------------------

MODNAME = "Random Map"
MODVERSION = "0.6"
maps = {}                                                               -- This array will contain the map list
nextmap = "none"                                                -- This variable will contain the randomly selected next map
curmap = et.trap_Cvar_Get("mapname")    -- Name of the current map
lastmap_a = et.trap_Cvar_Get("lastmap_a")       -- Name of the last played maps
lastmap_b = et.trap_Cvar_Get("lastmap_b")
lastmap_c = et.trap_Cvar_Get("lastmap_c")
lastmap_d = et.trap_Cvar_Get("lastmap_d")
msgSent = 0
msgTime = chatInterval * 60000 - 1
-- Parse the map list file into the "maps" array
function ParseMapFile()
        local file = io.open(mapListFile, "r")
        for line in file:lines() do
                table.insert (maps, string.lower(line));
        end
end

function nextMsgSend(clientNum)
        et.trap_SendServerCommand(clientNum, "" .. CHATCMD .. " \"" .. string.format(chatMsg, curmap, nextmap).. "\"")
end

function mapListMsgSend(clientNum)
        et.trap_SendServerCommand(clientNum, "" .. CHATCMD .. " \"" .. mapListPreCmd .. "\"")
        local color = 1
        local n = 1
        local line = ""
        for id, map in ipairs(maps) do
                if (n < mapsPerLine) then
                        line = line .. "^" .. color .. map .. " "
                        n = n + 1
                else
                        et.trap_SendServerCommand(clientNum, "" .. CHATCMD .. " \"" .. line .. "^" .. color .. map .. "\"")
                        n = 1
                        line = ""
                end
                if(color < 9) then
                        color = color + 1
                if(color == 4) then color = 5 end -- skip color 4 not goodly viewable
                else
                        color = 1
                end
        end
end

function setNextMap(mapName)
        for id, map in ipairs(maps) do
                if map == mapName then
                        nextmap = mapName
                        et.trap_Cvar_Set("nextmap", "map " .. nextmap)
                        nextMsgSend(-1)
                        et.G_Print("Next map set to " .. mapName .. "\n")
                        return
                end
        end
        et.G_Print("Map " .. mapName .. " not found\n")
end

function et_InitGame(levelTime,randomSeed,restart)
        local regModStr = string.format("%s v%s", MODNAME, MODVERSION)
        et.RegisterModname(regModStr) -- Register the LUA module
        ParseMapFile() -- Parse the map list now
        et.trap_Cvar_Set(bannerCvar, "") -- Clear banner
                et.trap_Cvar_Set("lastmap_d", et.trap_Cvar_Get("lastmap_c")) -- Set lastmap variables to avoid map loops
                et.trap_Cvar_Set("lastmap_c", et.trap_Cvar_Get("lastmap_b"))
                et.trap_Cvar_Set("lastmap_b", et.trap_Cvar_Get("lastmap_a"))
        et.trap_Cvar_Set("lastmap_a", curmap)
        luanm = et.trap_Cvar_Get("lua_nextmap") -- Get the previously selected random map
        if( curmap == luanm or luanm == "" or (curmap ~= lastmap_a and curmap ~= luanm) ) then -- If we've moved to the selected nextmap, to another map, or if it has not yet been set, pick another random map
                local i = 0
                while (1) do
                        nextmap = maps[math.random(table.getn(maps))]
                        if ((nextmap ~= curmap) and (nextmap ~= lastmap_a and nextmap ~= lastmap_b and nextmap ~= lastmap_c and nextmap ~= lastmap_d)) then -- loop again if you get one of the last 4 maps
                                break
                        end
                        if (i > 10) then
                                nextmap = "oasis"
                                break
                        end
                        i = i + 1
                end
        else -- If we're didn't switch to the random map yet, or to another map, don't change it.
                nextmap = luanm
        end
        et.trap_Cvar_Set("lua_nextmap", nextmap) -- Store the random map in a cvar to track it later
        et.trap_Cvar_Set("nextmap", "map " .. nextmap) -- Set the nextmap vstr
        if (useBanners == 1) then
                et.trap_Cvar_Set(bannerCvar, string.format(bannerMsg, curmap, nextmap)) -- Set the banner
        end
end

function et_RunFrame( levelTime )
        if( (chatInterval > 0) and ((msgSent + msgTime) < levelTime)) then
                msgSent = levelTime
                nextMsgSend(-1)
        end
end

function et_ClientCommand(clientNum, command)
        local arg0 = string.lower(et.trap_Argv(0))
        local arg1 = string.lower(et.trap_Argv(1))
        if ((arg0 == shownextcmd) or ((arg0 == "say") and (arg1 == shownextcmd))) then
                nextMsgSend(clientNum)
                return 1
        end
        if ((arg0 == showmapscmd) or ((arg0 == "say") and (arg1 == showmapscmd))) then
                mapListMsgSend(clientNum)
                return 1
        end
end

function et_ConsoleCommand(command)
        if (command == shownextcmd) then
                et.G_Print("" .. string.format(chatMsg, curmap, nextmap) .. "\n")
                return 1
        end
        if (command == setnextmapclcmd) then
                setNextMap(string.lower(et.trap_Argv(1)))
                return 1
        end
end

Last edited by Exagone313 (11-May-16 23:24:48)

Offline

#16 29-May-16 23:42:51

Fnatic
Member
Registered: 29-May-16
Posts: 1

Re: [UPDATE]Random Next Map LUA v0.4

Will this LUA work on Silent mod also?
If not, why not? what would be needed to make it work?

Offline

#17 30-May-16 18:53:20

jay1110
BETA Tester
Registered: 01-Sep-12
Posts: 208
Website

Re: [UPDATE]Random Next Map LUA v0.4

Fnatic wrote:

Will this LUA work on Silent mod also?
If not, why not? what would be needed to make it work?

why should it not work, try it and let us know.

edit: tested it, works well.

Last edited by jay1110 (05-Jun-16 02:29:53)

Offline

#18 08-Jun-16 01:37:56

Exagone313
BETA Tester
Registered: 23-Feb-15
Posts: 45

Re: [UPDATE]Random Next Map LUA v0.4

I stop the development for now, if the development of Nitmod stops. The actual commands could be converted into server commands, and be called from custom commands. This is the only thing I may change.

Last edited by Exagone313 (08-Jun-16 01:39:01)

Offline

Board footer

Powered by FluxBB