Trying to read an event's note tag based on an x,y

Philsco

Flipped Out RPG2Knet.com vet
Veteran
Joined
Apr 5, 2015
Messages
41
Reaction score
9
First Language
English
Primarily Uses
Hello! I'm having some difficulty determining how to use javascript to read an event's note tag. I've searched quite a bit, but only find ways to read the game data for items, battlers, etc.

What I'm trying to accomplish is a high-speed (practically instantaneous) projectile script for the open world map. I have it checking progressively in a straight line for events that it comes in contact with an event in line with the player from their originating (x,y), it should read their note tag to see if it is "blocking," "enemy," "destructible," or what have you.

A messy little example of how I want it to run is as follows, with the "what do I do to check for them?" part at the bottom:

Code:
// Find Player (x,y) and facing dir, and initiate check values
   var parameters = PluginManager.parameters('FNC_Ranged_Attack');

   var _startX = $gamePlayer.x;
   var _startY = $gamePlayer.y;
   var _startDir = $gamePlayer.direction();
   var _checkX = _startX;
   var _checkY = _startY;
   var _attack_range = parameters["Range"];
   var _rangeChecked = 0;


/* Check coordinates in an area ahead of Player (x,y)
 and see if there is an event in that square
 Then check for which note tag they have set and
 run the appropriate function to handle damage for enemies or
 facing direction / event removal for destructible objects
*/
   for (_rangeChecked = 0; _rangeChecked < _attack_range; _rangeChecked++) {
       if (_startDir == 2) { //Down
           _checkY++;
       } else if (_startDir == 8) { //Up
           _checkY--;
       } else if (_startDir == 4) { //Right
           _checkX++;
       } else if (_startDir == 2) { //Left
           _checkX--;
       }
       if ($gameMap.eventIdXy(_checkX, _checkY) != 0){
           //check event note tag, execute corresponding function
       }
   }

Any help would be appreciated, even if it's just, "Read this article," or, "You should be searching for [this]," or anything at all! Thank you for your time.

To note, I'm not against using comments in the event pages. That actually may be more beneficial, but I'm not sure if it is as easy as simply searching for a comment in an event. I know that Galv has a projectile plugin that uses this, but I also know he's a far more learned coder than I am! And, I don't want to ask for too much. But, if it's just as easy to read an event's containing comments as it is to read their note tag, I WOULD prefer that method.
 
Last edited:

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,660
First Language
Czech
Primarily Uses
RMMV
You need to use $dataMap to reach the notetags of events, they are stored in events[x].meta
 

Philsco

Flipped Out RPG2Knet.com vet
Veteran
Joined
Apr 5, 2015
Messages
41
Reaction score
9
First Language
English
Primarily Uses
Thanks Poryg.
So it'd be something like...
var _eventIdFound = $gameMap.eventIdXy(_checkX, _checkY);
if ($dataMap.events[_eventIdFound].meta == "enemy"){
...;
}
More or less?
I'll have to spend some time playing around with that when I get off work, tomorrow...thanks! I appreciate you pointing me in the right direction.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,660
First Language
Czech
Primarily Uses
RMMV
The var _eventIdFound line looks correct to me.
However, the second one would be incorrect.
The correct one would be
Code:
if ($dataMap.events[_eventIdFound].meta.enemy){

}
Meta is an associative array, so you can't use meta == "enemy".
So simply put <enemy> in the event note field, use the above command to check and you're good to go.
 

Philsco

Flipped Out RPG2Knet.com vet
Veteran
Joined
Apr 5, 2015
Messages
41
Reaction score
9
First Language
English
Primarily Uses
Oh, got'cha, so notes are saved as the "meta" array of an event object.
I'm sorry to keep picking your brain here, but if I'm looking to put two tags in the note field (say, <door><destructible> vs <door><indestructible>), what would be the proper syntax to check that?
Code:
if ($dataMap.events[_eventIdFound].meta.door) {
  if ($dataMap.events[_eventIdFound].meta.destructible){
    ...
  } else if ($dataMap.events[_eventIdFound].meta.indestructible){
    ...
  }
}
seems pretty straightforward, so is that about it?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,441
Reaction score
2,553
First Language
English
Primarily Uses
RMMZ
If there are only two states you don't even need one of those: whichever one you don't set with a tag will be the default, so if you use <destructible> then you know that anything that doesn't have that tag is indestructible and vice versa. That simplifies your if statement.
 

Philsco

