2 public MenuHandler_ChangeMap(Handle:menu, MenuAction:action, param1, param2)
4 if (action == MenuAction_Cancel)
6 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
8 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
11 else if (action == MenuAction_Select)
15 GetMenuItem(menu, param2, map, sizeof(map));
17 ShowActivity(param1, "%t", "Changing map", map);
19 LogAction(param1, -1, "\"%L\" changed map to \"%s\"", param1, map);
22 CreateDataTimer(3.0, Timer_ChangeMap, dp);
23 WritePackString(dp, map);
28 public AdminMenu_Map(Handle:topmenu,
30 TopMenuObject:object_id,
35 if (action == TopMenuAction_DisplayOption)
37 Format(buffer, maxlength, "%T", "Choose Map", param);
39 else if (action == TopMenuAction_SelectOption)
41 DisplayMenu(g_MapList, param, MENU_TIME_FOREVER);
45 public Action:Command_Map(client, args)
49 ReplyToCommand(client, "[SM] Usage: sm_map <map>");
50 return Plugin_Handled;
54 GetCmdArg(1, map, sizeof(map));
58 ReplyToCommand(client, "[SM] %t", "Map was not found", map);
59 return Plugin_Handled;
62 ShowActivity(client, "%t", "Changing map", map);
64 LogAction(client, -1, "\"%L\" changed map to \"%s\"", client, map);
67 CreateDataTimer(3.0, Timer_ChangeMap, dp);
68 WritePackString(dp, map);
70 return Plugin_Handled;
73 public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
78 ReadPackString(dp, map, sizeof(map));
80 ServerCommand("changelevel \"%s\"", map);
87 decl String:mapPath[256];
88 BuildPath(Path_SM, mapPath, sizeof(mapPath), "configs/adminmenu_maplist.ini");
90 if (!FileExists(mapPath))
92 if (g_MapList != INVALID_HANDLE)
94 RemoveAllMenuItems(menu);
97 return LoadMapFolder(menu);
100 // If the file hasn't changed, there's no reason to reload
102 new fileTime = GetFileTime(mapPath, FileTime_LastChange);
103 if (g_mapFileTime == fileTime)
105 return GetMenuItemCount(menu);
108 g_mapFileTime = fileTime;
111 if (g_MapList != INVALID_HANDLE)
113 RemoveAllMenuItems(menu);
116 new Handle:file = OpenFile(mapPath, "rt");
117 if (file == INVALID_HANDLE)
119 LogError("[SM] Could not open file: %s, reverting to map folder", mapPath);
120 return LoadMapFolder(menu);
123 decl String:buffer[64], len;
124 while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
128 if ((len = StrContains(buffer, ".bsp", false)) != -1)
133 if (buffer[0] == '\0' || !IsValidConVarChar(buffer[0]) || !IsMapValid(buffer))
138 AddMenuItem(menu, buffer, buffer);
143 new count = GetMenuItemCount(menu);
146 return LoadMapFolder(menu);
151 LoadMapFolder(Handle:menu)
153 LogMessage("[SM] Loading menu map list from maps folder");
155 new Handle:mapDir = OpenDirectory("maps/");
157 if (mapDir == INVALID_HANDLE)
159 LogError("[SM] Could not open map directory for reading");
163 new String:mapName[64];
164 new String:buffer[64];
165 new FileType:fileType;
168 while(ReadDirEntry(mapDir, mapName, sizeof(mapName), fileType))
170 if(fileType == FileType_File)
172 len = strlen(mapName);
174 if(SplitString(mapName, ".bsp", buffer, sizeof(buffer)) == len)
176 AddMenuItem(menu, buffer, buffer);
183 return GetMenuItemCount(menu);