Merge branch 'mapchooser_wip' of UNLOZE/sm-plugins into master

This commit is contained in:
BotoX 2019-09-18 17:35:05 +02:00 committed by Gogs
commit 21a2d72c6d
6 changed files with 391 additions and 209 deletions

View File

@ -1,77 +0,0 @@
"MapchooserSoundsList"
{
"tf"
{
"counter"
{
"1"
{
"sound" "sourcemod/mapchooser/tf2/announcer_begins_1sec.mp3"
"builtin" "vo/announcer_begins_1sec.wav"
"event" "Announcer.RoundBegins1Seconds"
}
"2"
{
"sound" "sourcemod/mapchooser/tf2/announcer_begins_2sec.mp3"
"builtin" "vo/announcer_begins_2sec.wav"
"event" "Announcer.RoundBegins2Seconds"
}
"3"
{
"sound" "sourcemod/mapchooser/tf2/announcer_begins_3sec.mp3"
"builtin" "vo/announcer_begins_3sec.wav"
"event" "Announcer.RoundBegins3Seconds"
}
"4"
{
"sound" "sourcemod/mapchooser/tf2/announcer_begins_4sec.mp3"
"builtin" "vo/announcer_begins_4sec.wav"
"event" "Announcer.RoundBegins4Seconds"
}
"5"
{
"sound" "sourcemod/mapchooser/tf2/announcer_begins_5sec.mp3"
"builtin" "vo/announcer_begins_5sec.wav"
"event" "Announcer.RoundBegins5Seconds"
}
"10"
{
"sound" "sourcemod/mapchooser/tf2/announcer_dec_missionbegins10s01.mp3"
"builtin" "vo/announcer_dec_missionbegins10s01.wav"
}
"30"
{
"sound" "sourcemod/mapchooser/tf2/announcer_dec_missionbegins30s01.mp3"
"builtin" "vo/announcer_dec_missionbegins30s01.wav"
}
"60"
{
"sound" "sourcemod/mapchooser/tf2/announcer_dec_missionbegins60s06.mp3"
"builtin" "vo/announcer_dec_missionbegins60s06.wav"
}
}
"vote start"
{
"sound" "sourcemod/mapchooser/tf2/vote_started.mp3"
"event" "Vote.Created"
"builtin" "ui/vote_started.wav"
}
"vote end"
{
"sound" "sourcemod/mapchooser/tf2/vote_success.mp3"
"event" "Vote.Passed"
"builtin" "ui/vote_success.wav"
}
"vote warning"
{
"sound" "sourcemod/mapchooser/tf2/announcer_dec_missionbegins60s03.mp3"
"builtin" "vo/announcer_dec_missionbegins60s03.wav"
}
"runoff warning"
{
"sound" "sourcemod/mapchooser/tf2/vote_failure.mp3"
"event" "Vote.Failed"
"builtin" "ui/vote_failure.wav"
}
}
}

View File

