AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [SNIPPET] Maplist Generator (https://forums.alliedmods.net/showthread.php?t=291152)

headline 12-03-2016 00:47

[SNIPPET] Maplist Generator
 
Hey. I had to copy ~300 map names from my map directory and instead of doing it manually I threw this plugin together in order to do it for me. Thought I'd share :D

Don't keep this in your server if you don't need it to be. It'll just eat up resources...
PHP Code:

/* This plugin assumes you want the maplist.txt to be OVERWRITTEN *
 * Made by Headline & SWAT_88                                       */

#include <sourcemod>

#pragma newdecls required
#pragma semicolon 1

ArrayList files null;

public 
void OnPluginStart()
{
    
files = new ArrayList(PLATFORM_MAX_PATH);
    
    
ReadFileFolder("maps");
    
    
File newFile OpenFile("maplist.txt""w");
    
    
char tempString[PLATFORM_MAX_PATH];

    for (
int i 0files.Lengthi++)
    {
        
files.GetString(itempStringsizeof(tempString));
        
newFile.WriteLine(tempString);
    }
    
    
newFile.Close();
}

/* Snippet from SWAT_88 */
public void ReadFileFolder(char[] path)
{
    
Handle dirh null;
    
char buffer[256];
    
char tmp_path[256];
    
FileType type FileType_Unknown;
    
int len;
    
    
len strlen(path);
    if (
path[len-1] == '\n')
        
path[--len] = '\0';

    
TrimString(path);
    
    if(
DirExists(path))
    {
        
dirh OpenDirectory(path);
        
        while(
ReadDirEntry(dirhbuffersizeof(buffer), type))
        {
            
len strlen(buffer);
            if (
buffer[len-1] == '\n')
                
buffer[--len] = '\0';

            
TrimString(buffer);

            if (!
StrEqual(buffer,"",false) && !StrEqual(buffer,".",false) && !StrEqual(buffer,"..",false))
            {
                
strcopy(tmp_path,255,path);
                
StrCat(tmp_path,255"/");
                
StrCat(tmp_path,255buffer);
                if(
type == FileType_File)
                {
                    if (
StrContains(tmp_path".bsp") != -1)
                    {
                        
ReplaceString(tmp_path255".bsp""");
                        
ReplaceString(tmp_path255"maps/""");
                        
files.PushString(tmp_path);
                    }
                }
            }
        }
    }
    else
    {
        
SetFailState("[Log Cleaner] No log folder found!");
    }
    
    if(
dirh != null)
    {
        
CloseHandle(dirh);
    }



Grey83 12-03-2016 13:40

Re: [SNIPPET] Maplist Generator
 
maybe better do it like this?
PHP Code:

//            if (!StrEqual(buffer,"",false) && !StrEqual(buffer,".",false) && !StrEqual(buffer,"..",false))
            
if (strlen(buffer) > 4)    // if length of contents of the buffer is equal or less than 4 characters, then contents wrong
            
{
                
strcopy(tmp_path,255,path);
                
StrCat(tmp_path,255"/");
                
StrCat(tmp_path,255buffer);
                if(
type == FileType_File)
                {
//                    if (StrContains(tmp_path, ".bsp") != -1)
                    
if (StrEqual(tmp_path[strlen(tmp_path)-4], ".bsp"false))    // just compare the last 4 characters with the correct extension
//    or use:            if (StrContains(tmp_path, ".bsp") == strlen(tmp_path)-4)
                    
{
                        
ReplaceString(tmp_path255".bsp""");
                        
ReplaceString(tmp_path255"maps/""");
                        
files.PushString(tmp_path);
                    }
                }
            } 


headline 12-03-2016 14:24

Re: [SNIPPET] Maplist Generator
 
Quote:

Originally Posted by Grey83 (Post 2474866)
maybe better do it like this?
PHP Code:

//            if (!StrEqual(buffer,"",false) && !StrEqual(buffer,".",false) && !StrEqual(buffer,"..",false))
            
if (strlen(buffer) > 4)    // if length of contents of the buffer is equal or less than 4 characters, then contents wrong
            
{
                
strcopy(tmp_path,255,path);
                
StrCat(tmp_path,255"/");
                
StrCat(tmp_path,255buffer);
                if(
type == FileType_File)
                {
//                    if (StrContains(tmp_path, ".bsp") != -1)
                    
if (StrEqual(tmp_path[strlen(tmp_path)-4], ".bsp"false))    // just compare the last 4 characters with the correct extension
//    or use:            if (StrContains(tmp_path, ".bsp") == strlen(tmp_path)-4)
                    
{
                        
ReplaceString(tmp_path255".bsp""");
                        
ReplaceString(tmp_path255"maps/""");
                        
files.PushString(tmp_path);
                    }
                }
            } 


I jist threw it together from my log cleaner plugin. While i didnt read your edit (at work), there are plenty of better ways to do this and Im sure yours is better than what I posted :D

I didnt bother to spend time on it :D The best solution is to not use sourcemod at all

Sillium 12-05-2016 02:04

Re: [SNIPPET] Maplist Generator
 
I think Maplister does the same thing:
https://forums.alliedmods.net/showthread.php?t=56376

headline 12-05-2016 03:17

Re: [SNIPPET] Maplist Generator
 
Quote:

Originally Posted by Sillium (Post 2475312)
I think Maplister does the same thing:
https://forums.alliedmods.net/showthread.php?t=56376

Lol! Yup


All times are GMT -4. The time now is 18:56.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.