Add nomination pool (Obus)

This commit is contained in:
BotoX 2018-03-20 01:05:31 +01:00
parent 0a7f08b561
commit 229fb7b8cd
2 changed files with 137 additions and 5 deletions

View File

@ -0,0 +1,21 @@
#if defined _nominations_extended_included_
#endinput
#endif
#define _nominations_extended_included_
native int GetNominationPool(ArrayList &pool);
native int PushMapIntoNominationPool(char[] map);
native int PushMapsIntoNominationPool(ArrayList maps);
native int RemoveMapFromNominationPool(char[] map);
native int RemoveMapsFromNominationPool(ArrayList maps);
public SharedPlugin __pl_nominations_extended =
{
name = "nominations",
file = "nominations_extended.smx",
#if defined REQUIRE_PLUGIN
required = 1,
#else
required = 0,
#endif
};

View File

@ -110,6 +110,19 @@ public void OnPluginStart()
g_mapTrie = CreateTrie(); g_mapTrie = CreateTrie();
} }
public APLRes AskPluginLoad2(Handle hThis, bool bLate, char[] err, int iErrLen)
{
RegPluginLibrary("nominations");
CreateNative("GetNominationPool", Native_GetNominationPool);
CreateNative("PushMapIntoNominationPool", Native_PushMapIntoNominationPool);
CreateNative("PushMapsIntoNominationPool", Native_PushMapsIntoNominationPool);
CreateNative("RemoveMapFromNominationPool", Native_RemoveMapFromNominationPool);
CreateNative("RemoveMapsFromNominationPool", Native_RemoveMapsFromNominationPool);
return APLRes_Success;
}
public void OnAllPluginsLoaded() public void OnAllPluginsLoaded()
{ {
// This is an MCE cvar... this plugin requires MCE to be loaded. Granted, this plugin SHOULD have an MCE dependency. // This is an MCE cvar... this plugin requires MCE to be loaded. Granted, this plugin SHOULD have an MCE dependency.
@ -156,11 +169,25 @@ public void OnConfigsExecuted()
g_NominationDelay = GetTime() + GetConVarInt(g_Cvar_InitialDelay); g_NominationDelay = GetTime() + GetConVarInt(g_Cvar_InitialDelay);
UpdateMapTrie();
UpdateMapMenus();
}
void UpdateMapMenus()
{
if(g_MapMenu != INVALID_HANDLE) if(g_MapMenu != INVALID_HANDLE)
delete g_MapMenu; delete g_MapMenu;
g_MapMenu = BuildMapMenu(""); g_MapMenu = BuildMapMenu("");
if(g_AdminMapMenu != INVALID_HANDLE)
delete g_AdminMapMenu;
g_AdminMapMenu = BuildAdminMapMenu("");
}
void UpdateMapTrie()
{
static char map[PLATFORM_MAX_PATH]; static char map[PLATFORM_MAX_PATH];
static char currentMap[PLATFORM_MAX_PATH]; static char currentMap[PLATFORM_MAX_PATH];
ArrayList excludeMaps; ArrayList excludeMaps;
@ -175,6 +202,7 @@ public void OnConfigsExecuted()
GetCurrentMap(currentMap, sizeof(currentMap)); GetCurrentMap(currentMap, sizeof(currentMap));
ClearTrie(g_mapTrie); ClearTrie(g_mapTrie);
for(int i = 0; i < GetArraySize(g_MapList); i++) for(int i = 0; i < GetArraySize(g_MapList); i++)
{ {
int status = MAPSTATUS_ENABLED; int status = MAPSTATUS_ENABLED;
@ -199,11 +227,6 @@ public void OnConfigsExecuted()
if(excludeMaps) if(excludeMaps)
delete excludeMaps; delete excludeMaps;
if(g_AdminMapMenu != INVALID_HANDLE)
delete g_AdminMapMenu;
g_AdminMapMenu = BuildAdminMapMenu("");
} }
public void OnNominationRemoved(const char[] map, int owner) public void OnNominationRemoved(const char[] map, int owner)
@ -597,7 +620,9 @@ Menu BuildMapMenu(const char[] filter)
GetArrayString(g_MapList, i, map, sizeof(map)); GetArrayString(g_MapList, i, map, sizeof(map));
if(!filter[0] || StrContains(map, filter, false) != -1) if(!filter[0] || StrContains(map, filter, false) != -1)
{
AddMenuItem(menu, map, map); AddMenuItem(menu, map, map);
}
} }
SetMenuExitButton(menu, true); SetMenuExitButton(menu, true);
@ -945,3 +970,89 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1,
return 0; return 0;
} }
public int Native_GetNominationPool(Handle plugin, int numArgs)
{
SetNativeCellRef(1, g_MapList);
return 0;
}
public int Native_PushMapIntoNominationPool(Handle plugin, int numArgs)
{
char map[PLATFORM_MAX_PATH];
GetNativeString(1, map, PLATFORM_MAX_PATH);
ShiftArrayUp(g_MapList, 0);
SetArrayString(g_MapList, 0, map);
UpdateMapTrie();
UpdateMapMenus();
return 0;
}
public int Native_PushMapsIntoNominationPool(Handle plugin, int numArgs)
{
ArrayList maps = GetNativeCell(1);
for (int i = 0; i < maps.Length; i++)
{
char map[PLATFORM_MAX_PATH];
maps.GetString(i, map, PLATFORM_MAX_PATH);
if (FindStringInArray(g_MapList, map) == -1)
{
ShiftArrayUp(g_MapList, 0);
SetArrayString(g_MapList, 0, map);
}
}
delete maps;
UpdateMapTrie();
UpdateMapMenus();
return 0;
}
public int Native_RemoveMapFromNominationPool(Handle plugin, int numArgs)
{
char map[PLATFORM_MAX_PATH];
GetNativeString(1, map, PLATFORM_MAX_PATH);
int idx;
if ((idx = FindStringInArray(g_MapList, map)) != -1)
RemoveFromArray(g_MapList, idx);
UpdateMapTrie();
UpdateMapMenus();
return 0;
}
public int Native_RemoveMapsFromNominationPool(Handle plugin, int numArgs)
{
ArrayList maps = GetNativeCell(1);
for (int i = 0; i < maps.Length; i++)
{
char map[PLATFORM_MAX_PATH];
maps.GetString(i, map, PLATFORM_MAX_PATH);
int idx = -1;
if ((idx = FindStringInArray(g_MapList, map)) != -1)
RemoveFromArray(g_MapList, idx);
}
delete maps;
UpdateMapTrie();
UpdateMapMenus();
return 0;
}