@ -106,8 +106,11 @@ native CanNominateResult CanNominate();
* @return true on success
*/
native bool ExcludeMap(const char[] map, int cooldown = 0, int mode = 0);
// Cooldown in seconds
native bool ExcludeMapTime(const char[] map, int cooldown = 0, int mode = 0);
native int GetMapCooldown(const char[] map);
native int GetMapCooldownTime(const char[] map); // in unix time
native int GetMapMinTime(const char[] map);
native int GetMapMaxTime(const char[] map);
native int GetMapMinPlayers(const char[] map);
@ -141,7 +144,7 @@ native bool GetMapVIPRestriction(const char[] map, int client = 0);
*/
native int GetExtendsLeft();
native int AreRestrictionsActive();
native bool AreRestrictionsActive();
public SharedPlugin __pl_mapchooser_extended =
{

View File

@ -53,7 +53,7 @@
#pragma semicolon 1
#pragma newdecls required
#define MCE_VERSION "1.2.0"
#define MCE_VERSION "1.3.0"
enum RoundCounting
{
@ -105,6 +105,7 @@ ConVar g_Cvar_ExtendTimeStep;
ConVar g_Cvar_ExtendRoundStep;
ConVar g_Cvar_ExtendFragStep;
ConVar g_Cvar_ExcludeMaps;
ConVar g_Cvar_ExcludeMapsTime;
ConVar g_Cvar_IncludeMaps;
ConVar g_Cvar_IncludeMapsReserved;
ConVar g_Cvar_NoVoteMode;
@ -122,6 +123,7 @@ Handle g_MapList = INVALID_HANDLE;
Handle g_NominateList = INVALID_HANDLE;
Handle g_NominateOwners = INVALID_HANDLE;
StringMap g_OldMapList;
StringMap g_TimeMapList;
Handle g_NextMapList = INVALID_HANDLE;
Handle g_VoteMenu = INVALID_HANDLE;
KeyValues g_Config;
@ -224,6 +226,7 @@ public void OnPluginStart()
g_NominateList = CreateArray(arraySize);
g_NominateOwners = CreateArray(1);
g_OldMapList = new StringMap();
g_TimeMapList = new StringMap();
g_NextMapList = CreateArray(arraySize);
g_OfficialList = CreateArray(arraySize);
@ -237,7 +240,8 @@ public void OnPluginStart()
g_Cvar_ExtendTimeStep = CreateConVar("mce_extend_timestep", "15", "Specifies how much many more minutes each extension makes", _, true, 5.0);
g_Cvar_ExtendRoundStep = CreateConVar("mce_extend_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 1.0);
g_Cvar_ExtendFragStep = CreateConVar("mce_extend_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0);
g_Cvar_ExcludeMaps = CreateConVar("mce_exclude", "5", "Specifies for how many hours past maps should be excluded from the vote.", _, true, 0.0);
g_Cvar_ExcludeMaps = CreateConVar("mce_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0);
g_Cvar_ExcludeMapsTime = CreateConVar("mce_exclude_time", "5h", "Specifies how long in minutes an old map is excluded from the vote.");
g_Cvar_IncludeMaps = CreateConVar("mce_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 7.0);
g_Cvar_IncludeMapsReserved = CreateConVar("mce_include_reserved", "2", "Specifies how many private/random maps to include in the vote.", _, true, 0.0, true, 5.0);
g_Cvar_NoVoteMode = CreateConVar("mce_novote", "1", "Specifies whether or not MapChooser should pick a map if no votes are received.", _, true, 0.0, true, 1.0);
@ -378,8 +382,6 @@ public void OnPluginStart()
g_MapVoteRunoffStartForward = CreateGlobalForward("OnMapVoteRunnoffWarningStart", ET_Ignore);
InternalRestoreMapCooldowns();
CreateTimer(60.0, UpdateCooldowns, INVALID_HANDLE, TIMER_REPEAT);
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
@ -408,7 +410,9 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("IsMapOfficial", Native_IsMapOfficial);
CreateNative("CanNominate", Native_CanNominate);
CreateNative("ExcludeMap", Native_ExcludeMap);
CreateNative("ExcludeMapTime", Native_ExcludeMapTime);
CreateNative("GetMapCooldown", Native_GetMapCooldown);
CreateNative("GetMapCooldownTime", Native_GetMapCooldownTime);
CreateNative("GetMapMinTime", Native_GetMapMinTime);
CreateNative("GetMapMaxTime", Native_GetMapMaxTime);
CreateNative("GetMapMinPlayers", Native_GetMapMinPlayers);
@ -528,35 +532,45 @@ public void OnMapEnd()
g_WarningTimer = INVALID_HANDLE;
g_RunoffCount = 0;
if(g_SaveCDOnMapEnd)
{
static char map[PLATFORM_MAX_PATH];
GetCurrentMap(map, PLATFORM_MAX_PATH);
int Cooldown = InternalGetMapCooldown(map);
g_OldMapList.SetValue(map, Cooldown, true);
InternalStoreMapCooldowns();
}
}
public Action UpdateCooldowns(Handle timer)
{
static char map[PLATFORM_MAX_PATH];
int Cooldown;
if(g_SaveCDOnMapEnd)
{
GetCurrentMap(map, PLATFORM_MAX_PATH);
Cooldown = InternalGetMapCooldown(map);
g_OldMapList.SetValue(map, Cooldown, true);
Cooldown = GetTime() + InternalGetMapCooldownTime(map);
g_TimeMapList.SetValue(map, Cooldown, true);
}
StringMapSnapshot OldMapListSnapshot = g_OldMapList.Snapshot();
for(int i = 0; i < OldMapListSnapshot.Length; i++)
{
OldMapListSnapshot.GetKey(i, map, sizeof(map));
g_OldMapList.GetValue(map, Cooldown);
Cooldown --;
Cooldown--;
if(Cooldown > 0)
g_OldMapList.SetValue(map, Cooldown, true);
else
g_OldMapList.Remove(map);
}
InternalStoreMapCooldowns();
delete OldMapListSnapshot;
StringMapSnapshot TimeMapListSnapshot = g_TimeMapList.Snapshot();
for(int i = 0; i < TimeMapListSnapshot.Length; i++)
{
TimeMapListSnapshot.GetKey(i, map, sizeof(map));
g_TimeMapList.GetValue(map, Cooldown);
if(Cooldown < GetTime())
g_TimeMapList.Remove(map);
}
delete OldMapListSnapshot;
InternalStoreMapCooldowns();
}
public void OnClientPutInServer(int client)
@ -1559,7 +1573,7 @@ void CreateNextVote()
GetCurrentMap(map, PLATFORM_MAX_PATH);
RemoveStringFromArray(tempMaps, map);
if((GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps)) && (InternalAreRestrictionsActive()))
if(GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps) && InternalAreRestrictionsActive())
{
StringMapSnapshot OldMapListSnapshot = g_OldMapList.Snapshot();
for(int i = 0; i < OldMapListSnapshot.Length; i++)
@ -1570,6 +1584,21 @@ void CreateNextVote()
delete OldMapListSnapshot;
}
if(InternalAreRestrictionsActive())
{
StringMapSnapshot TimeMapListSnapshot = g_TimeMapList.Snapshot();
for(int i = 0; i < TimeMapListSnapshot.Length; i++)
{
TimeMapListSnapshot.GetKey(i, map, sizeof(map));
int Cooldown;
g_TimeMapList.GetValue(map, Cooldown);
if(Cooldown > GetTime())
RemoveStringFromArray(tempMaps, map);
}
delete TimeMapListSnapshot;
}
int voteSize = GetVoteSize(2);
int limit = (voteSize < GetArraySize(tempMaps) ? voteSize : GetArraySize(tempMaps));
@ -2038,8 +2067,51 @@ public int Native_ExcludeMap(Handle plugin, int numParams)
return true;
}
public int Native_ExcludeMapTime(Handle plugin, int numParams)
{
if(!InternalAreRestrictionsActive())
return true;
int len;
GetNativeStringLength(1, len);
if(len <= 0)
return false;
char[] map = new char[len+1];
GetNativeString(1, map, len+1);
int Cooldown;
int Mode = GetNativeCell(3);
if(Mode == 0)
{
Cooldown = InternalGetMapCooldownTime(map);
}
else if(Mode == 1)
{
Cooldown = GetNativeCell(2);
}
else if(Mode == 2)
{
g_TimeMapList.GetValue(map, Cooldown);
int NewCooldown = GetTime() + GetNativeCell(2);
if(NewCooldown > Cooldown)
Cooldown = GetNativeCell(2);
}
Cooldown += GetTime();
g_TimeMapList.SetValue(map, Cooldown, true);
InternalStoreMapCooldowns();
return true;
}
public int Native_GetMapCooldown(Handle plugin, int numParams)
{
if(!InternalAreRestrictionsActive())
return 0;
int len;
GetNativeStringLength(1, len);
@ -2055,6 +2127,26 @@ public int Native_GetMapCooldown(Handle plugin, int numParams)
return Cooldown;
}
public int Native_GetMapCooldownTime(Handle plugin, int numParams)
{
if(!InternalAreRestrictionsActive())
return 0;
int len;
GetNativeStringLength(1, len);
if(len <= 0)
return false;
char[] map = new char[len+1];
GetNativeString(1, map, len+1);
int Cooldown = 0;
g_TimeMapList.GetValue(map, Cooldown);
return Cooldown;
}
public int Native_GetMapMinTime(Handle plugin, int numParams)
{
int len;
@ -2308,7 +2400,24 @@ stock int InternalGetMapCooldown(const char[] map)
g_Config.Rewind();
}
return RoundToNearest(Cooldown * 60.0);
return Cooldown;
}
stock int InternalGetMapCooldownTime(const char[] map)
{
char time[16];
g_Cvar_ExcludeMapsTime.GetString(time, sizeof(time));
int Cooldown = TimeStrToSeconds(time);
if(g_Config && g_Config.JumpToKey(map))
{
g_Config.GetString("CooldownTime", time, sizeof(time), "");
Cooldown = TimeStrToSeconds(time);
g_Config.Rewind();
}
return Cooldown;
}
void CheckMapRestrictions(bool time = false, bool players = false)
@ -2520,10 +2629,10 @@ stock int InternalGetMapPlayerRestriction(const char[] map)
return 0;
}
stock int InternalAreRestrictionsActive()
stock bool InternalAreRestrictionsActive()
{
if (!GetConVarBool(g_Cvar_NoRestrictionTimeframeEnable))
return 1;
return true;
char sTime[8];
FormatTime(sTime, sizeof(sTime), "%H%M");
@ -2538,10 +2647,10 @@ stock int InternalAreRestrictionsActive()
if ((MinTime <= CurTime <= MaxTime))
{
return 0;
return false;
}
return 1;
return true;
}
stock int FindIntInArray(int[] array, int size, int value)
@ -2612,6 +2721,12 @@ stock void InternalRestoreMapCooldowns()
LogMessage("Restored cooldown: %s -> %d", map, Cooldown);
g_OldMapList.SetValue(map, Cooldown, true);
}
if((Cooldown = Cooldowns.GetNum("CooldownTime", -1)) > 0)
{
LogMessage("Restored time cooldown: %s -> %d", map, Cooldown);
g_TimeMapList.SetValue(map, Cooldown, true);
}
} while(Cooldowns.GotoNextKey(true));
delete Cooldowns;
@ -2650,15 +2765,51 @@ stock void InternalStoreMapCooldowns()
Cooldowns.SetNum("Cooldown", Cooldown);
Cooldowns.Rewind();
}
delete OldMapListSnapshot;
StringMapSnapshot TimeMapListSnapshot = g_TimeMapList.Snapshot();
for(int i = 0; i < TimeMapListSnapshot.Length; i++)
{
TimeMapListSnapshot.GetKey(i, map, sizeof(map));
g_TimeMapList.GetValue(map, Cooldown);
if (!Cooldowns.JumpToKey(map, true))
{
LogMessage("Unable to create/find key: %s", map);
delete TimeMapListSnapshot;
delete Cooldowns;
return;
}
Cooldowns.SetNum("CooldownTime", Cooldown);
Cooldowns.Rewind();
}
delete TimeMapListSnapshot;
if(!Cooldowns.ExportToFile(sCooldownFile))
{
LogMessage("Unable to export cooldown file: \"%s\"", sCooldownFile);
delete OldMapListSnapshot;
delete Cooldowns;
return;
}
delete OldMapListSnapshot;
delete Cooldowns;
}
}
stock int TimeStrToSeconds(const char[] str)
{
int seconds = 0;
int maxlen = strlen(str);
for(int i = 0; i < maxlen;)
{
int val = 0;
i += StringToIntEx(str[i], val);
if(str[i] == 'h')
{
val *= 60;
i++;
}
seconds += val * 60;
}
return seconds;
}

