#include <adminmenu>
#pragma semicolon 1
#pragma newdecls required
#define SZF(%0) %0, sizeof(%0)
public Plugin myinfo =
{
name = "DeleteMaps",
author = "asdf",
description = "Remove maps from the server",
version = "1.01",
url = "vk.com/samoletik2009"
}
ArrayList g_MapList;
TopMenu hTopMenu;
char currentmap[256],
mapcyclefile[64];
public void OnPluginStart()
{
char sBuffer[64];
FindConVar("mapcyclefile").GetString(SZF(sBuffer));
FormatEx(SZF(mapcyclefile),"/%s",sBuffer);
if(!FileExists(mapcyclefile))
{
SetFailState("Not Found %s", mapcyclefile);
}
g_MapList = new ArrayList(ByteCountToCells(256));
Handle topmenu;
if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != null))
{
OnAdminMenuReady(topmenu);
}
}
public void OnMapStart()
{
GetCurrentMap(SZF(currentmap));
}
public void OnConfigsExecuted()
{
g_MapList.Clear();
LoadMapList();
}
public void OnAdminMenuReady(Handle aTopMenu)
{
TopMenu topmenu = TopMenu.FromHandle(aTopMenu);
if (topmenu == hTopMenu) return;
hTopMenu = topmenu;
TopMenuObject srvcommands = hTopMenu.FindCategory(ADMINMENU_SERVERCOMMANDS);
if (srvcommands != INVALID_TOPMENUOBJECT)
{
hTopMenu.AddItem("sm_deletemaps", wtfmenu, srvcommands, "sm_deletemaps", ADMFLAG_BAN);
}
}
public int wtfmenu(Handle topmenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength)
{
if (action == TopMenuAction_DisplayOption)
Format(buffer, maxlength, "Удаление карт");
else if (action == TopMenuAction_SelectOption)
MapsMenu(param);
}
void MapsMenu(int client)
{
Menu maps = new Menu(MenuAsk_Handler);
char sBuffer[256],sBuffer2[256];
maps.SetTitle("Удалить карту:");
maps.ExitBackButton = true;
for (int i,length = g_MapList.Length; i < length; ++i)
{
g_MapList.GetString(i, SZF(sBuffer));
FormatEx(SZF(sBuffer2),"%s %s",sBuffer,strcmp(currentmap,sBuffer) == 0 ? "[X]":"");
maps.AddItem(sBuffer, sBuffer2);
}
maps.Display(client, MENU_TIME_FOREVER);
}
public int MenuAsk_Handler(Menu hMenu, MenuAction action, int client, int iItem)
{
switch(action)
{
case MenuAction_Select:
{
char mapname[256];
hMenu.GetItem(iItem, SZF(mapname));
if(FindMap(mapname, SZF(mapname)) != FindMap_NotFound)
{
char sBuffer[256];
FormatEx(SZF(sBuffer),"maps/%s.bsp",mapname);
if(DeleteFile(sBuffer))
{
DeleteFromMapCycle(mapname);
PrintToChat(client,"Карта %s успешно удалена",mapname);
LogAction(-1, -1, "Админ %L удалил карту %s", client,mapname);
MapsMenu(client);
return;
}
}
PrintToChat(client,"Ошибка: карта %s не удалена",mapname);
MapsMenu(client);
return;
}
case MenuAction_Cancel:
{
if (iItem == MenuCancel_ExitBack && hTopMenu != null)
hTopMenu.Display(client, TopMenuPosition_LastCategory);
}
case MenuAction_End: delete hMenu;
}
}
void DeleteFromMapCycle(char[] mapname)
{
File fFile = OpenFile(mapcyclefile, "w");
char map[256];
int index = g_MapList.FindString(mapname);
if (index != -1)
g_MapList.Erase(index);
for (int i,length = g_MapList.Length; i < length; i++)
{
g_MapList.GetString(i, SZF(map));
fFile.WriteLine(map);
}
delete fFile;
}
void LoadMapList()
{
File fFile = OpenFile(mapcyclefile, "r");
char map[256];
while(!fFile.EndOfFile() && fFile.ReadLine(map, 256))
{
TrimString(map);
g_MapList.PushString(map);
}
delete fFile;
}
public void OnLibraryRemoved(const char[] name)
{
if (strcmp(name, "adminmenu") == 0) hTopMenu = null;
}
public void OnPluginEnd()
{
delete g_MapList;
}