Touch not triggering when same space occupied after jump?

werzaque

Canned Dinosaur
Regular
Joined
May 30, 2023
Messages
392
Reaction score
225
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,700
Reaction score
1,168
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,151
Reaction score
9,097
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
392
Reaction score
225
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,700
Reaction score
1,168
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,151
Reaction score
9,097
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
392
Reaction score
225
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,151
Reaction score
9,097
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
392
Reaction score
225
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,031
Reaction score
4,372
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
392
Reaction score
225
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 Posts

Latest Profile Posts

I'm pretty sure me watching Netflix while having sushi just led to me eating the tail of my tempura shrimp.
1696004095642.png
...and now he even makes resources, too! xD
OMG Y'all. I found an alternate Google Drive I 100% forgot I had. All my crusty old game files from 2014 (when I signed up) are in there. When I like...maybe actually make a prototype thread it's gonna be so much fun taking everyone down my memory lane.
We are at the finish line!!! Thank you COMMUNITY!!!
GameCompletion.jpg
Well, my cat died. Just had a feeling something was off, and went to check.
Someone abandoned her a while ago when she was pregnant, and she wandered into my yard.
Took her to the vet, and did all the usual stuff, making sure she had all the shots and no one was looking for her.
She had the kittens. I kept 1, and found a home for the rest. (Continued because of the limit)

Forum statistics

Threads
134,903
Messages
1,251,749
Members
177,721
Latest member
binamshelanro
Top