[AG] Pushy Map Events

Kyuukon

主人公
Veteran
Joined
Aug 22, 2013
Messages
2,217
Reaction score
1,077
First Language
Spanish
Primarily Uses
RMMV
Pushy Map Events
by Akumu Games (me)

Description:
This plugin makes marked events attempt to move characters whenever they bump into each other in the map. You can assign different actions and behaviors, as well as disable them at any time.
Instructions about how to use it are explained in more detail inside.

Plugin:
Code:
// ============================================================================
// Pushy Map Events by Akumu Games
// ============================================================================
// For: RPGMAKER MV
// AG_PushyMapEvents.js
// Version: 1.4.3
// Free to use for commercial and non commercial projects as long as proper credit is given.
// ============================================================================
/*:
 * @plugindesc Marked events will attempt to move characters whenever they bump into each other in the map.
 *
 * @author Akumu Games
 * ============================================================================
 * @param Behavior
 * @desc The type of pushy behavior: "push" or "makeway".
 * @default push
 * @param Disable Pushable Player Switch ID
 * @desc When this switch is turned ON, the player becomes unpushable.
 * @default 0
 * @param Disable Pushable Events Switch ID
 * @desc When this switch is turned ON, all events on the map become unpushable.
 * @default 0
 * ============================================================================
 * @help
 * ============================================================================
 * Intructions
 * ============================================================================
 *
 * A map event can have assigned different actions to them:
 *      Pushy    -> Will apply the given behaviour to Pushable events and player.
 *      Pushable -> Will react to Pushy events.
 *      NPC      -> Will check for map passability, even when its Through flag is ON.
 * To attach them, you need to tag the event by simply including the string/s
 * "<Pushy>" or "<Pushable>" or <"NPC"> somewhere in its note input field.
 * Keep in mind:
 *      - Events can be both, Pushy and Pushable, at the same time.
 *      - The player can be considered Pushable only (no tag).
 *      - Pushable events cannot walk into a Pushy event location.
 * You can always turn ON the designated switches to disable these actions at any
 * time, if you require. Naturally, turning them OFF will resume their actions.
 *
 * Designed to work with same priority events with through flag ON so that they
 * won't overlap with the player sprite when possible, but it may have other
 * utilities. I'll leave that up to you :) Feel free to make any changes.
 *
 * ============================================================================
 * Plugin Commands
 * ============================================================================
 *
 * You can use the following plugin command to change the pushy behavior ingame:
 *      SetPushyBehaviorTo <behavior>
 * Where <behavior> corresponds to either:
 *      push    -> Events will push the player until they hit a wall (default).
 *      makeway -> Events will attempt to move the player out of their way.
 *
 *    examples: SetPushyBehaviorTo push
 *              SetPushyBehaviorTo makeway
 *
 * ============================================================================
 */

