detect collision from event on event.

Monkey BizNiz

Veteran
Veteran
Joined
Apr 22, 2017
Messages
229
Reaction score
29
First Language
Not English
Primarily Uses
RMMV
Hey guys,

I currently have a problem with a jump system, where it is possible for events to fall on eachother.

Basically what i have done to check whether the player is on the same coordinates as an event is
Code:
!$gamePlayer.canPass($gamePlayer.x, $gamePlayer.y)
So that whenever the player is on the same location as an event, or a wall, the game will recognize that and push the player off.
But ive also wanted to do that with an event on event, and ive tried
Code:
!$gameMap.event(this._eventId).canPass($gameMap.event(this._eventId).x, $gameMap.event(this._eventId).y)
But in this scenario the game seemingly also counts the event the script is run from, so no matter if the event is sitting on another event or not, its always active.
My question is: is there a way to still have the active event detect whether or not theyre on the same coordinates as another event, without the game counting the active event as an obstruction?

Thanks in advance
 

dbchest

Beast Master
Veteran
Joined
Oct 1, 2013
Messages
434
Reaction score
306
First Language
English
Primarily Uses
RMMV
Use this instead of canPass:

Code:
$gameMap.event(this._eventId).isCollidedWithEvents();
 

Monkey BizNiz

Veteran
Veteran
Joined
Apr 22, 2017
Messages
229
Reaction score
29
First Language
Not English
Primarily Uses
RMMV
@dbchest
hmmm i tried it but for me it doesnt seem to respond to being on the same tile as other events.
I tried it like:
Code:
$gameMap.event(this._eventId).isCollidedWithEvents();
and
Code:
$gameMap.event(this._eventId).isCollidedWithEvents($gameMap.event(this._eventId).x, $gameMap.event(this._eventId).y);
Basically this was the test event I used:
◆If:Button
is pressed down
◆Set Movement Route:This Event (Skip, Wait)
:Set Movement Route:◇Jump:+1, +0

:End​
◆If:Button
is pressed down
◆Set Movement Route:This Event (Skip, Wait)
:Set Movement Route:◇Jump:-1, +0

:End
◆If:Script:$gameMap.event(this._eventId).isCollidedWithEvents() === false
◆Play SE:Blow2 (90, 150, 0)

:End
 

Monkey BizNiz

Veteran
Veteran
Joined
Apr 22, 2017
Messages
229
Reaction score
29
First Language
Not English
Primarily Uses
RMMV
Does really no one know the right script call? Or if it even exists at all... I mean there must be a proper way for events to check whether theyre colliding with another event or not right?
 

Monkey BizNiz

Veteran
Veteran
Joined
Apr 22, 2017
Messages
229
Reaction score
29
First Language
Not English
Primarily Uses
RMMV
Not sure what exactly the rules are for doubleposting to keep an unanswered question alive. But here goes nothing:mrsatan:
 

HexMozart88

The Master of Random Garbage
Veteran
Joined
May 15, 2016
Messages
1,879
Reaction score
3,349
First Language
English
Primarily Uses
RMVXA
Hmm, if memory serves, what you'd need to do to check that would be to get the X and Y of both events into variables, and subtract them, putting the value into another variable. Then you check if that variable is equal to 0, and put whatever you want to happen in that conditional branch. So basically:
Var. 1 = Event 1 X
Var. 2 = Event 1 Y
Var. 3 = Event 2 X
Var. 4 = Event 2 Y
Var. 5 = Var. 3 - Var. 1
Var. 6 = Var. 4 - Var. 2
If: Var. 5 == 0
[insert event here]
Branch End
If: Var. 6 == 0
[insert event here]
Branch End

Subtracting the variables would have to be done in two different variable operations, however, because you cannot do two operations at once using events. So it would look more like:
Var. 5 = Var. 3
Var. 5 -= Var. 1
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
You would have to run that for every event.

If there is no "valid" reason for two events occupying the same tile, you would simply need to check how many events are on the tile occupied by the current event. If more than one, the other one doesn't belong there, and you can "push" it off by whatever means you want. You haven't elaborated on how you intend to do that, so I will just give you something that will give you the other event's id, and you can do with it as you wish.

Put the following into a script call, and set the variable id to whatever variable you want the other event's id set to (I'll use 8, so change 8 to whatever you want to use).

Code:
var otherEventsOnThisTile = $gameMap.eventsXy(this.character(0).x, this.character(0).y).filter(function(e) { return e !== this.character() });
if (otherEventsOnThisTile.length > 0) {
  $gameVariables.setValue(8, otherEventsOnThisTile[0].eventId());
} else {
  $gameVariables.setValue(8, 0);
}
If the variable is 0, there is no other event on the same tile. If the variable is > 0, it contains the id of the other event on the same tile.

This is going to be difficult, though, if you want to put the same code on more than one event. In that case, you could have several events updating the same variable, so another event could change it before the first event is done using it. You might need a single variable for each event, or you might need to put your "push out the way" command into the script as well so you can avoid using variables.
 

Monkey BizNiz

Veteran
Veteran
Joined
Apr 22, 2017
Messages
229
Reaction score
29
First Language
Not English
Primarily Uses
RMMV
Sorry for the late reply guys, i was a little busy so i couldnt test out what solutions you guys have shown.
@HexMozart88
Wouldnt a more efficient way be; to just do: $gameVariables.value(1) === $gameVariables.value(3) && $gameVariables.value(2) === $gameVariables.value(4)
else:
Unless im reading your comment wrong. But in that case id have to clutter a huge part of the variables to make up for all the events on a map, and im trying to keep it as efficient as possible. :)