View File

@ -41,7 +41,7 @@
#include <multicolors>
#include <basecomm>
#define MCE_VERSION "1.13.0"
#define MCE_VERSION "1.3.0"
public Plugin myinfo =
{
@ -112,14 +112,13 @@ public void OnPluginStart()
RegAdminCmd("sm_nominate_addmap", Command_Addmap, ADMFLAG_CHANGEMAP, "sm_nominate_addmap <mapname> - Forces a map to be on the next mapvote.");
RegAdminCmd("sm_nominate_removemap", Command_Removemap, ADMFLAG_CHANGEMAP, "sm_nominate_removemap <mapname> - Removes a map from Nominations.");
RegAdminCmd("sm_nominate_exclude", Command_AddExclude, ADMFLAG_CHANGEMAP, "sm_nominate_exclude <mapname> [cooldown] - Forces a map to be inserted into the recently played maps. Effectively blocking the map from being nominated.");
RegAdminCmd("sm_nominate_exclude", Command_AddExclude, ADMFLAG_CHANGEMAP, "sm_nominate_exclude <mapname> [cooldown] [mode]- Forces a map to be inserted into the recently played maps. Effectively blocking the map from being nominated.");
RegAdminCmd("sm_nominate_exclude_time", Command_AddExcludeTime, ADMFLAG_CHANGEMAP, "sm_nominate_exclude_time <mapname> [cooldown] [mode] - Forces a map to be inserted into the recently played maps. Effectively blocking the map from being nominated.");
// Nominations Extended cvars
CreateConVar("ne_version", MCE_VERSION, "Nominations Extended Version", FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD);
g_mapTrie = CreateTrie();
CreateTimer(60.0, ForceUpdate, INVALID_HANDLE, TIMER_REPEAT);
}
public APLRes AskPluginLoad2(Handle hThis, bool bLate, char[] err, int iErrLen)
@ -241,11 +240,6 @@ void UpdateMapTrie()
delete excludeMaps;
}
public Action ForceUpdate(Handle timer)
{
UpdateMapTrie();
}
public void OnNominationRemoved(const char[] map, int owner)
{
int status;
@ -287,6 +281,8 @@ public Action Command_Addmap(int client, int args)
if(!CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_CHEATS, true))
{
bool RestrictionsActive = AreRestrictionsActive();
int status;
if(GetTrieValue(g_mapTrie, mapname, status))
{
@ -295,12 +291,10 @@ public Action Command_Addmap(int client, int args)
if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
CPrintToChat(client, "[NE] %t", "Can't Nominate Current Map");
if((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
{
int Cooldown = GetMapCooldown(mapname);
int ConvertedCooldown[2];
ConvertCooldown(Cooldown, ConvertedCooldown);
CPrintToChat(client, "[NE] %T", "Map Nominate Cooldown Error", client, ConvertedCooldown[0], ConvertedCooldown[1]);
CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown);
}
if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
@ -310,16 +304,25 @@ public Action Command_Addmap(int client, int args)
}
}
int TimeRestriction = GetMapTimeRestriction(mapname);
if(TimeRestriction)
int Cooldown = GetMapCooldownTime(mapname);
if(RestrictionsActive && Cooldown > GetTime())
{
CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60);
int Seconds = Cooldown - GetTime();
CPrintToChat(client, "[NE] %t", "Map Cooldown Time Error", Seconds / 3600, (Seconds % 3600) / 60);
return Plugin_Handled;
}
int TimeRestriction = GetMapTimeRestriction(mapname);
if(RestrictionsActive && TimeRestriction)
{
CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", TimeRestriction / 60, TimeRestriction % 60);
return Plugin_Handled;
}
int PlayerRestriction = GetMapPlayerRestriction(mapname);
if(PlayerRestriction)
if(RestrictionsActive && PlayerRestriction)
{
if(PlayerRestriction < 0)
CPrintToChat(client, "[NE] %t", "Map Nominate MinPlayers Error", PlayerRestriction * -1);
@ -330,7 +333,7 @@ public Action Command_Addmap(int client, int args)
}
int GroupRestriction = GetMapGroupRestriction(mapname);
if(GroupRestriction >= 0)
if(RestrictionsActive && GroupRestriction >= 0)
{
CPrintToChat(client, "[NE] %t", "Map Nominate Group Error", GroupRestriction);
return Plugin_Handled;
@ -394,7 +397,7 @@ public Action Command_AddExclude(int client, int args)
{
if(args < 1)
{
CReplyToCommand(client, "[NE] Usage: sm_nominate_exclude <mapname> [cooldown (minutes)] [mode]");
CReplyToCommand(client, "[NE] Usage: sm_nominate_exclude <mapname> [cooldown] [mode]");
return Plugin_Handled;
}
@ -434,6 +437,48 @@ public Action Command_AddExclude(int client, int args)
return Plugin_Handled;
}
public Action Command_AddExcludeTime(int client, int args)
{
if(args < 1)
{
CReplyToCommand(client, "[NE] Usage: sm_nominate_exclude_time <mapname> [cooldown] [mode]");
return Plugin_Handled;
}
static char mapname[PLATFORM_MAX_PATH];
GetCmdArg(1, mapname, sizeof(mapname));
int cooldown = 0;
int mode = 0;
if(args >= 2)
{
static char buffer[16];
GetCmdArg(2, buffer, sizeof(buffer));
cooldown = TimeStrToSeconds(buffer);
}
if(args >= 3)
{
static char buffer[8];
GetCmdArg(3, buffer, sizeof(buffer));
mode = StringToInt(buffer);
}
int status;
if(!GetTrieValue(g_mapTrie, mapname, status))
{
ReplyToCommand(client, "[NE] %t", "Map was not found", mapname);
return Plugin_Handled;
}
ShowActivity(client, "ExcludedTime map \"%s\" from nomination", mapname);
LogAction(client, -1, "\"%L\" excludedTime map \"%s\" from nomination", client, mapname);
// native call to mapchooser_extended
ExcludeMapTime(mapname, cooldown, mode);
return Plugin_Handled;
}
public Action Command_Say(int client, int args)
{
if(!client)
@ -494,6 +539,7 @@ public Action Command_Nominate(int client, int args)
static char mapname[PLATFORM_MAX_PATH];
GetCmdArg(1, mapname, sizeof(mapname));
int status;
if(!GetTrieValue(g_mapTrie, mapname, status))
{
@ -502,17 +548,17 @@ public Action Command_Nominate(int client, int args)
return Plugin_Handled;
}
bool RestrictionsActive = AreRestrictionsActive();
if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
{
if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
CPrintToChat(client, "[NE] %t", "Can't Nominate Current Map");
if(((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) && AreRestrictionsActive())
if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
{
int Cooldown = GetMapCooldown(mapname);
int ConvertedCooldown[2];
ConvertCooldown(Cooldown, ConvertedCooldown);
CPrintToChat(client, "[NE] %T", "Map Nominate Cooldown Error", client, ConvertedCooldown[0], ConvertedCooldown[1]);
CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown);
}
if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
@ -521,8 +567,17 @@ public Action Command_Nominate(int client, int args)
return Plugin_Handled;
}
int Cooldown = GetMapCooldownTime(mapname);
if(RestrictionsActive && Cooldown > GetTime())
{
int Seconds = Cooldown - GetTime();
CPrintToChat(client, "[NE] %t", "Map Cooldown Time Error", Seconds / 3600, (Seconds % 3600) / 60);
return Plugin_Handled;
}
bool VIPRestriction = GetMapVIPRestriction(mapname, client);
if((VIPRestriction) && AreRestrictionsActive())
if(RestrictionsActive && VIPRestriction)
{
CPrintToChat(client, "[NE] %t", "Map Nominate VIP Error");
@ -530,15 +585,15 @@ public Action Command_Nominate(int client, int args)
}
int TimeRestriction = GetMapTimeRestriction(mapname);
if((TimeRestriction) && AreRestrictionsActive())
if(RestrictionsActive && TimeRestriction)
{
CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60);
CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", TimeRestriction / 60, TimeRestriction % 60);
return Plugin_Handled;
}
int PlayerRestriction = GetMapPlayerRestriction(mapname);
if((PlayerRestriction) && AreRestrictionsActive())
if(RestrictionsActive && PlayerRestriction)
{
if(PlayerRestriction < 0)
CPrintToChat(client, "[NE] %t", "Map Nominate MinPlayers Error", PlayerRestriction * -1);
@ -549,7 +604,7 @@ public Action Command_Nominate(int client, int args)
}
int GroupRestriction = GetMapGroupRestriction(mapname, client);
if((GroupRestriction >= 0) && AreRestrictionsActive())
if(RestrictionsActive && GroupRestriction >= 0)
{
CPrintToChat(client, "[NE] %t", "Map Nominate Group Error", GroupRestriction);
return Plugin_Handled;
@ -760,7 +815,12 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
GetClientName(param1, name, MAX_NAME_LENGTH);
if((GetMapTimeRestriction(map) || GetMapPlayerRestriction(map) || GetMapGroupRestriction(map, param1) >= 0 || GetMapVIPRestriction(map, param1)) && AreRestrictionsActive())
if(AreRestrictionsActive() && (
GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) ||
GetMapGroupRestriction(map, param1) >= 0 ||
GetMapVIPRestriction(map, param1)))
{
PrintToChat(param1, "[NE] You can't nominate this map right now.");
return 0;
@ -811,7 +871,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
return ITEMDRAW_DISABLED;
}
if(((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) && AreRestrictionsActive())
if(AreRestrictionsActive() && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
{
return ITEMDRAW_DISABLED;
}
@ -822,8 +882,15 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
}
}
if((GetMapTimeRestriction(map) || GetMapPlayerRestriction(map) || GetMapGroupRestriction(map, param1) >= 0 || GetMapVIPRestriction(map, param1)) && AreRestrictionsActive())
if(AreRestrictionsActive() && (
GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) ||
GetMapGroupRestriction(map, param1) >= 0 ||
GetMapVIPRestriction(map, param1)))
{
return ITEMDRAW_DISABLED;
}
return ITEMDRAW_DEFAULT;
}
@ -868,8 +935,10 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
else
strcopy(buffer, sizeof(buffer), map);
bool RestrictionsActive = AreRestrictionsActive();
bool VIPRestriction = GetMapVIPRestriction(map);
if((VIPRestriction) && AreRestrictionsActive())
if(RestrictionsActive && VIPRestriction)
{
Format(buffer, sizeof(buffer), "%s (%T)", buffer, "VIP Restriction", param1);
}
@ -882,12 +951,10 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
return RedrawMenuItem(display);
}
if(((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) && AreRestrictionsActive())
if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
{
int Cooldown = GetMapCooldown(map);
int ConvertedCooldown[2];
ConvertCooldown(Cooldown, ConvertedCooldown);
Format(display, sizeof(display), "%s (%T)", buffer, "Map Cooldown", param1, ConvertedCooldown[0], ConvertedCooldown[1]);
Format(display, sizeof(display), "%s (%T %d)", buffer, "Recently Played", param1, Cooldown);
return RedrawMenuItem(display);
}
@ -898,15 +965,25 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
}
}
int TimeRestriction = GetMapTimeRestriction(map);
if((TimeRestriction) && AreRestrictionsActive())
int Cooldown = GetMapCooldownTime(map);
if(RestrictionsActive && Cooldown > GetTime())
{
Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60);
int Seconds = Cooldown - GetTime();
char time[16];
CustomFormatTime(Seconds, time, sizeof(time));
Format(display, sizeof(display), "%s (%T %s)", buffer, "Recently Played", param1, time);
return RedrawMenuItem(display);
}
int TimeRestriction = GetMapTimeRestriction(map);
if(RestrictionsActive && TimeRestriction)
{
Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", TimeRestriction / 60, TimeRestriction % 60);
return RedrawMenuItem(display);
}
int PlayerRestriction = GetMapPlayerRestriction(map);
if((PlayerRestriction) && AreRestrictionsActive())
if(RestrictionsActive && PlayerRestriction)
{
if(PlayerRestriction < 0)
Format(display, sizeof(display), "%s (%T)", buffer, "Map Player Restriction", param1, "+", PlayerRestriction * -1);
@ -917,13 +994,13 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
}
int GroupRestriction = GetMapGroupRestriction(map, param1);
if((GroupRestriction >= 0) && AreRestrictionsActive())
if(RestrictionsActive && GroupRestriction >= 0)
{
Format(display, sizeof(display), "%s (%T)", buffer, "Map Group Restriction", param1, GroupRestriction);
return RedrawMenuItem(display);
}
if((VIPRestriction) && AreRestrictionsActive())
if(RestrictionsActive && VIPRestriction)
{
return RedrawMenuItem(buffer);
}
@ -951,7 +1028,7 @@ stock bool IsNominateAllowed(int client)
int VIPTimeRestriction = GetVIPTimeRestriction();
if((VIPTimeRestriction) && AreRestrictionsActive())
{
CReplyToCommand(client, "[NE] During peak hours only VIPs are allowed to nominate maps. Wait for %d hours and %d minutes or buy VIP at Unloze.com to nominate maps again.", RoundToFloor(float(VIPTimeRestriction / 60)), VIPTimeRestriction % 60);
CReplyToCommand(client, "[NE] During peak hours only VIPs are allowed to nominate maps. Wait for %d hours and %d minutes or buy VIP at Unloze.com to nominate maps again.", VIPTimeRestriction / 60, VIPTimeRestriction % 60);
return false;
}
}
@ -1049,6 +1126,8 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1,
strcopy(buffer, sizeof(buffer), map);
bool RestrictionsActive = AreRestrictionsActive();
int status;
if(GetTrieValue(g_mapTrie, map, status))
{
@ -1060,12 +1139,10 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1,
return RedrawMenuItem(display);
}
if((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
{
int Cooldown = GetMapCooldown(map);
int ConvertedCooldown[2];
ConvertCooldown(Cooldown, ConvertedCooldown);
Format(display, sizeof(display), "%s (%T)", buffer, "Map Cooldown", param1, ConvertedCooldown[0], ConvertedCooldown[1]);
Format(display, sizeof(display), "%s (%T %d)", buffer, "Recently Played", param1, Cooldown);
return RedrawMenuItem(display);
}
@ -1077,16 +1154,26 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1,
}
}
int TimeRestriction = GetMapTimeRestriction(map);
if(TimeRestriction)
int Cooldown = GetMapCooldownTime(map);
if(RestrictionsActive && Cooldown > GetTime())
{
Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60);
int Seconds = Cooldown - GetTime();
char time[16];
CustomFormatTime(Seconds, time, sizeof(time));
Format(display, sizeof(display), "%s (%T %s)", buffer, "Recently Played", param1, time);
return RedrawMenuItem(display);
}
int TimeRestriction = GetMapTimeRestriction(map);
if(RestrictionsActive && TimeRestriction)
{
Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", TimeRestriction / 60, TimeRestriction % 60);
return RedrawMenuItem(display);
}
int PlayerRestriction = GetMapPlayerRestriction(map);
if(PlayerRestriction)
if(RestrictionsActive && PlayerRestriction)
{
if(PlayerRestriction < 0)
Format(display, sizeof(display), "%s (%T)", buffer, "Map Player Restriction", param1, "+", PlayerRestriction * -1);
@ -1097,7 +1184,7 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1,
}
int GroupRestriction = GetMapGroupRestriction(map);
if(GroupRestriction >= 0)
if(RestrictionsActive && GroupRestriction >= 0)
{
Format(display, sizeof(display), "%s (%T)", buffer, "Map Group Restriction", param1, GroupRestriction);
return RedrawMenuItem(display);
@ -1220,9 +1307,9 @@ stock int GetVIPTimeRestriction()
MinTime = (MinTime <= MaxTime) ? MinTime + 2400 : MinTime;
// Convert our 'time' to minutes.
CurTime = (RoundToFloor(float(CurTime / 100)) * 60) + (CurTime % 100);
MinTime = (RoundToFloor(float(MinTime / 100)) * 60) + (MinTime % 100);
MaxTime = (RoundToFloor(float(MaxTime / 100)) * 60) + (MaxTime % 100);
CurTime = ((CurTime / 100) * 60) + (CurTime % 100);
MinTime = ((MinTime / 100) * 60) + (MinTime % 100);
MaxTime = ((MaxTime / 100) * 60) + (MaxTime % 100);
return MaxTime - CurTime;
}
@ -1230,8 +1317,32 @@ stock int GetVIPTimeRestriction()
return 0;
}
stock void ConvertCooldown(int Cooldown, int Time[2])
stock void CustomFormatTime(int seconds, char[] buffer, int maxlen)
{
Time[0] = Cooldown / 60;
Time[1] = Cooldown - (Time[0] * 60);
if(seconds <= 60)
Format(buffer, maxlen, "%ds", seconds);
else if(seconds <= 3600)
Format(buffer, maxlen, "%dm", seconds / 60);
else if(seconds < 10*3600)
Format(buffer, maxlen, "%dh%dm", seconds / 3600, (seconds % 3600) / 60);
else
Format(buffer, maxlen, "%dh", seconds / 3600);
}
stock int TimeStrToSeconds(const char[] str)
{
int seconds = 0;
int maxlen = strlen(str);
for(int i = 0; i < maxlen;)
{
int val = 0;
i += StringToIntEx(str[i], val);
if(str[i] == 'h')
{
val *= 60;
i++;
}
seconds += val * 60;
}
return seconds;
}

