plugins/basecommands/map.sp
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/plugins/basecommands/map.sp	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,190 +0,0 @@
     1.4 -
     1.5 -public MenuHandler_ChangeMap(Handle:menu, MenuAction:action, param1, param2)
     1.6 -{
     1.7 -	if (action == MenuAction_Cancel)
     1.8 -	{
     1.9 -		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
    1.10 -		{
    1.11 -			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
    1.12 -		}
    1.13 -	}
    1.14 -	else if (action == MenuAction_Select)
    1.15 -	{
    1.16 -		decl String:map[64];
    1.17 -		
    1.18 -		GetMenuItem(menu, param2, map, sizeof(map));
    1.19 -	
    1.20 -		ShowActivity2(param1, "[SM] ", "%t", "Changing map", map);
    1.21 -
    1.22 -		LogAction(param1, -1, "\"%L\" changed map to \"%s\"", param1, map);
    1.23 -
    1.24 -		new Handle:dp;
    1.25 -		CreateDataTimer(3.0, Timer_ChangeMap, dp);
    1.26 -		WritePackString(dp, map);
    1.27 -
    1.28 -	}
    1.29 -}
    1.30 -
    1.31 -public AdminMenu_Map(Handle:topmenu, 
    1.32 -							  TopMenuAction:action,
    1.33 -							  TopMenuObject:object_id,
    1.34 -							  param,
    1.35 -							  String:buffer[],
    1.36 -							  maxlength)
    1.37 -{
    1.38 -	if (action == TopMenuAction_DisplayOption)
    1.39 -	{
    1.40 -		Format(buffer, maxlength, "%T", "Choose Map", param);
    1.41 -	}
    1.42 -	else if (action == TopMenuAction_SelectOption)
    1.43 -	{
    1.44 -		DisplayMenu(g_MapList, param, MENU_TIME_FOREVER);
    1.45 -	}
    1.46 -}
    1.47 -
    1.48 -public Action:Command_Map(client, args)
    1.49 -{
    1.50 -	if (args < 1)
    1.51 -	{
    1.52 -		ReplyToCommand(client, "[SM] Usage: sm_map <map>");
    1.53 -		return Plugin_Handled;
    1.54 -	}
    1.55 -
    1.56 -	decl String:map[64];
    1.57 -	GetCmdArg(1, map, sizeof(map));
    1.58 -
    1.59 -	if (!IsMapValid(map))
    1.60 -	{
    1.61 -		ReplyToCommand(client, "[SM] %t", "Map was not found", map);
    1.62 -		return Plugin_Handled;
    1.63 -	}
    1.64 -
    1.65 -	ShowActivity2(client, "[SM] ", "%t", "Changing map", map);
    1.66 -
    1.67 -	LogAction(client, -1, "\"%L\" changed map to \"%s\"", client, map);
    1.68 -
    1.69 -	new Handle:dp;
    1.70 -	CreateDataTimer(3.0, Timer_ChangeMap, dp);
    1.71 -	WritePackString(dp, map);
    1.72 -
    1.73 -	return Plugin_Handled;
    1.74 -}
    1.75 -
    1.76 -public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
    1.77 -{
    1.78 -	decl String:map[65];
    1.79 -
    1.80 -	ResetPack(dp);
    1.81 -	ReadPackString(dp, map, sizeof(map));
    1.82 -
    1.83 -	ServerCommand("changelevel \"%s\"", map);
    1.84 -
    1.85 -	return Plugin_Stop;
    1.86 -}
    1.87 -
    1.88 -LoadMapList(Handle:menu)
    1.89 -{
    1.90 -	decl String:mapPath[256];
    1.91 -	BuildPath(Path_SM, mapPath, sizeof(mapPath), "configs/adminmenu_maplist.ini");
    1.92 -	
    1.93 -	if (!FileExists(mapPath))
    1.94 -	{	
    1.95 -		if (g_MapList != INVALID_HANDLE)
    1.96 -		{
    1.97 -			RemoveAllMenuItems(menu);
    1.98 -		}
    1.99 -		
   1.100 -		return LoadMapFolder(menu);		
   1.101 -	}
   1.102 -
   1.103 -	// If the file hasn't changed, there's no reason to reload
   1.104 -	// all of the maps.
   1.105 -	new fileTime =  GetFileTime(mapPath, FileTime_LastChange);
   1.106 -	if (g_mapFileTime == fileTime)
   1.107 -	{
   1.108 -		return GetMenuItemCount(menu);
   1.109 -	}
   1.110 -	
   1.111 -	g_mapFileTime = fileTime;
   1.112 -	
   1.113 -	// Reset the array
   1.114 -	if (g_MapList != INVALID_HANDLE)
   1.115 -	{
   1.116 -		RemoveAllMenuItems(menu);
   1.117 -	}
   1.118 -
   1.119 -	new Handle:file = OpenFile(mapPath, "rt");
   1.120 -	if (file == INVALID_HANDLE)
   1.121 -	{
   1.122 -		LogError("[SM] Could not open file: %s, reverting to map folder", mapPath);
   1.123 -		return LoadMapFolder(menu);
   1.124 -	}
   1.125 -	
   1.126 -	decl String:buffer[256], len;
   1.127 -	while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
   1.128 -	{
   1.129 -		TrimString(buffer);
   1.130 -		
   1.131 -		if ((len = StrContains(buffer, ".bsp", false)) != -1)
   1.132 -		{
   1.133 -			buffer[len] = '\0';
   1.134 -		}
   1.135 -
   1.136 -		if (buffer[0] == '\0' 
   1.137 -			|| buffer[0] == ';'
   1.138 -			|| buffer[0] == '/'
   1.139 -			|| !IsValidConVarChar(buffer[0]))
   1.140 -		{
   1.141 -			continue;
   1.142 -		}
   1.143 -		
   1.144 -		if (IsMapValid(buffer))
   1.145 -		{
   1.146 -			AddMenuItem(menu, buffer, buffer);
   1.147 -		}
   1.148 -	}
   1.149 -
   1.150 -	CloseHandle(file);
   1.151 -	
   1.152 -	new count = GetMenuItemCount(menu);
   1.153 -	
   1.154 -	if (!count)
   1.155 -		return LoadMapFolder(menu);
   1.156 -	else
   1.157 -		return count;
   1.158 -}
   1.159 -
   1.160 -LoadMapFolder(Handle:menu)
   1.161 -{
   1.162 -	LogMessage("[SM] Loading menu map list from maps folder");
   1.163 -	
   1.164 -	new Handle:mapDir = OpenDirectory("maps/");
   1.165 -	
   1.166 -	if (mapDir == INVALID_HANDLE)
   1.167 -	{
   1.168 -		LogError("[SM] Could not open map directory for reading");
   1.169 -		return 0;
   1.170 -	}
   1.171 -	
   1.172 -	new String:mapName[64];
   1.173 -	new String:buffer[64];
   1.174 -	new FileType:fileType;
   1.175 -	new len;
   1.176 -	
   1.177 -	while(ReadDirEntry(mapDir, mapName, sizeof(mapName), fileType))
   1.178 -	{
   1.179 -		if(fileType == FileType_File)
   1.180 -		{
   1.181 -			len = strlen(mapName);
   1.182 -
   1.183 -			if(SplitString(mapName, ".bsp", buffer, sizeof(buffer)) == len)
   1.184 -			{
   1.185 -				AddMenuItem(menu, buffer, buffer);
   1.186 -			}
   1.187 -		}
   1.188 -  	}
   1.189 -  	
   1.190 -  	CloseHandle(mapDir);
   1.191 -  	
   1.192 -  	return GetMenuItemCount(menu);
   1.193 -}