[Ace] How to modify map tiles using script call

Discussion in 'RMVX Ace Tutorials' started by TheoAllen, Jan 16, 2019.

  1. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,499
    Likes Received:
    5,103
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    Example case:
    superherolanding.gif
    Q: Alright, but can you just do that by using tile event and flip the switch or just change the graphics and it solves the same problem?
    A: You can, but then you add more events. More event means extra process and may cause lag, and also makes your game looks messy in the back end.

    General thing you need to know.
    We are going to make a change in tile B to E on your map. So you need to know that each tile has its own ID.
    Started from tile B, from the left-top, the ID is 0, to the bottom-right, the ID is 255.
    Then goes to tile C, it started from 256 to 511.
    Then tile D, it started from 512, etc, you get the idea.

    What are these IDs tell us? And how are we going to use it?
    You can access the ID by using this script call.
    Code:
    $game_map.data[x, y, 2]
    X and Y are the coordinate positions of the map.
    The number 2 means it's layer 2, where the tile B to E is placed.

    Another Example Case:
    We are going to add objects surrounding the player. I'm going to use default world map tileset as an example.
    Here is what we are going to do.
    spawn.gif
    And so this is what I did.
    tilechange.jpg
    The coordinate adjacent to the player will be changed.

    However, do note that the change will not be saved. So if you leave the map and re-enter, all the changes made by the script will be gone. You will need an extra effort to make the change is saved. But I think it's better for someone to make a script for that.

    I guess that's all for now! :D

    Author Notes
    • I'm honestly not sure how useful it will be. But I think better tell everyone how to do the trick then it's up to their judgment how to use it.
    • For fun, you can actually place tile B in the first layer by doing $game_map.data[x,y,0] = 1 but doing so will eliminate ground tile.
    • If you have no idea what number a certain tile has, you can place that specific tile somewhere, and run a script call "p $game_map.data[x,y,2]" and open console log (Of course you have to change the [x,y] into the real number of the map position). It will print the number of that specific tile.
    • You can actually make a change of the auto-tiles/Tile-A, but the number is more complicated.
     
    Last edited: Mar 4, 2019
    #1
    Archeia, Heirukichi, Canini and 3 others like this.
  2. shivaa

    shivaa Villager Member

    Messages:
    11
    Likes Received:
    0
    First Language:
    French
    Primarily Uses:
    Other
    Hey, thanks for the tutorial
    May I ask you if we can modify the map using another script?
     
    Last edited by a moderator: Apr 25, 2019
    #2
  3. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,499
    Likes Received:
    5,103
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    Elaborate pls
     
    #3
  4. Andar

    Andar Veteran Veteran

    Messages:
    28,695
    Likes Received:
    6,599
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    to store the change map, you'll need more than this simple tutorial - you need a full script that modifies loading the map.
    Tsukihime's tile change script is one example for such a script.
     
    #4
  5. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,969
    Location:
    Philippines
    First Language:
    Tagalog
    This is certainly useful for temporary changes, I think especially with cutscenes.
     
    #5
  6. Canini

    Canini Veteran Veteran

    Messages:
    987
    Likes Received:
    657
    First Language:
    Swedish
    Primarily Uses:
    RMVXA
    Very nice tutorial and a good presentation of tile IDs. I will try experimenting a bit with this during the weekend. Like @Engr. Adiktuzmiko mentions, I think it will work wonders for cutscenes. I think I am going to replicate your first example as a lead-in to a boss battle!
     
    #6
    Engr. Adiktuzmiko likes this.
  7. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,499
    Likes Received:
    5,103
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    I just realized that adding this code isn't necessary as it's already in the default code. I wonder how/why I missed it.
    Code:
    class Game_Map
      def data
       @map.data
      end
    end
    
    Removing it ....

    Edit: Another sample use
    collapsing bridge.gif
     
    Last edited: Feb 26, 2019
    #7
    Engr. Adiktuzmiko and VeryXInh like this.
  8. VeryXInh

    VeryXInh Veteran Veteran

    Messages:
    90
    Likes Received:
    114
    First Language:
    Japanese
    Primarily Uses:
    RMXP
    Hello @TheoAllen , so we can swap tile just like that. What about change those tile's passage setting too?
     
    #8
  9. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,499
    Likes Received:
    5,103
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    Passability flag is still beyond my knowledge. The number is even weird than Tile ID. But I will get there in the future, or at least, I believe.
     
    #9
    VeryXInh likes this.
  10. VeryXInh

    VeryXInh Veteran Veteran

    Messages:
    90
    Likes Received:
    114
    First Language:
    Japanese
    Primarily Uses:
    RMXP
    Your tips are so awesome!
     
    #10
    TheoAllen likes this.
  11. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    1,297
    Likes Received:
    547
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    @TheoAllen I honestly think this is quite useful. I can think of quite a number of situations where you need something like this. Not to mention that I am a fan of using the lowest possible number of events to improve performance.

    I have been swapping tiles instead of using events for a while and I am quite glad to see that you made a nice tutorial about it. This way whenever I see people using events that way I can provide them a link to this tutorial. :D
     
    #11
    TheoAllen likes this.
  12. gstv87

    gstv87 Veteran Veteran

    Messages:
    1,817
    Likes Received:
    852
    First Language:
    Spanish
    Primarily Uses:
    RMVXA
    don't you need a refresh after changing the tiles? or is that taken care at each scene update?

    it's a binary/hexx conversion.
    if this is the tile's properties: 01001010, read as "0 to property 1, 1 to property 2, 0 to 3, etc", you turn that into Hex, and it gives you 48, so the tile's visible and stored data is 0x48.
    reverse that and you get the lot of properties as a binary string, but you have to know what each bit corresponds to.
    if you look into the passability checks in the code, you'll see each check passes down an Hex value and the coordinate, that Hex value when converted to binary is the bit to be scanned, so you binary AND or XOR (can't remember now) that against the full string, and it should return 0 or 1, meaning "this coordinate has THIS value 0/1".
    it's a neat way of storing a lot of booleans in a small space.
     
    Last edited: Mar 4, 2019
    #12
    TheoAllen likes this.
  13. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,499
    Likes Received:
    5,103
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    The data refresh is built-in by default.

    This is an interesting insight. Probably to reverse engineering the bits gonna take some time, unless if there's already source I can read somewhere. Thanks!
     
    #13
  14. gstv87

    gstv87 Veteran Veteran

    Messages:
    1,817
    Likes Received:
    852
    First Language:
    Spanish
    Primarily Uses:
    RMVXA
    RPG::Tileset, sub title "flags", Ace's help files.

    a solid impassable tile would be written as
    Code:
    0000111000001111
    |--|
    15 terrain tags
        |-|
        impassable by airship/boats
           |---|
           no counter/draw on top/bush/ladder
                |--|
                solid in 4 directions
    
     
    Last edited: Mar 4, 2019
    #14
    A-Moonless-Night likes this.
  15. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,499
    Likes Received:
    5,103
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    In short, if I wrote a flag that is "0x0140" means it's a tile that is a bush and does a floor damage?
     
    #15
  16. gstv87

    gstv87 Veteran Veteran

    Messages:
    1,817
    Likes Received:
    852
    First Language:
    Spanish
    Primarily Uses:
    RMVXA
    maybe?
    set everything to 0, change it by code, recompile, and restore the project, and it should be changed in the database.

    EDIT:
    yes.
    solid yes.
    I got confused because the scheme is 4-3-5-4, when the notation is 4-4-4-4, there's a bit that carries over from the counter/bush properties to the airship passability set.
     
    #16
  17. Oddball

    Oddball Veteran Veteran

    Messages:
    1,667
    Likes Received:
    445
    First Language:
    English
    Primarily Uses:
    N/A
    Thank you! I can make a wall collapse in after a player solves a simple puzzle involving it
     
    #17

Share This Page