View File

@ -40,7 +40,7 @@
#include <mapchooser>
#include <nextmap>
#define MCE_VERSION "1.13.0"
#define MCE_VERSION "1.3.0"
public Plugin myinfo =
{

View File

@ -2,45 +2,45 @@
{
"Vote Nextmap"
{
"en" "Vote for the next map!"
"en" "Vote for the next map!"
}
"Nextmap Voting Started"
{
"en" "Voting for next map has started."
"en" "Voting for next map has started."
}
"Nextmap Voting Finished"
{
"#format" "{1:s},{2:i},{3:i}"
"en" "Map voting has finished. The next map will be {1}. (Received {2}%% of {3} votes)"
"#format" "{1:s},{2:i},{3:i}"
"en" "Map voting has finished. The next map will be {1}. (Received {2}%% of {3} votes)"
}
"Current Map Extended"
{
"#format" "{1:i},{2:i}"
"en" "The current map has been extended. (Received {1}%% of {2} votes)"
"#format" "{1:i},{2:i}"
"en" "The current map has been extended. (Received {1}%% of {2} votes)"
}
"Extend Map"
{
"en" "Extend Current Map"
"en" "Extend Current Map"
}
"Dont Change"
{
"en" "Don't Change"
"en" "Don't Change"
}
"Current Map Stays"
{
"#format" "{1:i},{2:i}"
"en" "Current map continues! The Vote has spoken! (Received {1}%% of {2} votes)"
"#format" "{1:i},{2:i}"
"en" "Current map continues! The Vote has spoken! (Received {1}%% of {2} votes)"
}
"Changed Next Map"
{
"#format" "{1:s}"
"#format" "{1:s}"
"en" "Changed nextmap to \"{1}\"."
}
@ -106,90 +106,84 @@
"en" "*{1}"
}
"VIP Nomination"
"Map Cooldown Time Error"
{
"en" "VIP Nomination"
"#format" "{1:d},{2:d}"
"en" "This map is on cooldown for the next {1} hours and {2} minutes."
}
"Map Nominate Cooldown Error"
"VIP Nomination"
{
"#format" "{1:d},{2:d}"
"en" "You need to wait {1} hours and {2} minutes for the map to come off cooldown."
"en" "VIP"
}
"Map Nominate VIP Error"
{
"en" "You need to be VIP to nominate this map."
"en" "Only VIPs can nominate this map."
}
"Map Nominate Time Error"
{
"#format" "{1:d},{2:d}"
"en" "You can only nominate this map in {1} hours and {2} minutes."
"#format" "{1:d},{2:d}"
"en" "You can nominate this map in {1} hours and {2} minutes."
}
"Map Nominate MinPlayers Error"
{
"#format" "{1:d}"
"en" "Map requires {1} more players."
"#format" "{1:d}"
"en" "Map requires {1} more players."
}
"Map Nominate MaxPlayers Error"
{
"#format" "{1:d}"
"en" "Map requires {1} less players."
"#format" "{1:d}"
"en" "Map requires {1} less players."
}
"Map Nominate Group Error"
{
"#format" "{1:d}"
"en" "The maximum amount ({1}) of maps from this group has already been nominated."
}
"Map Cooldown"
{
"#format" "{1:d},{2:d}"
"en" "Cooldown: {1}H{2}M"
"#format" "{1:d}"
"en" "The maximum amount ({1}) of maps from this group has already been nominated."
}
"Map Time Restriction"
{
"#format" "{1:s},{2:d},{3:d}"
"en" "Time{1}{2}H{3}M"
"#format" "{1:s},{2:d},{3:d}"
"en" "Time{1}{2}H{3}M"
}
"Map Player Restriction"
{
"#format" "{1:s},{2:d}"
"en" "Players{1}{2}"
"#format" "{1:s},{2:d}"
"en" "Players{1}{2}"
}
"Map Group Restriction"
{
"#format" "{1:d}"
"en" "Group max: {1}"
"#format" "{1:d}"
"en" "Group max: {1}"
}
"VIP Restriction"
{
"en" "VIP only"
"en" "VIP only"
}
"Nomination Removed Time Error"
{
"#format" "{1:s}"
"en" "Your nomination {1} has been removed because it doesn't meet the time requirements."
"#format" "{1:s}"
"en" "Your nomination {1} has been removed because it doesn't meet the time requirements."
}
"Nomination Removed MinPlayers Error"
{
"#format" "{1:s}"
"en" "Your nomination {1} has been removed because it doesn't meet the minimum player requirements."
"#format" "{1:s}"
"en" "Your nomination {1} has been removed because it doesn't meet the minimum player requirements."
}
"Nomination Removed MaxPlayers Error"
{
"#format" "{1:s}"
"en" "Your nomination {1} has been removed because it exceeds the maximum player restriction."
"#format" "{1:s}"
"en" "Your nomination {1} has been removed because it exceeds the maximum player restriction."
}
}
}