• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] Swapping Tilesets based on Day/Night

24
Posts
5
Years
    • Seen Jul 24, 2023
    Hi all.

    I've been trying to figure out how to switch tilesets based on the in-game time of day. Specifically, I'd like my maps to switch to a tileset at night where the windows are colored yellow, like in GSC.

    What I've done is created a new tileset graphic that is the same as Outside, but with the windows yellow instead of blue. I wasn't having any luck getting it to switch tileset graphics based on time of day, so instead I am having it switch Tilesets (as in, the ones defined in the Data tab of RPGMXP)

    In the Game_Map script section, I've altered the "tileset = $data_tilesets[@map.tileset_id]" line under def updateTileset to be the following:
    Code:
      def updateTileset
        if pbGetTimeNow.hour >= 20 || pbGetTimeNow.hour < 5
            tileset = $data_tilesets[@map.tileset_id+40]
          end
        else
            tileset = $data_tilesets[@map.tileset_id]
        end

    This is working just fine. In the Data tab, Outside Night is Tileset #41, so when the player is on a map that uses Tileset #1 (Outside) and the time is correct, it switches to Tileset #41 and shows the nighttime tileset graphics associated with that Tileset.

    Where I'm stuck is in trying to get it to only add 40 to the Tileset number when the player is on a map with tilesets so I don't have to make a separate "night" Tileset for everything (Inside, Pokecenter, etc). I've tried the following:
    Code:
      def updateTileset
        if @map.tileset_id == 1
          if pbGetTimeNow.hour >= 20 || pbGetTimeNow.hour < 5
              tileset = $data_tilesets[@map.tileset_id+40]
          else
              tileset = $data_tilesets[@map.tileset_id]
            end
          else
              tileset = $data_tilesets[@map.tileset_id]
        end

    And it works fine. The issue is if I try to add anything in addition to 1 (@map.tileset_id == 1 || 10) it treats every single map as adding 40 to @map.tileset_id.

    I hope this all made sense, if anyone has any ideas as to what's going wrong, or what I can do differently, I'd love to hear them.
     
    24
    Posts
    5
    Years
    • Seen Jul 24, 2023
    Update: I corrected it by doing the following:
    Code:
      def updateTileset
        maps=[1,2,24]
        if maps.include?(@map.tileset_id)
          if pbGetTimeNow.hour >= 20 || pbGetTimeNow.hour < 5
              tileset = $data_tilesets[@map.tileset_id+40]
          else
              tileset = $data_tilesets[@map.tileset_id]
            end
        else
            tileset = $data_tilesets[@map.tileset_id]
        end

    Now it will only swap tilesets on the correct maps! Still, this way of doing it feels inelegant. I am definitely still open to better ideas.
     
    465
    Posts
    7
    Years
    • Seen Apr 26, 2024
    hey there, i dont know that much coding wise, especially towards tilesets and stuff, however a script has existed for a bit (the animated tilesets by klein to be precise) which uses specific tiles from tilesets then changes them.

    maybe look into that.

    since i use it you could do it that you pick out the tiles you want the windows or things to change but instead of having multiple for animations just have one

    if we use the script;
    Code:
    KleinTiles=[]
    
    KleinTiles[1]=[]
    #Windows
    KleinTiles[1].push([2124,[1]])
    KleinTiles[1].push([2125,[2]])

    Basically, in the tileset 1 (so your outside map) the individial tile 2124 and 2125 are windows, then instead it uses tiles 1 or 2 from the animated ones

    only modification you'd have to make is find where it checks and make it check the time?
    in theory this should work. just an idea i had hope it helps
     
    24
    Posts
    5
    Years
    • Seen Jul 24, 2023
    Thanks, Archy, I love this idea. It's a lot cleaner than what I've got!

    I'll have some time this weekend to mess around with it, I'll let you know what I come up with.
     
    15
    Posts
    4
    Years
  • Hey! Thank you very much- I had tried that code previously, but I took another look at with a friend and we realized the problem was a bit of confusing code asking for maps when it was actually looking for tilesets. For any future onlookers looking for the fixed code:
    Placed in Game_Map around line 68, wherein [23] is the ID for the tileset you want to swap out, assuming that the night time version is at [24].
    Code:
      def updateTileset
        tilesets=[23] 
        if tilesets.include?(@map.tileset_id)
          if pbGetTimeNow.hour >= 20 || pbGetTimeNow.hour < 5
              tileset = $data_tilesets[@map.tileset_id+1]
          else
              tileset = $data_tilesets[@map.tileset_id]
            end
        else
            tileset = $data_tilesets[@map.tileset_id]
          end

    Thank you again!
     
    Last edited:
    24
    Posts
    5
    Years
    • Seen Jul 24, 2023
    Ah, good catch. I'm not really sure why I used "maps" instead of "tilesets" there! Hope that makes it easier for people who see this in the future.

    Using +1 as opposed to something like +40 to determine the nighttime version of the tileset will certainly lead to a cleaner Tilesets list in your Data tab, but just a heads up to any newcomers that it'll also require some rearranging of tilesets that are already there.

    Also, just as a side note - I originally used this just for window glow from the outside, but I've also made and nighttime version of the Indoor tilesets to make the windows deep purple/black, which is a nice effect. Windows shouldn't be bursting with sunshine at night!
     
    Last edited:
    Back
    Top