//=============================================================================
// Parameter Variables
//=============================================================================
(function() {
 
   var parameters = PluginManager.parameters('AG_PushyMapEvents');
   var _pushyBehavior = String(parameters['Behavior'] || 'push');
   var _disablePushablePlayerSwitch = Number(parameters['Disable Pushable Player Switch ID'] || 0);
   var _disablePushableEventsSwitch = Number(parameters['Disable Pushable Events Switch ID'] || 0);
 
   function isPushablePlayerDisabled(){
       return $gameSwitches.value(_disablePushablePlayerSwitch);
   }
 
   function isPushableEventsDisabled(){
       return $gameSwitches.value(_disablePushableEventsSwitch);
   }

//=============================================================================
// Game_Interpreter
//=============================================================================

   var Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
   Game_Interpreter.prototype.pluginCommand = function(command, args) {
       Game_Interpreter_pluginCommand.call(this, command, args)
       if (command === 'SetPushyBehaviorTo'){
           if (args[0] === 'push'){
               _pushyBehavior = 'push';
           }else if(args[0] === 'makeway'){
               _pushyBehavior = 'makeway';
           }
       }
   };
 
//=============================================================================
// Game_CharacterBase
//=============================================================================
 
   Game_CharacterBase.prototype.isCollidedWithPushyEvents = function(x, y){
       var events = $gameMap.eventsXy(x, y);
       return events.some(function(event) {
           return event.isPushy() || event.isBlock();
       });
   };
 
   Game_CharacterBase.prototype.pushableEvents = function(x, y){
       var events = $gameMap.eventsXy(x, y);
       return events.filter(function(event) {
           return event.isPushable();
       });
   };
 
   Game_CharacterBase.prototype.directionLeft90 = function(dir) {
       switch (dir) {
       case 2:
           return 6;
       case 4:
           return 2;
       case 6:
           return 8;
       case 8:
           return 4;
       }
   };

   var pushyMapEvents_Game_CharacterBase_canPass = Game_CharacterBase.prototype.canPass;
   Game_CharacterBase.prototype.canPass = function(x, y, d) {
       return this.isPushyPassable(x, y, d) && this.isNPCPassable(x, y, d) && pushyMapEvents_Game_CharacterBase_canPass.call(this, x, y, d);
   };
 
   Game_CharacterBase.prototype.isPushyPassable = function(x, y, d) {
       if(!this.isPushableCharacterDisabled() && this.isPushable() && !this.isDebugThrough()){
           var x2 = $gameMap.roundXWithDirection(x, d);
           var y2 = $gameMap.roundYWithDirection(y, d);
           return !this.isCollidedWithPushyEvents(x2, y2);
       }
       return true;
   };
 
   Game_CharacterBase.prototype.isNPCPassable = function(x, y, d) {
       if(!isPushableEventsDisabled() && this.isNPC() && !this.isDebugThrough()){
           return this.isMapPassable(x, y, d);
       }
       return true;
   };
 
   Game_CharacterBase.prototype.isPushableCharacterDisabled = function() {
       return true;
   };
 
   Game_CharacterBase.prototype.isPushable = function() {
       return false;
   };
 
   Game_CharacterBase.prototype.isNPC = function() {
       return false;
   };

//=============================================================================
// Game_Player
//=============================================================================

   Game_Player.prototype.isPushableCharacterDisabled = function() {
       return isPushablePlayerDisabled();
   };
 
   Game_Player.prototype.isPushable = function() {
       return !isPushablePlayerDisabled();
   };

//=============================================================================
// Game_Event
//=============================================================================

   var pushyMapEvents_Game_Event_update = Game_Event.prototype.update;
   Game_Event.prototype.update = function() {
       if(this.isPushy()){
           if(!isPushableEventsDisabled()){
               this.pushableEvents(this.x,this.y).forEach(function(event) {
                   if(event._eventId != this._eventId) this.pushCharacter(event);
               },this);
           }
           if(!isPushablePlayerDisabled()){
               this.pushCharacter($gamePlayer);
           }
       }
       pushyMapEvents_Game_Event_update.call(this);
   };
 
   Game_Event.prototype.pushPlayer = function() {
       this.PushCharacter($gamePlayer);
   };

   Game_Event.prototype.pushCharacter = function(character) {
       if(character.pos(this.x,this.y) && !character.isMoving()){
           var new_direction;
           if(_pushyBehavior == 'makeway'){
               new_direction = this.directionLeft90(this.direction());
               if(!character.canPass(character.x,character.y,new_direction)){
                   new_direction = this.reverseDir(new_direction);
                   if(!character.canPass(character.x,character.y,new_direction)){
                       new_direction = this.reverseDir(this.direction());
                       if(!character.canPass(character.x,character.y,new_direction))
                           new_direction = this.direction();
                   }
               }
           }else{
               new_direction = this.direction();
               if(!character.canPass(character.x,character.y,new_direction)){
                   new_direction = this.directionLeft90(this.direction());
                   if(!character.canPass(character.x,character.y,new_direction)){
                       new_direction = this.reverseDir(new_direction);
                       if(!character.canPass(character.x,character.y,new_direction))
                           new_direction = this.reverseDir(this.direction());
                   }
               }
           }
           if(!character.isDirectionFixed()){
               character.setDirection(this.reverseDir(new_direction));
               character.moveBackward();
           }else{
               character.moveStraight(new_direction);
           }
       }
   };
 
   Game_Event.prototype.isPushableCharacterDisabled = function() {
       return isPushableEventsDisabled();
   };
 
   Game_Event.prototype.isPushy = function() {
       return this.event().note.indexOf('<Pushy>') != -1;
   };
 
   Game_Event.prototype.isBlock = function() {
       return this.event().note.indexOf('<Block>') != -1;
   };
 
   Game_Event.prototype.isPushable = function() {
       return this.event().note.indexOf('<Pushable>') != -1 && !isPushableEventsDisabled();
   };
 
   Game_Event.prototype.isNPC = function() {
       return this.event().note.indexOf('<NPC>') != -1;
   };

})();
(save as "AG_PushyMapEvents.js" in your plugins folder)

Credits:
Author: Akumu Games

Notes:
This is my first plugin ever released xD It's rather simple, but I'm proud on how it turned out. It gives a nice little touch to how characters move in the map. I hope it's of use :)
 
Last edited:

Kyuukon

主人公
Veteran
Joined
Aug 22, 2013
Messages
2,217
Reaction score
1,077
First Language
Spanish
Primarily Uses
RMMV
Ugh... had to fix some errors in the logic. Updated to version 1.3. Now movement should be more consistent ;E
 

Skurge

" (GASP) What's going on!? "
Veteran
Joined
Jul 12, 2015
Messages
1,137
Reaction score
233
First Language
English
Primarily Uses
N/A
For my project which has events used for teleporting and events using the guise of a car which would logically be unmovable by a person.


How could you make exclusions for certain events?
 

Kyuukon

主人公
Veteran
Joined
Aug 22, 2013
Messages
2,217
Reaction score
1,077
First Language
Spanish
Primarily Uses
RMMV
For my project which has events used for teleporting and events using the guise of a car which would logically be unmovable by a person.


How could you make exclusions for certain events?
If you don't tag them by writing <Pushable> in their notes, the events should behave like they'd normally do, so they won't move.


Let's say you have a car event, then you'd tag it <Pushy> and set its through flag to ON. This way, the player and other <Pushable> NPCs will move along/aside whenever a car passes them over (this depends on the set behavior).
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Managed to find a way to hang a bed cover over my window. So no more being toasted alive in the afternoon!:kaoswt2:
So, uh, has anyone tried buying any resources from KokoroReflections? Because I've been looking for a 'buy' button on the site for like 10 minutes now and can't find one.
Any also thought it's too cringy to put the word "and you" in your credit as a special thanks?
Cause that's what I thought...
Everyone in the US right now: Please stay safe.
Symphony Celestia: Prophecy of the Falling Stars RPG Maker music pack WIP. Symphony Celestia is a new series that focuses on symphonic and orchestrated music to tell a story. Each story will include compositions that make up that story from beginning to end. Themes include: Battles, adventures, character themes, etc. Below is a video preview to the first story.

Forum statistics

Threads
97,980
Messages
948,321
Members
129,244
Latest member
Noxtrasave
Top