@Shaz
oh boy . . . I dont think my rpg maker knowledge is good enough to pull off what you explained yet.
What i basically did was replace 8 with 56(because that was the event ID it was happening in), and it gives out an error, which no doubt is me doing wrong what you explained:

◆Script:var otherEventsOnThisTile = $gameMap.eventsXy(this.character(0).x, this.character(0).y).filter(function(e) { return e !== this.character() });
:Script:if (otherEventsOnThisTile.length > 0) {
:Script: $gameVariables.setValue(56, otherEventsOnThisTile[0].eventId());
:Script:} else {
:Script: $gameVariables.setValue(56, 0);
:Script:}

Maybe you could help me by answering some questions I have about your code too:

1) ''var otherEventsOnThisTile = $gameMap.eventsXy(this.character(0).x, this.character(0).y).filter(function(e) { return e !== this.character() });'' is this you giving ''$gameMap.eventsXy(this.character(0).x, this.character(0).y).filter(function(e) { return e !== this.character() });'' a reference name so you can call on it any time with "otherEventsOnThisTile"?

2) what do these "commands?" mean and do: ''gameMap.eventsXy()'', ''this.character(0).x,y'', "filter(function(e) { return e !=="

3) how would i actually use this code in a situation where - for example: event ID 40, and event ID 50 would end up on the same tile. Also for clarification - my method was to let the unwanted event "jump" one tile away from the other event.
 
Last edited:

HexMozart88

The Master of Random Garbage
Veteran
Joined
May 15, 2016
Messages
1,879
Reaction score
3,349
First Language
English
Primarily Uses
RMVXA
@Monkey BizNiz It probably would be a more efficient way, but I use Ace more often than MV, so I'm not very accustomed to the script calls. XD
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
Can you please show a screenshot of the code inserted into your event, and state what the error is that you get when you run it? If possible, hit F8 to pull up the developer tools and get a screenshot of the console tab.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
Try replacing the first line with this:

Code:
var otherEventsOnThisTile = $gameMap.eventsXy(this.character(0).x, this.character(0).y).filter(function(e) { return e !== this.character(0) }.bind(this));
If that still gives you an error, I'll have a closer look later today.
 
Last edited:

Monkey BizNiz

Veteran
Veteran
Joined
Apr 22, 2017
Messages
229
Reaction score
29
First Language
Not English
Primarily Uses
RMMV
@Shaz
It doesnt give an error anymore; but im not sure how to actually make use of script conditional branches. Could you explain how i would actually take this action into effect?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
You don't. That script is setting a variable to the id of the other event on that tile. You just use the variable in a regular conditional branch. If it's 0, there's no other event on the tile. If it's something other than 0, that's the id of the event.
 

Monkey BizNiz

Veteran
Veteran
Joined
Apr 22, 2017
Messages
229
Reaction score
29
First Language
Not English
Primarily Uses
RMMV
My problem was that i didnt know what variable i had to use - but I misread, and had forgotten that you already stated earlier that it was the variable that I had to use in the code.
Anyway. It seems to work, and i know how to use it now. Thanks!:D
 

GamesOfShadows

♥ Gamer/Games ♥
Veteran
Joined
Jan 31, 2017
Messages
40
Reaction score
19
First Language
German
Primarily Uses
RMMV
After a long search, I finally came across this thread. Thank you very much @Shaz that you have shared that script. That helps me alot. I have many events that query a collision with a particular event. Thus, the game would be unplayable for bad PCs, but this has saved my day / project! :D

I edited the script a bit to trigger a Self-Switch. - Unfortunately, that does not work with "YEP - Self Switches & Variables".
If someone need that:

Code:
var mapid = $gameMap._mapId;
var eventid = this._eventId;
var key = [mapid, eventid, 'A'];

var otherEventsOnThisTile = $gameMap.eventsXy(this.character(0).x, this.character(0).y).filter(function(e) { return e !== this.character(0) }.bind(this));
if (otherEventsOnThisTile.length > 0) {
$gameSelfSwitches.setValue(key, true);
} else {
$gameSelfSwitches.setValue(key, false);
}
You can replace 'A' with 'B'; 'C' or 'D'. :)


Shaz do you want credits? If yes how should it looks like?

PS: Sorry for my bad english :)
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
I do not want credit for that little snippet. But thank you for asking.
 

GamesOfShadows

♥ Gamer/Games ♥
Veteran
Joined
Jan 31, 2017
Messages
40
Reaction score
19
First Language
German
Primarily Uses
RMMV
Code Edit #2 (if someone else could need this):

Self-Switch "A" is now only triggered if the other event is named "Change me to Event name".

So you can limit the whole thing nicely. Thanks again to Shaz. ^^



Code:
var otherEventsOnThisTile = $gameMap.eventsXy(this.character(0).x, this.character(0).y).filter(function(e) { return e !== this.character(0) }.bind(this));
var mapid = $gameMap._mapId;
var eventid = this._eventId;
var key = [mapid, eventid, 'A'];
if (otherEventsOnThisTile.length > 0 && otherEventsOnThisTile[0].event().name == "Change me to Event name") {
  $gameSelfSwitches.setValue(key, true);
} else {
  $gameSelfSwitches.setValue(key, false);
}
 

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

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,050
Messages
1,018,548
Members
137,835
Latest member
yetisteven
Top