Touch not triggering when same space occupied after jump?

werzaque

Canned Dinosaur
Regular
Joined
May 30, 2023
Messages
390
Reaction score
223
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,693
Reaction score
1,166
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,133
Reaction score
9,062
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
390
Reaction score
223
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,693
Reaction score
1,166
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,133
Reaction score
9,062
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
390
Reaction score
223
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,133
Reaction score
9,062
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
390
Reaction score
223
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,030
Reaction score
4,368
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
390
Reaction score
223
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 was thinking about how funny it'd be if there was an 80's action movie parody based off of RPG Maker starring a protagonist called Sergeant John RPGMaker.
Come and join me shortly for Throwback Thursday, where I'll be continuing with Grim Fandango! https://twitch.tv/trihanstreams
Hi guys do yall like the new way im going to do battle sprites? It dosnt actoully matter what you think im doing it this way anyway but uhm hey1!!!!!!!!!!!!!!!1!!!!11111!!!
Painfull Spirite.png
Papercut bat i think.png
Short cutscene test. Didn't add the dialogues yet because I wanted to make sure this animation idea worked.

Forum statistics

Threads
134,880
Messages
1,251,540
Members
177,682
Latest member
Sisyo011
Top