[SOLVED] Detecting Region Tiles for Conditional/Common Events?

Status
Not open for further replies.

Riazey

Master of None
Veteran
Joined
Feb 27, 2014
Messages
51
Reaction score
24
First Language
English
Primarily Uses
RMMV
TE QUESTION

Hmmm... is it possible to check if the tile in front of the player is in a specific region? I want to basically make a check for if the tile in front of the actor is a specific region when using conditions with script or plugin calls for a conditional branch. Or more specifically I want to an action button on the tile ahead which uses a tool (already have) but for it to only work if that tile is within a specific region (this is the part I dont qvq).

I was hoping to be able to accomplish that with some more well-known plugins but... qvq I am just not good enough with coding or really understanding a lot of the code yet to sift through it, so I'm not sure if it can be used that way even with the knowledge!

Alternatively, if there is no way to do this do you think it would be possible for someone to script, or are regions just super meh about these kinds of things and I should go a different route?


_____________________________________________


PLUGINS

I have Yanfly's region events, and a few other of their lovely scripts (i.e. also listed below) if they are helpful, plus galv's tools installed (using tools from this script triggers a common event) I just need a way for that common event to check if the tile it is about to be used on (one tile ahead of the character) is within a specified region.


Others that might help?


_____________________________________________



CURRENT WORKAROUND


The road I am heading down right now is using a region that activates a switch allowing the tool to be used, and outlining that region in event tiles that when the tools are used on it has no effect or nullifies the effect + when they step on it deactivates the tool. It's really messy with event tiles all around it you can't place other events on, feels less fluid than the above working would, and is basically a ton of events if used on other applications. @-@


I also thought of using this method but I am not 100% sure how to. I would need to check what direction the player is facing then check the tile 1 ahead of that direction, if it's a region tile then go forth young tool, but if it isn't it just wouldn't do anything! :)
If you have an example of how I could put that in well even as a last case scenerio I would still be quite happy!


_____________________________________________


THANKS AND THANKS AGAIN!
For taking the time to read through my ramblings aaahh- I was very nervous to ask about this (oops!)
but having a solution or alternative perhaps to help with this would be GREATLY appreciated and I'll luv you forever. qvq
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,766
Reaction score
12,202
First Language
English
Primarily Uses
RMMV
Did you actually reduce the font size in your post? For those of us with not-so-good eyesight, please don't do that.

In the script portion of a conditional branch, you can put this:

Code:
$gameMap.regionId($gameMap.roundXWithDirection($gamePlayer.x, $gamePlayer.direction()), $gameMap.roundYWithDirection($gamePlayer.y, $gamePlayer.direction())) === 15
replacing 15 with whatever region id you're interested in - without leading zeros.
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
702
Reaction score
233
First Language
Javascript
Primarily Uses
RMMV
In the script portion of a conditional branch, you can put this:
Code:
$gameMap.regionId($gameMap.roundXWithDirection($gamePlayer.x, $gamePlayer.direction()), $gameMap.roundYWithDirection($gamePlayer.y, $gamePlayer.direction())) === 15
Is it really that simple... jeesh well my plugin works too but shaz seems to have a simple solution also...

ahh so that's what roundXWithDirection & roundYWithDirection do... (like the name even implies... jeesh I feel dumb, i did it manually lol)
Code:
    Game_CharacterBase.prototype.regionInFront = function() {
        switch (this._direction) {
            case 1:  d = {x: this.x-1, y: this.y+1}; break;
            case 2:  d = {x: this.x  , y: this.y+1}; break;
            case 3:  d = {x: this.x+1, y: this.y+1}; break;
            case 4:  d = {x: this.x-1, y: this.y  }; break;
            case 6:  d = {x: this.x+1, y: this.y  }; break;
            case 7:  d = {x: this.x-1, y: this.y-1}; break;      
            case 8:  d = {x: this.x  , y: this.y-1}; break;
            case 9:  d = {x: this.x+1, y: this.y-1}; break;  
            default: d = {x: this.x  , y: this.y  }
        }      
        return $gameMap.regionId(d.x, d.y);
    };
