Comparing player location with current event

mike7

Villager
Member
Joined
Oct 18, 2015
Messages
16
Reaction score
2
First Language
English
Primarily Uses
I'm trying to compare the player's position with the position of an event to determine when a player is within 2 tiles of the event horizontally and 3 tiles vertically north of the event. I'm wanting this to work for the current event that the code is placed within so it works with each event of this type, but I can't figure out the correct java variables to use for the current event position.


An example of this would be (according to my limited java script knowledge):


if (($gamePlayer._x <= ($currentEvent._x + 2)) && ($gamePlayer._x >= ($currentEvent._x - 2)) && ($gamePlayer._y <= ($currentEvent._y + 3)) && ($gamePlayer._y >= $currentEvent._y))


but I know that $currentEvent isn't correct.


Does any one know how to access the position of the current event to use in a condition that's compared with the player's position?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,614
Reaction score
13,208
First Language
English
Primarily Uses
RMMV
north is currentevent.y - 3, not + 3.  0 is at the top, not the bottom.


Where are you putting this - as a conditional branch within an event?  Be aware that if you're doing this and have the event set to parallel process, you could introduce some lag to your game - especially if you have several events doing it.


Is the event stationary or moving around?  If it's stationary, you can just use regions to draw over the appropriate tiles, and then check if $gamePlayer.regionId() === whatever the region number is.


However, if the event is moving around and you are using a conditional branch, try this:

Code:
p = $gamePlayer; e = character(0);  Math.abs(e.x - p.x) <= 2 && p.y <= e.y && p.y >= e.y - 3
 

mike7

Villager
Member
Joined
Oct 18, 2015
Messages
16
Reaction score
2
First Language
English
Primarily Uses
Thanks Shaz,


Yeah, I should have known that negative values are north as they are north in most image editors.


I am using it in an event condition for trees in my game. I could have used trees as stationary tiles, but with my characters and trees being much larger than the defaults, I need events with priorities set to "Same as character" so that the player appears in front of and behind the trees depending on the location of the player.


I was setting these events to parallel and in checking the region ID using the GALV_MapAnimEffects plugin, I had the trees change to an image that's partially transparent when the character is under them so that you can see the character through the leaves. I didn't know about using "$gamePlayer.regionId() ===", but I can use that too to do the same thing.


The problem is that I want the transparency to affect individual trees depending on when the character is under them and not all trees at the same time. I could have multiple region ids set for individual trees, but that would use up a lot of the region ids and it gets complicated when multiple trees are close together.


With the trees being stationary, I can use your suggestion of the following:

Code:
p = $gamePlayer; e = character(0);  Math.abs(e.x - p.x) <= 2 && p.y <= e.y && p.y >= e.y - 3


but would "character(0)" be the exact phrase to use and does "0" represents the event ID? Is there any way of making it reference the current event of whatever event it is a part of?


Also is there any other way of doing this without making these tree events parallel processes? There are some areas of a map I'm working on that has 50+ trees and with all the trees added up on the map, I can imagine it could slow things down quite a bit.


Or is there a common event that I can create that changes the tree events on a screen to a parallel process and changes to another process when they're not on the screen so there aren't so many events running with a parallel process at the same time?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,614
Reaction score
13,208
First Language
English
Primarily Uses
RMMV
Game_Interpreter.prototype.character = function(param) {
if ($gameParty.inBattle()) {
return null;
} else if (param < 0) {
return $gamePlayer;
} else if (this.isOnCurrentMap()) {
return $gameMap.event(param > 0 ? param : this._eventId);
} else {
return null;
}
};


character(0) is this._eventId


This means you can copy & paste the event and not have to change the code to insert every event id.  Each event will only compare the player's position with its own position.


I would still look for another way.  If you have a few dozen trees and you're going to make each one a parallel process event, that is very likely going to make your game lag.


I would use a single region id to cover ALL areas where you want a tree to change opacity, and a single event set to parallel process that has a wait for a few frames, checks if the player is on the special region id, and if they are, find out which tree (there could be several), and set the events opacity for each one.  It would also need to check if there WAS a tree that was semi-transparent, and the player is no longer behind it, so sets it back to fully opaque.


The other thing you could do, which would remove events and conditions entirely, is to have two versions of the tree in the tileset.  One version would be fully opaque and would be below the player (you could use my terrain tag script in the development section so this tree's passage settings are ignored and it looks at what's underneath), and the other version would be semi transparent and would be drawn exactly over the first version.  This would make it look like there's a fully opaque tree on that spot, but when the player walks behind it, the opaque layer is below the player, and the semi transparent layer is above the player.  It would LOOK like the tree is becoming semi-transparent when the player walks behind it, but really nothing at all is happening.  This could be a very good option if your trees are not overlapping, or you don't have other things you want to put on either of the top layers - takes advantage of MV's two-top-layer feature.


If you don't follow what I mean, but you think it could be useful if you can get it working, let me know (tag me in the post to make sure I see it), and I'll do up a quick demo for you.
 
Last edited by a moderator:

mike7

Villager
Member
Joined
Oct 18, 2015
Messages
16
Reaction score
2
First Language
English
Primarily Uses
The no event idea would be great, but my trees are 7x7 tiles large and they'll take up a huge amount of my tile space on my tile bitmaps if I have a solid and a transparent one too. I also want the full branch/leaves transparent to make a line of sight effect and not just the immediate portion of the image that's over the character so I think the first option where there's a single parallel process running, the region id to cover all areas, the conditions for each tree and the actions to flip the switches of the affected trees all from one event would be best.


Thanks for all of your insight.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

In other news, my new computer is now ordered, and I'll have it in my hot little hands by the end of the week! CAN'T WAIT!!!
I've said my cat's names in such a baby-talk manner over the years, Biggs is now Biggoro, Bella is now Bellllyyaah, and somehow.....somehow Tessa is Sessashan
Did a massive ****up in my code that would have caused the game to crash on most computers and almost released an update without noticing it.
I keep thinking today is Thursday.
And I look forward to the next preview thread coming this afternoon.
And then I realise it's not Thursday at all.
And then I get sad :(

Forum statistics

Threads
100,449
Messages
976,080
Members
132,082
Latest member
nwr
Top