1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

[Solved] A problem loading maps with custom loaders

Discussion in 'Modding Help' started by Vermilicious, Jan 21, 2016.

  1. Vermilicious

    Vermilicious Ballista Bolt Thrower

    Messages:
    232
    Hey guys, I've been working a bit on a new twist on Zombie mode, but I've come across an early problem.
    (Code available here: https://github.com/ANybakk/kag-undeadinvasion)

    I've written a custom loader by extending the generic PNGLoader. All nice and dandy. Because KAG.as uses default loaders, I've had to supply my own onInit function with much of the same code, except I try to register my own loader:

    Code:
    void onInit(CRules@ this) {
    
      //Register custom script for loading PNG map files
      RegisterFileExtensionScript("Scripts/UndeadInvasionMap.as", "png");
    
      //...
    }
    The problem is that LoadMap(CMap@, const string&) is never actually called, and even if KAG.as is omitted in gamemode.cfg, somehow when I run a local server the map is loaded with the default loader.

    Does anyone have a clue how this is possible?
     
  2. makmoud98

    makmoud98 You are already DEAD Forum Moderator Staff Alumni Tester

    Messages:
    586
    take a look at DefaultLoaders.as and make sure KAG.as is included in your gamemode.cfg, I think this will solve your issues.
     
  3. Vermilicious

    Vermilicious Ballista Bolt Thrower

    Messages:
    232
    I've looked into those scripts - that's how I figured I had to perform the RegisterFileExtensionScript call. Adding KAG.as is a problem, because there's no way to extend the script in DefaultLoaders.as. It only offers the default loaders. Therefore I copied the code in KAG.as into my own script, replacing the call to LoadDefaultMapLoaders.

    Code:
    void onInit(CRules@ this) {
    
      print("[UndeadInvasion:onInit]"); //This code is run
    
      //Register custom script for loading PNG map files
      //Instead of LoadDefaultMapLoaders()
      RegisterFileExtensionScript("Scripts/UndeadInvasionMap.as", "png"); //LoadMap in this script is never run
    
      LoadDefaultGUI();
    
      sv_gravity = 9.81f;
      particles_gravity.y = 0.25f;
      v_camera_ints = true;
      sv_visiblity_scale = 1.25f;
      cc_halign = 2;
      cc_valign = 2;
    
      s_effects = false;
    
      sv_max_localplayers = 1;
    
      //smooth shader
      Driver@ driver = getDriver();
    
      driver.AddShader("hq2x", 1.0f);
      driver.SetShader("hq2x", true);
    
    }
    --- Double Post Merged, Jan 25, 2016, Original Post Date: Jan 21, 2016 ---
    KAG.as is not included in the script list. (Modifying the script with a blank function and no includes makes no difference)

    Code:
    scripts = #KAG.as;
              UndeadInvasionRules.as; //onInit() in this file is called
              UndeadInvasionMap.as; //LoadMap() in this file is never called (included it here in the list to make sure it's available)
              UndeadInvasionPNGLoader.as; //The Custom loader extending the PNGLoader
              CTF_Trading.as;
              UseFakeTechs.as;
              SpawnFish.as;
              TeamMenu.as;
                        SpawnTraders.as;
              CTF_GiveSpawnItems.as;
              #CTF_BuilderMenu.as;
              KillMessages.as;
              JoinCoreHooks.as;
              CoreHooks.as;
                        CTF_PickSpawn.as;
              ChatCommands.as;
              TimeToEnd.as;
              RestartAfterShortPostGame.as;
              FanfareOnWin.as;
              PlayerCamera.as;
              DefaultScoreboard.as;
              Editor.as;
              SpawnImmunity.as;
              BasicHelps.as;
              ShowGamemode.as;
              VoteCore.as;
              DefaultVotes.as;
    But somehow, magically, the default PNG load script is still used:

    Code:
    [15:56:15] Loading script Scripts/MapLoaders/LoadPNGMap.as
    [15:56:15] LOADING PNG MAP ../Mods/ANybakk.kag-undeadinvasion/Maps/UndeadInvasionDefault.png
    But, if I include KAG.as normally, instead of doing the same stuff in my own script (UndeadInvasionRules.as), and just override Scripts/Default/DefaultLoaders.as with an extra game mode check, the correct load script is called.

    It would seem that even if KAG.as is included or not, edited or non-edited, only DefaultLoaders.as (or an overridden version) is allowed to call RegisterFileExtensionScript in a way that works. Doing it yourself, elsewhere, is ignored, or the program looks for the file in the wrong places. Weird.
     
  4. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    You're looking in the wrong place ;) be sure to search all files in these kind of cases.
    [​IMG]
    The one in autostart and server autostart is probably what you want to hook into (or in the defaultmaploaders function itself) - i'd also suggest not overwriting the default one but instead registering a custom loader for ".yourcustomextension.png" files - eg .vermloader.png so that you can still load normal maps on the server, and if you ever want to distribute your stuff, it'll be easier to integrate for others. introducing it as an "extra" extension means windows or whatever will still treat it as the right file type, but the engine will load it as something different. (This is how kaggen files are detected as different from normal configs.)
     
  5. Vermilicious

    Vermilicious Ballista Bolt Thrower

    Messages:
    232
    Thanks, Geti. Always helpful.

    I've only recently started using the search in files functionality in Notepad++, I guess it comes in handy. It is a bit confusing that this script is called in so many places. Is the call in KAG.as actually without any effect, but just a source of confusion? Maybe it should be removed :o)

    Using an extra, custom extension is a clever idea. However, when I add the RegisterFileExtensionScript call in onInit(CRules@), the loading fails ("Unknown map file extension"), so I guess there's a reason it's being called in the "server" scripts. While I can get away without overriding the default function by doing it this way, I will then have to override these scripts instead. I'm not sure that's a good trade-off.

    I've so far gotten away without actually overriding anything default, it's all contained, except this one thing. Not a huge thing, but it breaks the modularity principle(s) used elsewhere. I think it's a subject of improvement :o)
     
  6. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    @Verrazano is probably the one to talk to about improving modularity. Registering the extension generally has to be done before maps are loaded, which is why it's in the autostart/boot script. Some sort of maploaders.cfg could maybe be an easy trade-off though, I guess. Asking people to modify their autostart isn't a huge deal for server mods though imo.

    I'm not sure why MM included it in KAG.as but its not doing any harm there other than confusing innocent modders :)

    Incidentally, I'd suggest sublime over notepad++.
     
    Vermilicious likes this.