Touch not triggering when same space occupied after jump?

werzaque

Canned Dinosaur
Regular
Joined
May 30, 2023
Messages
400
Reaction score
227
First Language
EN/JP/NL
Primarily Uses
RMMZ
Hi,

Sorry for the unintelligible title. I'm trying to make a battle trigger when a Goblin jumps you. In trying to achieve this I have an event with a Goblin sprite that triggers a battle upon event touch. The movement part is scripted, as below (yes this is all crammed into the single line field).

JavaScript:
const DivX = $gamePlayer.x - this.x;
const DivY = $gamePlayer.y - this.y;
if(Math.abs(DivX) + Math.abs(DivY) < 6){
this._waitCount = 59;
$gameTemp.requestBalloon(this,5);
this.jump(DivX,DivY);
this.setMoveSpeed(4);
} else {
this.moveRandom();this.setMoveSpeed(3);
}

It works very nicely in that the goblin jumps you when you are within range... and if you happen to run away it will resume its random routine... The only thing that doesn't work as intended is the trigger for the battle. Right after the goblin jumps (and the player is not moving away at the time of the jump), it will occupy the same space as the player. Funnily enough, the battle event will not trigger, and the goblin will just continue hopping in place.

Is there any way to have the battle trigger when the goblin successfully lands on the player? I've thought about having the goblin back-step and then moveStraight() to the player, but that's... slightly less aesthetically pleasing.

Any suggestions highly appreciated.
 

AquaEcho

Script Kitty
Regular
Joined
Sep 20, 2021
Messages
1,713
Reaction score
1,177
First Language
English
Primarily Uses
RMMV
I don't think event touch is triggered by the event touching the player, but rather the player touching the event?
Why not add an additional check to initiate battle if the goblin is in the same tile coordinates as the player?
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,226
Reaction score
9,186
First Language
English
Primarily Uses
RMMV
I don't think event touch is triggered by the event touching the player, but rather the player touching the event?
It is, that's the difference between Event Touch and Player Touch.

However, as far as I know, the triggers for touching are only checked after actual walking movement. The easiest solution would be what AquaEcho described, a few event commands to check whether the goblin is on top of or adjacent to the player after the jump.

If you want a plugin that makes jumping check all triggers, you could request that.
 

werzaque

Canned Dinosaur
Regular
Joined
May 30, 2023
Messages
400
Reaction score
227
First Language
EN/JP/NL
Primarily Uses
RMMZ
I don't think event touch is triggered by the event touching the player, but rather the player touching the event?
Tried both player touch and event touch as triggers. The latter works for "normal" symbol encounters in which the enemy sprite walks up to the player and makes contact.
Why not add an additional check to initiate battle if the goblin is in the same tile coordinates as the player?
Thanks, that would probably work but I've also got some branching depending on the outcome of the battle (win = goblin sprite runs away; escape = goblin sprite semi-transparent for five seconds, etc...). On second thought if I can just flip a self-switch when the event and the player occupy the same space?
 

AquaEcho

Script Kitty
Regular
Joined
Sep 20, 2021
Messages
1,713
Reaction score
1,177
First Language
English
Primarily Uses
RMMV
I don't see why you can't have both a conditional statement for initiating the battle and one for ending it.
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,226
Reaction score
9,186
First Language
English
Primarily Uses
RMMV
Thanks, that would probably work but I've also got some branching depending on the outcome of the battle (win = goblin sprite runs away; escape = goblin sprite semi-transparent for five seconds, etc...). On second thought if I can just flip a self-switch when the event and the player occupy the same space?
None of that would have to change. It just all goes inside of the conditional that checks whether the fight should start.
 

werzaque

Canned Dinosaur
Regular
Joined
May 30, 2023
Messages
400
Reaction score
227
First Language
EN/JP/NL
Primarily Uses
RMMZ
However, as far as I know, the triggers for touching are only checked after actual walking movement.
Ah, that would make sense, thanks. Now that I think of it that would also explain behavior of "move" events.

If you want a plugin that makes jumping check all triggers, you could request that.
I want that, yes. But maybe this is a good time to practice building my own... I see that jumping is specifically excluded, even. Interesting.

JavaScript:
Game_Event.prototype.checkEventTriggerTouch = function(x, y) {
    if (!$gameMap.isEventRunning()) {
        if (this._trigger === 2 && $gamePlayer.pos(x, y)) {
            if (!this.isJumping() && this.isNormalPriority()) {
                this.start();
            }
        }
    }
};
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,226
Reaction score
9,186
First Language
English
Primarily Uses
RMMV
The code you quoted is saying if a character is in the process of jumping it doesn't check triggers. You probably don't want to change that, because then it could potentially make all kinds of stuff go off as you jump over it.
 

werzaque

Canned Dinosaur
Regular
Joined
May 30, 2023
Messages
400
Reaction score
227
First Language
EN/JP/NL
Primarily Uses
RMMZ
Thanks!

Found the part about jumping and indeed there doesn't seem to be anything to make "jump" count as "having moved". Going to bed now and study some more after work tomorrow...
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
5,041
Reaction score
4,393
First Language
EN
Primarily Uses
RMMZ
Maybe (untested):
JavaScript:
/*:
 * @target MZ
 * @plugindesc Check Event Touch triggers when events complete a jump.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/158077/
 * @help Free to use and/or modify for any project, no credit required.
 */
void (alias => {
  Game_Event.prototype.updateJump = function() {
    alias.apply(this, arguments);   // do usual stuff
    if (
      this._jumpCount === 0 &&              // jump just ended
      $gamePlayer.canStartLocalEvents() &&  // player can start events
      this.isTriggerIn([2]) &&              // trigger is Event Touch
      $gamePlayer.pos(this.x, this.y)       // player is here
    )
      this.start();   // flag this event as "starting"
  };
})(Game_Event.prototype.updateJump);
 

werzaque

Canned Dinosaur
Regular
Joined
May 30, 2023
Messages
400
Reaction score
227
First Language
EN/JP/NL
Primarily Uses
RMMZ
Works like a charm! Absolutely wonderful! Thank you!

And also thanks for the comments in the code! Extremely helpful!
 

Latest Threads

Latest Posts

Latest Profile Posts

I’m so lucky! Simone got referred to a feline cardiologist and had I not called this morning the moment there was a cancellation the next opening would have been SEVEN months from now! The other heart hospital would have been on the other side of Michigan. Who knew that animal specialty appointments were also terrible to get!?
Scalemail project is one step closer to completion. Ordered scales from a local metalworking company, ordered some split rings... now all I need is to wait. :>
And pray that the split rings will be flexible enough to handle that.
A spooky banner and a spooky pfp for a spooky season.
Spooky-Season.png
Broke: Actually making the stuff you need to make before the game can progress.
Woke: Wasting time instead by making a sidequest where you can recruit an imaginary friend to the party.
1696264391516.png
Day 1 I don't know where to start... I enjoy designing icons and brainstorming the abilities my video game will have

Forum statistics

Threads
134,991
Messages
1,252,679
Members
177,896
Latest member
Wulf_SDP_58343
Top