05-20-2012, 23:34 (This post was last modified: 05-20-2012, 23:47 by superg1973.)
Decided to learn a thing or 2. Updated and compiled it myself thanks to the great info on itsmods.com. Seems to be working. Remember if i missed something here i'm a noob and have no idea how to code. LOL
Thanks:
@JariZ for how to compile for noobs
@Yurio for the great plugin
Code:
using System;
using System.Collections.Generic;
using System.IO;
using Addon;
namespace YuMap
{
public class PluPack : CPlugin
{
const int MAPS = 20;
bool haveadmin = false;
List<string> admins = new List<string>();
string[] mapdev = { "mp_alpha", "mp_bootleg", "mp_bravo", "mp_carbon", "mp_dome", "mp_exchange", "mp_hardhat", "mp_interchange", "mp_lambeth", "mp_mogadishu", "mp_paris", "mp_plaza2", "mp_radar", "mp_seatown", "mp_underground", "mp_village", "mp_overwatch", "mp_park", "mp_italy", "mp_morningwood" };
string[] mapuser = { "lockdown", "bootleg", "mission", "carbon", "dome", "downturn", "hardhat", "interchange", "fallen", "bakaara", "resistance", "arkaden", "outpost", "seatown", "underground", "village", "overwatch", "liberation", "piazza", "blackbox" };
int[] maprange = new int[MAPS];
int range;
int nextmap = -1;
string dspl, dsr;
string[] dsrlist;
Random rnd = new Random(unchecked((int)DateTime.Now.Ticks));
int max, counter;
bool mult = false;
void GetAdmins()
{
string xuids = GetServerCFG("Yu", "xuids", "");
if (xuids != "")
foreach (string x in xuids.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries))
admins.Add(x);
if (admins.Count > 0) { haveadmin = true; }
}
bool Admin(string id)
{
foreach (string a in admins)
if (id.ToLowerInvariant().Contains(a.ToLowerInvariant())) { return true; }
return false;
}
void GetRotation()
{
dspl = GetServerCFG("Yu", "dspl", "default") + ".dspl";
dsrlist = GetServerCFG("Yu", "dsr", "FFA_default").Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
max = dsrlist.Length;
if (max == 1)
dsr = dsrlist[0];
else
{
counter = 0;
mult = true;
}
string[] weights = GetServerCFG("Yu", "weights", "3, 2, 5, 3, 5, 2, 5, 3, 2, 5, 5, 3, 2, 3, 2, 5, 3, 5, 2, 5").Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < MAPS; i++)
{
range += int.Parse(weights[i]);
maprange[i] = range;
}
}
int FindMap(int r)
{
for (int i = 0; i < MAPS; i++)
if (r <= maprange[i])
return i;
return -1;
}
void WriteDSPL(string map)
{
File.WriteAllText(@"admin\" + dspl, map + "," + dsr + ",1");
}
void GetNextMode()
{
dsr = dsrlist[counter];
counter++;
if (counter == max) { counter = 0; }
}
int GetMapByName(string map, bool dev = false)
{
string[] m = dev ? mapdev : mapuser;
for (int i = 0; i < MAPS; i++)
if (m[i].StartsWith(map, StringComparison.InvariantCultureIgnoreCase))
return i;
return -1;
}
int GetModeByName(string mode)
{
for (int i = 0; i < max; i++)
if (dsrlist[i].StartsWith(mode, StringComparison.InvariantCultureIgnoreCase))
return i;
return -1;
}
void SetMode(string[] p, int n = 2)
{
if (mult && p.Length > n)
{
int mode = GetModeByName(p[n]);
if (mode != -1)
{
dsr = dsrlist[mode];
counter = mode + 1;
if (counter == max) { counter = 0; }
}
}
}
public override void OnServerLoad()
{
ServerPrint("Yurio Map Plugin v1.2 loaded");
GetAdmins();
GetRotation();
}
public override void OnMapChange()
{
int prevmap = GetMapByName(GetDvar("mapname"), true);
repeat:
nextmap = FindMap(1 + rnd.Next(range));
if (prevmap == nextmap) { goto repeat; }
if (mult) { GetNextMode(); }
WriteDSPL(mapdev[nextmap]);
}
public override ChatType OnSay(string Message, ServerClient Client)
{
string[] parsed = Message.Split(null as char[], StringSplitOptions.RemoveEmptyEntries);
bool admin = haveadmin && Admin(Client.XUID);
if (Message.StartsWith("!mode", StringComparison.InvariantCultureIgnoreCase) && mult)
{
if (admin)
{
SetMode(parsed, 1);
WriteDSPL(mapdev[nextmap]);
}
string msg = "Next map is ^3" + mapuser[nextmap].ToUpperInvariant() + " ^7(^3" + dsr.ToUpperInvariant() + "^7)";
ServerSay(msg, true);
ServerPrint(msg);
return ChatType.ChatNone;
}
if (Message.StartsWith("!map", StringComparison.InvariantCultureIgnoreCase))
{
if (!admin) { return ChatType.ChatGame; }
if (parsed.Length > 1)
{
int map = GetMapByName(parsed[1]);
if (map != -1)
{
nextmap = map;
SetMode(parsed);
WriteDSPL(mapdev[nextmap]);
ServerCommand("map_rotate");
}
}
return ChatType.ChatNone;
}
if (Message.StartsWith("!nextmap", StringComparison.InvariantCultureIgnoreCase))
{
if (admin && parsed.Length > 1)
{
int map = GetMapByName(parsed[1]);
if (map != -1)
{
nextmap = map;
SetMode(parsed);
WriteDSPL(mapdev[nextmap]);
}
}
string m = (mult) ? " ^7(^3" + dsr.ToUpperInvariant() + "^7)" : String.Empty;
string msg = "Next map is ^3" + mapuser[nextmap].ToUpperInvariant() + m;
ServerSay(msg, true);
ServerPrint(msg);
return ChatType.ChatNone;
}
return ChatType.ChatContinue;
}
}
}