Edit:
Using my plugin you can just simply use
Code:
$gamePlayer.regionInFront() === 15
1582948291136.png
 
Last edited:

Riazey

Master of None
Veteran
Joined
Feb 27, 2014
Messages
51
Reaction score
24
First Language
English
Primarily Uses
RMMV
Did you actually reduce the font size in your post? For those of us with not-so-good eyesight, please don't do that.

In the script portion of a conditional branch, you can put this:

Code:
$gameMap.regionId($gameMap.roundXWithDirection($gamePlayer.x, $gamePlayer.direction()), $gameMap.roundYWithDirection($gamePlayer.y, $gamePlayer.direction())) === 15
replacing 15 with whatever region id you're interested in - without leading zeros.
Ah oops I am used to 12px font being the norm in programs like google docs/books so I totally forgot to take bad eyesight take that into account! Large font messes with me aesthetically so I automatically changed it without thinking, especially on a 2k monitor oof- qvq I will keep that in mind for my next post though thanks!

In regards to the piece of script you are a LIFESAVER, I looked everywhere I could think of but hit a dead end!

Is there a particular reason people tend to not use them for say tilling soil? Aka is there anything to be wary of while using it?

I will try that out when I get back to work on it tomorrow I didn't expect to get a reply so incredibly fast so I went to bed haha!
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
702
Reaction score
233
First Language
Javascript
Primarily Uses
RMMV
Ah oops I am used to 12px font being the norm in programs like google docs/books so I totally forgot to take bad eyesight take that into account! Large font messes with me aesthetically so I automatically changed it without thinking, especially on a 2k monitor oof- qvq I will keep that in mind for my next post though thanks!

In regards to the piece of script you are a LIFESAVER, I looked everywhere I could think of but hit a dead end!

Is there a particular reason people tend to not use them for say tilling soil? Aka is there anything to be wary of while using it?

I will try that out when I get back to work on it tomorrow I didn't expect to get a reply so incredibly fast so I went to bed haha!
Using my plugin you can just simply use
Code:
$gamePlayer.regionInFront() === 15
...in case you want to use a simplier script call... (I can also update if needed)
 

Riazey

Master of None
Veteran
Joined
Feb 27, 2014
Messages
51
Reaction score
24
First Language
English
Primarily Uses
RMMV
Using my plugin you can just simply use
Code:
$gamePlayer.regionInFront() === 15
...in case you want to use a simplier script call... (I can also update if needed)


Haha watching your realization and edits happen in realtime made my day! XD

Honestly tho making a simple plugin command or script for a plugin for people using this region check (ezpz for the masses) would make a whole new level of eventing possible.

Easy treasure detectors, general item usage for specific spots (like using a whip/etc standing on a specific region to cross a gap), new puzzle elements and using it for farming games is a HUGE plus, because they won't be restricted by using a single tile with a seed event on they can set people to be able to plant/hoe in a whole region!

It's a good thing shaz is all-knowing and we have you to take the initiative for a plugin! ☆0☆

Did you happen to be able to update it with the script call shaz gave? I am excited to wake up tomorrow n try these~ I really want to get up now but my fiance might throttle me!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,766
Reaction score
12,202
First Language
English
Primarily Uses
RMMV
I actually thought about writing a plugin, but you specifically asked for a script call that could be used with a conditional branch.

The plugin solution is more elegant, and tbh if I needed to do this, I'd go that way.

@ct_bolt - $gameMap also has an xWithDirection and yWithDirection function, and I'm not entirely sure why the 'round' versions exist, but they are the functions used when characters are about to move, to see if they can step onto those tiles. It may have something to do with scrolling maps, but I haven't been curious enough to dig any deeper.
 

Riazey

