James' Easier Distance Conditions

James Westbrook

JamesWestbrook
Veteran
Joined
May 10, 2015
Messages
43
Reaction score
3
First Language
English
Primarily Uses

Distance Conditional 1.0


Written By James Westbrook(assistance given by Galv)


Introduction


Normally to make a conditional that makes an event happen if you(or another event) are X spaces close to an event, you have to either make a bunch of variables and assign each of them to the correct value of the event and player. Or you could write 4 lines of code that does it without the need of variables. With my plugin it's as simple as entering in one line of code.


This can be used in any way, even commercial. Credit not necessary since this is the probably the simplest plugin out there.


Features


This plugin has two basic functions:


Allows you to make conditional statement that only happens if you are X away from the event.


Or it allows you to make a conditional statement that only happens if an event is X away from another event.


I would use screenshots here, but I cannot think of a way to show this, unless you were actively playing the demo yourself.


How to Use


To install 1.0 of this plugin, you simply take the "JMW_DistanceConditional.js" file and copy it over to your project folder, inside the "plugins" folder which resides in "js". In your project, open the plugin manager. Double click on an empty space to add a plugin. In the drop down under "name" select "JMW_DistanceConditional". Then change the status to "on". Click "OK. Then click "OK" a second time, or click "APPLY".


To use the script, make a new event command. The command you are entering is under the first tab, "Conditonal Branch". Go to the fourth tab and enter either of the script commands below into the box. 


JMW.checkDist(eventID, distance)


This script command will be used when making things happen if the player is close enough to the event.


You replace "eventID" with the ID of the event. "Distance" you replace with the number of how close you want to be to make the event happen. For example, if I put "JMW.checkDist(5,2)", if my character walked within 2 spaces near event 5, the specified actions in the conditional will go off!


JMW.checkEventsDist(eventNumber1, eventNumber2, distance)


This command is if you want something to happen if two events get close enough.


You replace "eventNumber1" with the first event's ID, and "eventNumber2" with the second event's ID. "Distance" you replace with the distance you want to be between them.


For example, If I put "JMW.checkEventsDist(1,16,8), and events 1 and 16 were as little as 8 spaces close to each other, the actions specified in the conditional will occur!


Demo


Demo 1.0


Plugin Download:


Plugin 1.0


Script

Code:
//-----------------------------------------------------------------------------
// James Westbrook's Distance Conditional
// Version 1.0
var Imported = Imported || {};
Imported.JMW_DistanceConditional = true;

var JMW = JMW || {};                // Main object
JMW.DC = JMW.DC || {};  // Plugin object

/*:
 * @plugindesc Version 1.0 Checks how close the event is to the player/ another event.
 * 
 * @author James Westbrook 1.0
 *
 * @param
 * @desc
 * @default
 *
 * @help
 *Credits: James Westbrook for writing plugin, and Galv for
 *assisting James in writing his first plugin.
 *(find Galv at galvs-scripts.com)
 *Allowed for any use. Credit not necessary since this
 *is one of the easiest plugins to make.
 *
 * Normally when determining the distance between the player and an event(or an 
 *event with another event), you need four lines of scripting that you will have 
 *to insert into a conditional command. This plugin allows you to need only 
 *one line!
 *
 *Uses for this plugin:
 *You can use this plugin to determine if the player is close enough to an 
 *event to meet the distance requirement. You are able to modify this distance 
 *number to suit your needs. You can also use it with two different events, 
 *instead of with a player. 
 *
 *Script Calls:
 *You can put either of the scripts in a conditional event.
 *
 *JMW.checkDist(eventID, X distance)
 *
 *JMW.checkEventsDist(eventNumber1, eventNumber2, distance)
 *
 *(read later in help for further instructions
 * on how to use these calls)
 *
 *The first is used when you want the condition to be if 
 *the player is X close to the event. In "eventID" 
 *you fill in what the event's ID is. 
 *In "X distance" you fill in the distance you
 *want. For example if I put "JMW.checkDist(4, 5)"
 *, it would make the conditional would only
 *be met if the player was within 5 spaces
 *of event 4!
 *
 *The second script can be used to determine
 *if two events were within X range. For 
 *example, if I put "JMW.checkEventsDist(7, 8, 5)"
 * if events 7 and 8 were within 5 spaces, the
 condition is met.
 *The exact place you will be using these SCRIPT
 *commands is found in the first tab when making
 * an event. Under "Flow Control", select
 *"Conditional Branch". Go to the fourth
 *tab. At the bottom is the script option.
 *Click onto the word "Script" and then
 fill in the box with your script call!
 *For a visual aid, refer to my Distance
 *Conditional Demo!
 * 
 *
 */
    

(function() {
   

JMW.checkDist = function(eventNumber, playerDistance) {
return $gameMap.event(eventNumber)._x > $gamePlayer._x - playerDistance && $gameMap.event(eventNumber)._x < $gamePlayer._x + playerDistance && $gameMap.event(eventNumber)._y > $gamePlayer._y - playerDistance && $gameMap.event(eventNumber)._y < $gamePlayer._y + playerDistance
};

JMW.checkEventsDist = function(eventFirst, eventSecond, distanceSecond) {
    return $gameMap.event(eventFirst)._x > $gameMap.event(eventSecond)._x - distanceSecond && $gameMap.event(eventFirst)._x < $gameMap.event(eventSecond)._x + distanceSecond && $gameMap.event(eventFirst)._y > $gameMap.event(eventSecond)._y - distanceSecond && $gameMap.event(eventFirst)._y < $gameMap.event(eventSecond)._y + distanceSecond
};
    
	


})();
 

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

Latest Threads

Latest Posts

Latest Profile Posts

buinguyenhoangtho wrote on fizzly's profile.
Hello @fizzly, i would like to use your asset/ resource for my project ( is maybe commercial ). May i have your permission? Thanks you !
Working on breaking the limits of RPGMaker! :cool:
I have 470+ hours on RMMV but have only made a demo game, is this normal? :kaoswt: (I lose motivation a lot plus I use a 32gb laptop, so..)
I like Iron Maiden.
Benku wrote on Magnus0808's profile.
Hey man you helped me out a long time ago with a plugin i was wondering if you can help me out one more time since its literally the last thing i need help with if not is cool but id figured id ask you one more soild.

Forum statistics

Threads
95,427
Messages
929,082
Members
125,659
Latest member
AphoticAmaranth
Top