Features:
Scheduled Features:
Changelog:
- nextmap command
- setnextmap command
- setmap command
- weightings for maps (see @installation how to set the weights)
Scheduled Features:
- Vote for next map
Changelog:
v1.1 (Click to View)
- Added support for weightings of maps
- !nextmap command - next map will only be showed to the player who has executed
- Commands do not show up in chat
Usage (Click to View)
Commands:
Mapnames:
- !nextmap - displays the next map
- !setnextmap {mapname} - sets the next map
- !setmap {mapname} - Changes the map
Mapnames:
- Arkaden
- Bakaara
- Bootleg
- Carbon
- Dome
- Downturn
- Fallen
- Hardhat
- Interchange
- Lockdown
- Mission
- Outpost
- Resistance
- Seatown
- Underground
- Village
Installation (Click to View)
- Copy the "NextMap.dll" file to your plugin folder
- If you dont want to weighting the maps for maprotation, go to Step 3
Add following lines for weighings of maps to the sv_config.ini:
Quote:[NextMapPlugin]
A weighting of 0 means that the map will never be loaded automatically.
//Order of maps for weightings
//Arkaden, Bakaara, Bootleg, Carbon, Dome
//Downturn, Fallen, Hardhat, Interchange,
//Lockdown, Mission, Outpost, Resistance,
//Seatown, Underground, Village
weightings=1,2,3,4,5,5,4,3,2,1,3,6,2,3,0,1
- If you want only to deny guests to change the next map or map you have to use the Permission plugin from Pozzuh.
I recommend to work with the permission plugin, otherwise every player is able to change the map.
For example:
* admins & moderators are allowed to execute the !setnextmap and !setmap commands
* others can only view which will be the next map (!nextmap)
ExampleConfiguration (Click to View)[Permission]
//You can add more user groups here
Usergroups=Admin,Moderator,User
//Add admin xuids here (Go ingame and use !getxuid)
Admin_xuids=xuid1,xuid2,xuid3
//Admins can use all commands (Do not change!).
Admin_commands=*ALL*
//Add moderator xuids here
Moderator_xuids=xuid1,xuid2,xuid3
//Add commands moderators can use here
Moderator_commands=!help,!getxuid,!gettype,!setnextmap,!setmap
//Add commands everyone can use
User_commands=!help,!getxuid,!gettype,!nextmap
//Everyone who isn't in any other group is a user (Do not change!).
User_xuids=*EVERYONE*
Source code: (Click to View)
Code:
using Addon;
using System.Collections.Generic;
using System;
using System.Text.RegularExpressions;
namespace NextMap
{
public class NextMapPlugin : CPlugin
{
private string[] _keys;
private Dictionary<string, string> _maps;
private string _nextMap;
private bool _ignoreNextMap;
private int[] _weightings;
public override void OnServerLoad()
{
initMaps();
getRandomMap();
ServerLog(LogType.LogData, _nextMap);
ServerCommand("map " + _maps[_nextMap]);
_ignoreNextMap = false;
ServerPrint("Next Map Plugin loaded (v1.1) - Author: milchshake");
}
public override ChatType OnSay(string Message, ServerClient Client)
{
bool send = true;
if (Message == "!nextmap")
{
TellClient(Client.ClientNum, "Next map is: ^2" + _nextMap, true);
send = false;
}
if (Message.StartsWith("!setnextmap ", StringComparison.InvariantCultureIgnoreCase))
{
string map = Regex.Match(Message, "!setnextmap ([a-z]*)", RegexOptions.IgnoreCase).Groups[1].Value;
map = map.ToLower();
if (_maps.ContainsKey(map))
{
_nextMap = map;
ServerSay("Next map has been set: ^2" + _nextMap, true);
}
else
{
TellClient(Client.ClientNum, "^1 Unknown map", true);
TellClient(Client.ClientNum, "^2 Type !maps to display all maps", true);
}
send = false;
}
else if (Message.StartsWith("!setmap ", StringComparison.InvariantCultureIgnoreCase))
{
string map = Regex.Match(Message, "!setmap ([a-z]*)", RegexOptions.IgnoreCase).Groups[1].Value;
map = map.ToLower();
if (_maps.ContainsKey(map))
{
_ignoreNextMap = true;
ServerCommand("map " + _maps[map]);
}
else
{
TellClient(Client.ClientNum, "^1 Unknown map", true);
TellClient(Client.ClientNum, "^2 Type !maps to display all maps", true);
}
send = false;
}
ChatType type = send == true ? ChatType.ChatContinue : ChatType.ChatNone;
ServerLog(LogType.LogData, type.ToString());
return send == true ? ChatType.ChatContinue : ChatType.ChatNone;
}
public override void OnMapChange()
{
if (!_ignoreNextMap)
{
ServerCommand("map " + _maps[_nextMap]);
_ignoreNextMap = true;
}
else
{
_ignoreNextMap = false;
}
getRandomMap();
}
private void getRandomMap()
{
int weightCount = 0;
int max = 0;
foreach (int weighting in _weightings)
{
if(weighting > 0){
weightCount++;
}
max += weighting;
}
Random rand = new Random();
int unweighted = rand.Next(0, max);
int threshold = 0;
int mapIndex = 0;
bool abort = false;
for (int weighted = 0; weighted < _weightings.Length && !abort; weighted++)
{
threshold += _weightings[weighted];
if (unweighted < threshold)
{
mapIndex = weighted;
abort = true;
}
}
if (_nextMap == _keys[mapIndex] && weightCount > 1)
{
getRandomMap();
}
else if (weightCount == 0)
{
Random Rnd = new Random((int)DateTime.Now.Ticks);
_nextMap = _keys[Rnd.Next(0, _keys.Length - 1)];
}
else
{
_nextMap = _keys[mapIndex];
}
}
private void initMaps(){
_maps = new Dictionary<string, string>();
_maps.Add("arkaden", "mp_plaza2");
_maps.Add("bakaara", "mp_mogadishu");
_maps.Add("bootleg", "mp_bootleg");
_maps.Add("carbon", "mp_carbon");
_maps.Add("dome", "mp_dome");
_maps.Add("downturn", "mp_exchange");
_maps.Add("fallen", "mp_lambeth");
_maps.Add("hardhat", "mp_hardhat");
_maps.Add("interchange", "mp_interchange");
_maps.Add("lockdown", "mp_alpha");
_maps.Add("mission", "mp_bravo");
_maps.Add("outpost", "mp_radar");
_maps.Add("resistance", "mp_paris");
_maps.Add("seatown", "mp_seatown");
_maps.Add("underground", "mp_underground");
_maps.Add("village", "mp_village");
_keys = new string[_maps.Count];
_maps.Keys.CopyTo(_keys, 0);
string defaultWeightings = "";
for (int i = 0; i < _maps.Count; i++)
{
defaultWeightings += "1,";
}
defaultWeightings = defaultWeightings.Remove(defaultWeightings.Length - 1);
string str = GetServerCFG("NextMapPlugin", "weightings", defaultWeightings);
str = Regex.Replace(str, @"\s", "");
string[] weightings = str.Split(',');
if(_maps.Count != weightings.Length){
weightings = defaultWeightings.Split(',');
ServerPrint("ERROR loading weightings");
ServerLog(LogType.LogData, "ERROR loading weightings");
}
_weightings = new int[weightings.Length];
try
{
for (int i = 0; i < weightings.Length; i++)
{
_weightings[i] = int.Parse(weightings[i]);
}
}
catch (Exception e)
{
ServerPrint("ERROR loading weightings");
ServerLog(LogType.LogData, "ERROR loading weightings");
weightings = defaultWeightings.Split(',');
for (int i = 0; i < weightings.Length; i++)
{
_weightings[i] = int.Parse(weightings[i]);
}
}
}
}
}