Master of None
Veteran
Joined
Feb 27, 2014
Messages
51
Reaction score
24
First Language
English
Primarily Uses
RMMV
I actually thought about writing a plugin, but you specifically asked for a script call that could be used with a conditional branch.

The plugin solution is more elegant, and tbh if I needed to do this, I'd go that way.

Yeah personally I was kind of preferring the script simply because I was worried about plugin compatibility (the bane of plugin existence) because I wasn't sure how someone might code it or what they may use, and I would understand it a lot better or understand errors it could cause better that way~

But that was before seeing the awesome answers I got, if it is your recommendation to use the plugin over the script as well, I trust that opinion a lot more than the scarring fear of updates (ahaha) in future threads! <3 You guys have shown me the way!

I am overjoyed with both of you for working with me on this, couldn't ask for a better community.
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,766
Reaction score
12,202
First Language
English
Primarily Uses
RMMV
That plugin shouldn't have any compatibility issues, because it's a completely new function and isn't altering any of the existing behaviour.
 

Riazey

Master of None
Veteran
Joined
Feb 27, 2014
Messages
51
Reaction score
24
First Language
English
Primarily Uses
RMMV
That plugin shouldn't have any compatibility issues, because it's a completely new function and isn't altering any of the existing behaviour.
Yaay yes that is exactly what I was hoping when I saw ct's plugin! At the time of posting originally I didn't know it was apparently going to be so light n great a feature!

Using my plugin you can just simply use
Code:
$gamePlayer.regionInFront() === 15
...in case you want to use a simplier script call... (I can also update if needed)
Speaking of I just thought and if it's not too hard, do you two think it would be possible to add another feature into the same plugin that checks the region under your current player position with a similar script? (If I was being greedy I also really want the script too in case I needed to troubleshoot in the future). That would make it neat and both in the one plugin, but also a double the flexibility!

Or do you think that would have compatibility issues with the yanfly one? I would rather use yours and remove the yanfly one if it does <3 cuz this plug is more flexible for me >v<! But if you think it might cause issues elewhere then these current fixes are already my hero!

Gosh sorry for my major js noobism...
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,766
Reaction score
12,202
First Language
English
Primarily Uses
RMMV
There is already a way to check the region under the current player position.

You can use Control Variable to set one variable to the player's X position, then again to set another to the player's Y position, then use Get Location Info (on the third tab of the event commands) to get the region id based on the X and Y variable into yet another variable, and then use that third variable in a conditional branch.

Or as a script, it's $gamePlayer.regionId()

So in your conditional branch,
Code:
Script: $gamePlayer.regionId() === 15
 

Riazey

Master of None
Veteran
Joined
Feb 27, 2014
Messages
51
Reaction score
24
First Language
English
Primarily Uses
RMMV
I got up without waking my fiance (somehow at 1am) to try these and they work wonderfully with what I wanted to use them for qvq Life is great. Yall are great. I feel both enlightened and powerfully motivated. Even with my level of programming I feel like I understand a bit more and my question is sorted out which is all I could ask for~
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,766
Reaction score
12,202
First Language
English
Primarily Uses
RMMV
Just report your first post and let the mods know your question is solved, and they'll close the thread for you :)
 

Riazey

Master of None
Veteran
Joined
Feb 27, 2014
Messages
51
Reaction score
24
First Language
English
Primarily Uses
RMMV
Just report your first post and let the mods know your question is solved, and they'll close the thread for you :)
Did just that! Thanks!
 

Kes

Global Moderators
Global Mod
Joined
Aug 3, 2012
Messages
21,763
Reaction score
10,984
First Language
English
Primarily Uses
RMVXA

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

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.
Stream will be live shortly with a guest stream! Tonight, a new guest joins~ Feel free to drop by!
Finally told my boss I need a day off. Tomorrow will be my first in 23 days.
Kind of a goofy question but has the pandemic inspired you in any way?

Forum statistics

Threads
95,421
Messages
929,039
Members
125,649
Latest member
Laser_Kirin
Top