Flipped Out RPG2Knet.com vet
Veteran
Joined
Apr 5, 2015
Messages
41
Reaction score
9
First Language
English
Primarily Uses
You guys are incredibly helpful and I can't thank you all enough for working with me on this. I'll pay it all back by releasing this plugin once it's good and polished up :p
 

Philsco

Flipped Out RPG2Knet.com vet
Veteran
Joined
Apr 5, 2015
Messages
41
Reaction score
9
First Language
English
Primarily Uses
One final question, and I should be able to handle the rest of it myself.
And this is a really, really stupid question...but...
How do I handle calling the plugin? I've searched for the plugin command to call a plugin within a common event, but I just seem to get the weirdest results in searches...
So far, I'm testing it by just scrunching all the code onto single lines and executing them with the [Script] button in a common event, but that's just not very clean and really, REALLY makes for a headache if I want to edit it later :p
I know this has to be the dumbest question ever asked on here, but I just can't seem to find how to call up a plugin I've written within RPG Maker MV that isn't tied to a predetermined keypress, a movement function, window interaction, or other premade engine code. Just want to call it when a common event is triggered.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,660
First Language
Czech
Primarily Uses
RMMV
If you want to call it when a common event is triggered, perhaps you can alias a function that deals with common event activation. If there are any that is xD

Btw. It's not the dumbest question ever, I can assure you that I have seen dumber on this forum.
 

Philsco

Flipped Out RPG2Knet.com vet
Veteran
Joined
Apr 5, 2015
Messages
41
Reaction score
9
First Language
English
Primarily Uses
lol well that's a relief then!
And I'll just have to keep searching for a way to make this work, then. I want it to activate within common event 1, preferably if there was a script call I could use, like, "$gameSomething.callPlugin["MyRangedCheck"]" or some craziness like that which I could nest within an event to act as a trigger. Or...y'know, something :p
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,660
First Language
Czech
Primarily Uses
RMMV
Well, you can use Plugin command to act as a trigger :D Use plugins that have plug-in commands as study material for your own ones :)
 

Philsco

Flipped Out RPG2Knet.com vet
Veteran
Joined
Apr 5, 2015
Messages
41
Reaction score
9
First Language
English
Primarily Uses
That's a good idea. Do you have any you could recommend to look at? The ones I've been looking at all are based off of aliasing the move, button press, or window interaction calls, but not that have any script calls to a function. Not sure of what to look for there >_<
Oof, I almost miss the days of pure-eventing in rm2k/rm2k3/2k3e lol
 

Philsco

Flipped Out RPG2Knet.com vet
Veteran
Joined
Apr 5, 2015
Messages
41
Reaction score
9
First Language
English
Primarily Uses
Got it figured out!
Thanks to Pivoo for the answer.
Just had it poorly scoped, didn't understand I could go above the initial function scoping to make it something I could call
It's now evolved to this:

Code:
/*:
* @plugindesc Mad's Ranged Attack
*
* @author Philsco
*
* @help
* This will enable the use of interacting with events that contain the
* <enemy> meta tag (just put <enemy> in the "Note" field of an event on the map)
* Then, call based on the weapon type to be used in a Script event call (button in the editor)
* MAD.hitTestPistol(atkDmg, atkAcc, atkRng, atkPen, atkBld);
*/

var MAD = MAD || {};

