From 1e62242690c521b74f191366300953f7c3b2f25f Mon Sep 17 00:00:00 2001 From: div0 Date: Mon, 4 Dec 2006 12:55:51 +0000 Subject: [PATCH] maplist edit commands git-svn-id: svn://svn.icculus.org/nexuiz/trunk@1988 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/default.cfg | 2 ++ data/qcsrc/server/g_world.qc | 64 ++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/data/default.cfg b/data/default.cfg index 821db7b15..5464013cf 100644 --- a/data/default.cfg +++ b/data/default.cfg @@ -218,6 +218,8 @@ seta g_maplist_index 0 // this is used internally for saving position in maplist seta g_maplist_selectrandom 0 // if 1, a random map will be chosen as next map, DEPRECATED in favor of g_maplist_shuffle seta g_maplist_shuffle 0 // new randomization method: like selectrandom, but avoid playing the same maps in short succession. This works by taking out the first element and inserting it into g_maplist with a bias to the end of the list. alias g_maplist_shufflenow "set _g_maplist_shufflenow 1" +alias g_maplist_add "set _g_maplist_add $1" +alias g_maplist_remove "set _g_maplist_remove $1" // timeout for kill credit when your damage knocks someone into a death trap set g_maxpushtime 8.0 diff --git a/data/qcsrc/server/g_world.qc b/data/qcsrc/server/g_world.qc index 5d94bf207..b1c5caec5 100644 --- a/data/qcsrc/server/g_world.qc +++ b/data/qcsrc/server/g_world.qc @@ -1244,6 +1244,60 @@ void PrintScoreboard() ServerConsoleEcho(".", FALSE); } +void RemoveFromMaplist(string m) +{ + string result; + float litems; + float i; + float found; + + litems = tokenize(cvar_string("g_maplist")); + found = 0; + result = ""; + for(i = 0; i < litems; ++i) + { + m = strcat(m); + result = strcat(result); + if(argv(i) == m) + found += 1; + else + result = strcat(result, "'", argv(i), "'"); + } + if(found) + { + cvar_set("g_maplist", result); + localcmd("set _g_maplist_have_shuffled 0\n"); + } + ServerConsoleEcho(strcat("Removed ", ftos(found), " items."), FALSE); +} + +void AddToMaplist(string m) +{ + float found; + float litems; + float i; + + if(!TryFile(strcat("maps/", m, ".mapcfg"))) + { + ServerConsoleEcho("Map not found.", FALSE); + return; + } + + litems = tokenize(cvar_string("g_maplist")); + found = 0; + for(i = 0; i < litems; ++i) + if(argv(i) == m) + found += 1; + if(!found) + { + cvar_set("g_maplist", strcat(cvar_string("g_maplist"), "'", m, "'")); + localcmd("set _g_maplist_have_shuffled 0\n"); + ServerConsoleEcho("Map added.", FALSE); + } + else + ServerConsoleEcho("Map already in list.", FALSE); +} + void ShuffleMaplist() { string result; @@ -1314,6 +1368,16 @@ void() CheckRules_World = } // automatically shuffle when setting g_maplist_shuffle + if(cvar_string("_g_maplist_add") != "") + { + AddToMaplist(cvar_string("_g_maplist_add")); + cvar_set("_g_maplist_add", ""); + } + if(cvar_string("_g_maplist_remove") != "") + { + RemoveFromMaplist(cvar_string("_g_maplist_remove")); + cvar_set("_g_maplist_remove", ""); + } if(cvar("_g_maplist_shufflenow") || (cvar("g_maplist_shuffle") && !cvar("_g_maplist_have_shuffled"))) { ShuffleMaplist(); -- 2.39.2