FindLump and the /maps directory

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm

FindLump and the /maps directory

Post by Mikk- »

Is it possible to use FindLump to find map files (.wads) in a .pk3 or do I need to use one of the other functions? My code works for standard vanilla maps, but not for maps in a .pk3

Code: Select all

class episodic : eventhandler
    {
    static const string final_level[] =
        {
        "", "E1M8", "E2M8", "E3M8", "E4M8", "MAP30", "NV_MAP08", "ML_MAP21", "TN_MAP30"
        };    
        
    static const string start_level[] =
        {
        "", "E2M1", "E3M1", "E4M1", "E5M1", "MAP01", "NV_MAP01", "ML_MAP01", "TN_MAP01", "PL_MAP01"
        };

    private int CheckLevelExists(int pos)
        {
        int max = start_level.Size();
        for(int i = pos; i < max; i++)
            {
            if(Wads.FindLump(start_level[i]) != -1)
                { return i; } 
            }
        return 0;
        }        
        
    private int GetFinalLevel(string mapname)
        {
        int max = final_level.Size();
        for(int i; i < max; i++)
            {
            if(mapname ~== final_level[i])
                { return i; } 
            }
        return 0;
        }
        
    private int GetStartLevel(string mapname)
        {
        int max = start_level.Size();
        for(int i; i < max; i++)
            {
            if(mapname ~== start_level[i])
                { return i; } 
            }
        return 0;
        }    
        
    Override void WorldLoaded(WorldEvent e)
        {
        
        cvar sequence     = CVar.FindCVar("sv_sequentialepisodes");
        cvar restorehp     = CVar.FindCVar("sv_sequentialhealing");
        string curlevel = Level.MapName;
        
        if(sequence && sequence.GetInt())
            {
                int lev0 = GetFinalLevel(curlevel);
                int lev1 = CheckLevelExists(lev0);
                if(lev0 && lev1)
                    {
                    Level.NextMap = start_level[lev1];
                    }
            
            if(restorehp && restorehp.GetInt() && GetStartLevel(curlevel))
                {
                for (int i = 0; i < MAXPLAYERS; i++)
                    {
                    PlayerInfo p = players[i];
                    if (p != NULL)
                        {
                        playerpawn plr = p.mo;
                        if(plr)
                            {
                            p.mo.A_GiveInventory("Health",restorehp.GetInt());
                            }
                        }
                    }
                }
                
            }
        }
    }
 
_mental_
 
 
Posts: 3819
Joined: Sun Aug 07, 2011 4:32 am

Re: FindLump and the /maps directory

Post by _mental_ »

Individual lumps from WADs inside maps folder are not exposed to overall list of lumps.
That's why the given code doesn't work with .pk3 maps.

One of the possible solutions is to check map's .wad presence using Wads.CheckNumForFullName() method

Code: Select all

if (Wads.CheckNumForFullName("maps/map01.wad") != -1)

Return to “Scripting”