(function () {

    // Find Player (x,y) and facing dir, and initiate check values
    // var parameters = PluginManager.parameters('FNC_Ranged_Attack'); for future use

    // Melee hit test
    MAD.hitTestMelee  = function(atkDmg, atkAcc, atkRng, atkPen, atkBld) {
        var _startX = $gamePlayer.x;
        var _startY = $gamePlayer.y;
        var _startDir = $gamePlayer.direction();
        var _checkX = _startX;
        var _checkY = _startY;
        var _attack_range = atkRng;
        var _rangeChecked = 0;

        /* Check coordinates in an area ahead of Player (x,y)
        and see if there is an event in that square
        Then check for which note tag they have set and
        run the appropriate function to handle damage for enemies or
        facing direction / event removal for destructible objects
         */
        for (_rangeChecked = 0; _rangeChecked < _attack_range; _rangeChecked++) {
            if (_startDir == 8) {
                _checkY--;
            } else if (_startDir == 2) {
                _checkY++;
            } else if (_startDir == 6) {
                _checkX++;
            } else if (_startDir == 4) {
                _checkX--;
            }
            if ($gameMap.eventIdXy(_checkX, _checkY) != 0) {
                var _eventIdFound = $gameMap.eventIdXy(_checkX, _checkY);
                if ($dataMap.events[_eventIdFound].meta.enemy) {
                    //$gameMessage.add("Check x/y = (" + _checkX + "," + _checkY + ")  Player x/y = (" + $gamePlayer.x + "," + $gamePlayer.y + ")");
                    $gameMessage.add("Hit event number " + _eventIdFound);
                }
            }
        }
    }
    
    // Pistol hit test
    MAD.hitTestPistol  = function(atkDmg, atkAcc, atkRng, atkPen, atKBld) {
        var _startX = $gamePlayer.x;
        var _startY = $gamePlayer.y;
        var _startDir = $gamePlayer.direction();
        var _checkX = _startX;
        var _checkY = _startY;
        var _attack_range = atkRng;
        var _rangeChecked = 0;

        for (_rangeChecked = 0; _rangeChecked < _attack_range; _rangeChecked++) {
            if (_startDir == 8) {
                _checkY--;
            } else if (_startDir == 2) {
                _checkY++;
            } else if (_startDir == 6) {
                _checkX++;
            } else if (_startDir == 4) {
                _checkX--;
            }
            if ($gameMap.eventIdXy(_checkX, _checkY) != 0) {
                var _eventIdFound = $gameMap.eventIdXy(_checkX, _checkY);
                if ($dataMap.events[_eventIdFound].meta.enemy) {
                    $gameMessage.add("Hit event number " + _eventIdFound);
                }
            }
        }
    }
    
    // Shotgun hit test
    MAD.hitTestShotgun  = function(atkDmg, atkAcc, atkRng, atkPen, atKBld) {
        var _startX = $gamePlayer.x;
        var _startY = $gamePlayer.y;
        var _startDir = $gamePlayer.direction();
        var _checkX = _startX;
        var _checkY = _startY;
        var _attack_range = atkRng;
        var _rangeChecked = 0;

        for (_rangeChecked = 0; _rangeChecked < _attack_range; _rangeChecked++) {
            if (_startDir == 8) {
                _checkY--;
            } else if (_startDir == 2) {
                _checkY++;
            } else if (_startDir == 6) {
                _checkX++;
            } else if (_startDir == 4) {
                _checkX--;
            }
            if ($gameMap.eventIdXy(_checkX, _checkY) != 0) {
                var _eventIdFound = $gameMap.eventIdXy(_checkX, _checkY);
                if ($dataMap.events[_eventIdFound].meta.enemy) {
                    $gameMessage.add("Hit event number " + _eventIdFound);
                }
            }
        }
    }
    
    // Rifle hit test
    MAD.hitTestRifle  = function(atkDmg, atkAcc, atkRng, atkPen, atKBld) {
        var _startX = $gamePlayer.x;
        var _startY = $gamePlayer.y;
        var _startDir = $gamePlayer.direction();
        var _checkX = _startX;
        var _checkY = _startY;
        var _attack_range = atkRng;
        var _rangeChecked = 0;

       for (_rangeChecked = 0; _rangeChecked < _attack_range; _rangeChecked++) {
            if (_startDir == 8) {
                _checkY--;
            } else if (_startDir == 2) {
                _checkY++;
            } else if (_startDir == 6) {
                _checkX++;
            } else if (_startDir == 4) {
                _checkX--;
            }
            if ($gameMap.eventIdXy(_checkX, _checkY) != 0) {
                var _eventIdFound = $gameMap.eventIdXy(_checkX, _checkY);
                if ($dataMap.events[_eventIdFound].meta.enemy) {
                    $gameMessage.add("Hit event number " + _eventIdFound);
                }
            }
        }
    }
    
    // Machine Gun hit test
    MAD.hitTestMG  = function(atkDmg, atkAcc, atkRng, atkPen, atKBld) {
        var _startX = $gamePlayer.x;
        var _startY = $gamePlayer.y;
        var _startDir = $gamePlayer.direction();
        var _checkX = _startX;
        var _checkY = _startY;
        var _attack_range = atkRng;
        var _rangeChecked = 0;

        for (_rangeChecked = 0; _rangeChecked < _attack_range; _rangeChecked++) {
            if (_startDir == 8) {
                _checkY--;
            } else if (_startDir == 2) {
                _checkY++;
            } else if (_startDir == 6) {
                _checkX++;
            } else if (_startDir == 4) {
                _checkX--;
            }
            if ($gameMap.eventIdXy(_checkX, _checkY) != 0) {
                var _eventIdFound = $gameMap.eventIdXy(_checkX, _checkY);
                if ($dataMap.events[_eventIdFound].meta.enemy) {
                    $gameMessage.add("Hit event number " + _eventIdFound);
                }
            }
        }
    }
    
    // Grenade Launcher hit test
    MAD.hitTestGL  = function(atkDmg, atkAcc, atkRng, atkAoE, atKBld) {
        var _startX = $gamePlayer.x;
        var _startY = $gamePlayer.y;
        var _startDir = $gamePlayer.direction();
        var _checkX = _startX;
        var _checkY = _startY;
        var _attack_range = atkRng;
        var _rangeChecked = 0;

        for (_rangeChecked = 0; _rangeChecked < _attack_range; _rangeChecked++) {
            if (_startDir == 8) {
                _checkY--;
            } else if (_startDir == 2) {
                _checkY++;
            } else if (_startDir == 6) {
                _checkX++;
            } else if (_startDir == 4) {
                _checkX--;
            }
            if ($gameMap.eventIdXy(_checkX, _checkY) != 0) {
                var _eventIdFound = $gameMap.eventIdXy(_checkX, _checkY);
                if ($dataMap.events[_eventIdFound].meta.enemy) {
                    $gameMessage.add("Hit event number " + _eventIdFound);
                }
            }
        }
    }
    
    
    // Rocket Launcher hit test
    MAD.hitTestRL  = function(atkDmg, atkAcc, atkRng, atkAoE, atKBld) {
        var _startX = $gamePlayer.x;
        var _startY = $gamePlayer.y;
        var _startDir = $gamePlayer.direction();
        var _checkX = _startX;
        var _checkY = _startY;
        var _attack_range = atkRng;
        var _rangeChecked = 0;

        for (_rangeChecked = 0; _rangeChecked < _attack_range; _rangeChecked++) {
            if (_startDir == 8) {
                _checkY--;
            } else if (_startDir == 2) {
                _checkY++;
            } else if (_startDir == 6) {
                _checkX++;
            } else if (_startDir == 4) {
                _checkX--;
            }
            if ($gameMap.eventIdXy(_checkX, _checkY) != 0) {
                var _eventIdFound = $gameMap.eventIdXy(_checkX, _checkY);
                if ($dataMap.events[_eventIdFound].meta.enemy) {
                    $gameMessage.add("Hit event number " + _eventIdFound);
                }
            }
        }
    }
    
    // Flamethrower hit test
    MAD.hitTestFT  = function(atkDmg, atkAcc, atkRng, atkAoE, atKBld) {
        var _startX = $gamePlayer.x;
        var _startY = $gamePlayer.y;
        var _startDir = $gamePlayer.direction();
        var _checkX = _startX;
        var _checkY = _startY;
        var _attack_range = atkRng;
        var _rangeChecked = 0;

        for (_rangeChecked = 0; _rangeChecked < _attack_range; _rangeChecked++) {
            if (_startDir == 8) {
                _checkY--;
            } else if (_startDir == 2) {
                _checkY++;
            } else if (_startDir == 6) {
                _checkX++;
            } else if (_startDir == 4) {
                _checkX--;
            }
            if ($gameMap.eventIdXy(_checkX, _checkY) != 0) {
                var _eventIdFound = $gameMap.eventIdXy(_checkX, _checkY);
                if ($dataMap.events[_eventIdFound].meta.enemy) {
                    $gameMessage.add("Hit event number " + _eventIdFound);
                }
            }
        }
    }
    
    
})();

// Thanks to Pivoo and waynee95 for helping me implement MAD.hitTest??();
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,441
Reaction score
2,553
First Language
English
Primarily Uses
RMMZ
As an aside you may not have been aware of, the console you can open in-game with F8 allows you to enter and execute any JavaScript code you want, so you can test things without having to put them in a plugin first.
 

Latest Threads

Latest Posts

Latest Profile Posts

Zeno Remake's English Release, & A Text Editor That Lets Us Type Anywhere | RPG Maker News #76

Make a Game in RMMZ Streams are going to remain in hiatus this week. Too much to do! 4 things will be announced on Monday though! Look forward to that.
Typed a long-ish reply to a post... forgot to actually HIT the post button, and moved to a different page.... finally noticed, don't remember what all I had typed and don't feel like trying to re-type it all.... smh....
Their tactics are evolving. They've learned to call for help when cornered. Never trust a mammal!
Good morning all. I still have a post up on video editing for cinematic trailers. Please make sure to check that out and give me a message as its still active in offers.

Forum statistics

Threads
112,371
Messages
1,067,850
Members
146,020
Latest member
DSBwizzardMakesGame
Top