CityShrimp's Cover Tiles

● ARCHIVED · READ-ONLY
Started by cityshrimp 7 posts View original ↗
  1. CS_CoverTiles v1.0.2
    CityShrimp
    Introduction

    Cover Tiles for RPG Maker MV. Based on Neon Black's Terrain Tags script for Ace VX. Allows setting specific tiles as "covers" where the tile is passable and also drawn above the character. Common use case is to allow events and characters to walk behind walls and roofs.

    Free for commercial and non commercial use.

    Features
    1. Create cover tiles that are passable and drawn above events.
    2. Create block tiles that are always impassable
    Change Log
    1.0.2

    • Fixed bug where Tiles B-E do not show up when a tile is marked as a cover tile
    • Added a "Pass" tile. Does not change the appearance of a tile, just allows players to pass through.

    1.0.1
    • Fixed bug where cover tiles are not in right layer after loading game.
    • Added support for non-WebGl graphics (never tested!)
    How to Use
    • Download CS_CoverTiles.js
    • Place it into your project's Plugin list
    • Check description in file for latest Parameter
    Script:

    Download v1.0.2

    Script
    /*=============================================================================
    * CityShrimp's Cover Tiles
    * CS_CoverTiles.js
    * Version: 1.0.2
    * Free for commercial and non commercial use.
    *=============================================================================*/

    /*:
    * @plugindesc This plugin provides a way to create "covers".
    *
    * @author CityShrimp
    *
    * ===Parameter List===
    *
    * @param Pass RegionID
    * @desc This region ID will cause tile to become passable.
    * @Default 18
    *
    * @param Cover RegionID
    * @desc This region ID will cause tile to become a cover (passable + higher than events).
    * @Default 19
    *
    * @param Block RegionID
    * @desc This region ID will cause tile to become impassible.
    * @Default 20
    *
    * @Help
    * ============================================================================
    * Latest Version
    * ============================================================================
    *
    * Get the latest version of this script on
    * https://github.com/cityshrimp/rmmv/blob/master/CS_CoverTiles.js
    *
    *=============================================================================
    */

    var Imported = Imported || {};
    Imported['CS_CoverTiles'] = "1.0.2";

    var CS_CoverTiles = CS_CoverTiles || {};

    (function($) {
    "use strict";

    // Load parameters
    $.parameters = PluginManager.parameters("CS_CoverTiles") || {};
    $._pass_region_id = Number($.parameters['Pass RegionId'] || 18);
    $._cover_region_id = Number($.parameters['Cover RegionId'] || 19);
    $._block_region_id = Number($.parameters['Block RegionId'] || 20);
    $.tile_flag_set = {};

    var old_Game_Map_checkPassage = Game_Map.prototype.checkPassage;
    Game_Map.prototype.checkPassage = function(x, y, bit) {
    var rid = this.regionId(x, y);
    if (rid == $._block_region_id)
    return false;
    if (rid == $._pass_region_id || rid == $._cover_region_id)
    return true;
    return old_Game_Map_checkPassage.call(this, x, y, bit);
    }

    ShaderTilemap.prototype._paintTiles = function(startX, startY, x, y) {
    var mx = startX + x;
    var my = startY + y;
    var dx = x * this._tileWidth, dy = y * this._tileHeight;
    var tileId0 = this._readMapData(mx, my, 0);
    var tileId1 = this._readMapData(mx, my, 1);
    var tileId2 = this._readMapData(mx, my, 2);
    var tileId3 = this._readMapData(mx, my, 3);
    var shadowBits = this._readMapData(mx, my, 4);
    var upperTileId1 = this._readMapData(mx, my - 1, 1);
    var lowerLayer = this.lowerLayer.children[0];
    var upperLayer = this.upperLayer.children[0];

    var rtileId0 = (0 * $dataMap.height + my) * $dataMap.width + mx;
    var rtileId1 = (1 * $dataMap.height + my) * $dataMap.width + mx;
    var rtileId2 = (2 * $dataMap.height + my) * $dataMap.width + mx;
    var rtileId3 = (3 * $dataMap.height + my) * $dataMap.width + mx;

    if (this._isHigherTile(tileId0) || $gameMap.regionId(mx, my) == $._cover_region_id) {
    this._drawTile(upperLayer, tileId0, dx, dy);
    } else {
    this._drawTile(lowerLayer, tileId0, dx, dy);
    }
    if (this._isHigherTile(tileId1) || $gameMap.regionId(mx, my) == $._cover_region_id) {
    this._drawTile(upperLayer, tileId1, dx, dy);
    } else {
    this._drawTile(lowerLayer, tileId1, dx, dy);
    }

    this._drawShadow(lowerLayer, shadowBits, dx, dy);
    if (this._isTableTile(upperTileId1) && !this._isTableTile(tileId1)) {
    if (!Tilemap.isShadowingTile(tileId0)) {
    this._drawTableEdge(lowerLayer, upperTileId1, dx, dy);
    }
    }

    if (this._isOverpassPosition(mx, my)) {
    this._drawTile(upperLayer, tileId2, dx, dy);
    this._drawTile(upperLayer, tileId3, dx, dy);
    } else {
    if (this._isHigherTile(tileId2) || $gameMap.regionId(mx, my) == $._cover_region_id) {
    this._drawTile(upperLayer, tileId2, dx, dy);
    } else {
    this._drawTile(lowerLayer, tileId2, dx, dy);
    }

    if (this._isHigherTile(tileId3) || $gameMap.regionId(mx, my) == $._cover_region_id) {
    this._drawTile(upperLayer, tileId3, dx, dy);
    } else {
    this._drawTile(lowerLayer, tileId3, dx, dy);
    }
    }
    };

    Tilemap.prototype._paintTiles = function(startX, startY, x, y) {
    var tableEdgeVirtualId = 10000;
    var mx = startX + x;
    var my = startY + y;
    var dx = (mx * this._tileWidth).mod(this._layerWidth);
    var dy = (my * this._tileHeight).mod(this._layerHeight);
    var lx = dx / this._tileWidth;
    var ly = dy / this._tileHeight;
    var tileId0 = this._readMapData(mx, my, 0);
    var tileId1 = this._readMapData(mx, my, 1);
    var tileId2 = this._readMapData(mx, my, 2);
    var tileId3 = this._readMapData(mx, my, 3);
    var shadowBits = this._readMapData(mx, my, 4);
    var upperTileId1 = this._readMapData(mx, my - 1, 1);
    var lowerTiles = [];
    var upperTiles = [];

    if (this._isHigherTile(tileId0) || $gameMap.regionId(mx, my) == $._cover_region_id) {
    upperTiles.push(tileId0);
    } else {
    lowerTiles.push(tileId0);
    }
    if (this._isHigherTile(tileId1) || $gameMap.regionId(mx, my) == $._cover_region_id) {
    upperTiles.push(tileId1);
    } else {
    lowerTiles.push(tileId1);
    }

    lowerTiles.push(-shadowBits);

    if (this._isTableTile(upperTileId1) && !this._isTableTile(tileId1)) {
    if (!Tilemap.isShadowingTile(tileId0)) {
    lowerTiles.push(tableEdgeVirtualId + upperTileId1);
    }
    }

    if (this._isOverpassPosition(mx, my)) {
    upperTiles.push(tileId2);
    upperTiles.push(tileId3);
    } else {
    if (this._isHigherTile(tileId2) || $gameMap.regionId(mx, my) == $._cover_region_id) {
    upperTiles.push(tileId2);
    } else {
    lowerTiles.push(tileId2);
    }
    if (this._isHigherTile(tileId3) || $gameMap.regionId(mx, my) == $._cover_region_id) {
    upperTiles.push(tileId3);
    } else {
    lowerTiles.push(tileId3);
    }
    }

    var lastLowerTiles = this._readLastTiles(0, lx, ly);
    if (!lowerTiles.equals(lastLowerTiles) ||
    (Tilemap.isTileA1(tileId0) && this._frameUpdated)) {
    this._lowerBitmap.clearRect(dx, dy, this._tileWidth, this._tileHeight);
    for (var i = 0; i < lowerTiles.length; i++) {
    var lowerTileId = lowerTiles;
    if (lowerTileId < 0) {
    this._drawShadow(this._lowerBitmap, shadowBits, dx, dy);
    } else if (lowerTileId >= tableEdgeVirtualId) {
    this._drawTableEdge(this._lowerBitmap, upperTileId1, dx, dy);
    } else {
    this._drawTile(this._lowerBitmap, lowerTileId, dx, dy);
    }
    }
    this._writeLastTiles(0, lx, ly, lowerTiles);
    }

    var lastUpperTiles = this._readLastTiles(1, lx, ly);
    if (!upperTiles.equals(lastUpperTiles)) {
    this._upperBitmap.clearRect(dx, dy, this._tileWidth, this._tileHeight);
    for (var j = 0; j < upperTiles.length; j++) {
    this._drawTile(this._upperBitmap, upperTiles[j], dx, dy);
    }
    this._writeLastTiles(1, lx, ly, upperTiles);
    }
    };

    // ===End Alias Game_Map===
    })(CS_CoverTiles);

    Credits

    • CityShrimp
    Notes and Limitations
    • Weird stuff happens when you using mouse and character tries to run off screen. This causes the x, y coordinates to screw up and the covers won't work properly anymore.
  2. @cityshrimp In the "How to Use", should it be "Download "CS_CoverTiles.js"?
  3. mlogan said:
    @cityshrimp In the "How to Use", should it be "Download "CS_CoverTiles.js"?
    LOL, just saw that :D
  4. Wow! excellent plugin!!!
  5. Thanks. It's easy to use and works great but it eliminates the shadow if you have shadow above your tiles or at least it did for me.
  6. @ThePreparator Welcome to the forum! It's been a couple of years since the plugin's author was last seen here, so you may want to post a topic on the JS Plugin Support board if you're looking for help getting the shadows to work correctly with this plugin. Maybe someone else who has used this plugin can help you there.