MV Chrono Engine: Have Hookshot pull items to the player?

Sorry for making another Chrono Engine thread, there's only so much existing support for it.

Currently, the Chrono Engine's Hookshot feature can pull the player towards any events with the hookshot_collision comment. It can also damage enemies in ABS mode with knockback, as well as pick up item drops.

What I would like to do is have a similar but opposite comment tag for the Hookshot, one that denotes events that would be pulled to the player with the Hookshot, rather than the player being pulled towards it. (For example: A chest on the other side of a chasm that would need to be pulled over in order to open.) Since I'm using the ATB mode instead of ABS, I would also like the Hookshot to be able to pull enemies towards the player to engage a battle.

In a custom "HookShotFix.js" plugin I've been cobbling together, I (apparently?) managed to denote hookshot_collision events as one of two "Pull types" by adding and reading a variable, which would show up in the event editor as something like hookshot_collision : 2:

1696365294505.png


But beyond being able to make the distinction in code, I have no idea how to actually add the effect I want. Has anyone done something similar to this before in Chrono Engine? Any pointers would be appreciated.

(I'll keep tooling at it on my own and edit this original post with any updates.)
what exactly means "comment[1] !== 2" and the other with === 2?
isn't it easier to make a comment read "pulls_player" and/or "pulls_event"
as a tag?

there should be something how to make them read that way or distance?
Doesn't the boomerang function do this already?
what exactly means "comment[1] !== 2" and the other with === 2?
isn't it easier to make a comment read "pulls_player" and/or "pulls_event"
as a tag?

there should be something how to make them read that way or distance?
You're right, that's a much more intuitive way of coding it 😅 Just added that in, haha.

Doesn't the boomerang function do this already?
I got really excited when I read this, but no, it does not appear to, at least in my game.

One hypothetical solution is that if a single event could respond differently to different collision IDs, I could have one event script run if it detects the Hookshot tool, and another if the player just activates it like normal. I may try to wedge this into my little fixes plugin if possible, since it could open up way more other possibilities as well, but any more direct/practical suggestions are very much welcome.




EDIT: Okay this may seem unrelated but I think I'm really close to figuring this out and I just need a little help with Javascript!

This is a segment from what I overwrote the "Check Tool Comments" function with:
JavaScript:
Game_Event.prototype.checkToolComments = function() {
    this._user.touchDamage = false;
    this._user.toolCollision = [];
    if (!this._erased && this.page()) {this.list().forEach(function(l) {
           if (l.code === 108) {var comment = l.parameters[0].split(' : ')
                if (comment[0].toLowerCase() == "collision_id"){
                    this._user.toolCollision.push(Number(comment[1]));
                    this._user.toolCollisionSwitchString = (String(comment[2]));
                };

And here's what I did to the "Execute Collision" function (note the $gameSelfSwitches):
JavaScript:
ToolEvent.prototype.executeCollision = function(target) {
    //console.log($gameMap._mapId, target._eventId, this._user.toolCollisionSwitchString);
    $gameSelfSwitches.setValue([$gameMap._mapId, target._eventId, this._user.toolCollisionSwitchString], true);
    console.log(this._user.toolCollisionSwitchString);
    if (this.isCollisionEvent(target)) {this.collisionTool(target)};
    if (this.isHookshotEvent(target)) {this.collisionHookshot(target)};   
    if (target === this.user()) {this.collisionUser(target)};
    if (!this.isPiercing()) {this.durationOne()};
    if (target.battler()) {this.setInvunerableDuration(target)};
};

What this is trying to do is add a second parameter to the collision_id comment that designates a self switch to activate when it detects a certain collision ID (in this case 10, or the Hookshot).

But when I run console.log(this._user.toolCollisionSwitchString); it returns undefined, even though when I run console.log(String(comment[2])); it returns "a" as expected. I assume the variable just isn't carrying over somehow? I'm sure it's some dumb basic thing that I don't understand. Any help would be appreciated!

(Also, this didn't occur to me until I started typing this--would it be more useful for this to jump to a label instead of activating a self switch?)
when I run console.log(this._user.toolCollisionSwitchString);
Because when you run that command from the console log it doesn't know what "this" is referring to. You need to tell it the object you want to check.
I tried specifying the object, though I also wasn't sure which one I should apply it to:

JavaScript:
Game_Event.prototype.checkToolComments = function() {
    this._user.touchDamage = false;
    this._user.toolCollision = [];
    if (!this._erased && this.page()) {this.list().forEach(function(l) {
           if (l.code === 108) {var comment = l.parameters[0].split(' : ')
                if (comment[0].toLowerCase() == "collision_id"){
                    this._user.toolCollision.push(Number(comment[1]));
                    Game_Event.prototype.selfswitch = (String(comment[2]));
                };

JavaScript:
ToolEvent.prototype.executeCollision = function(target) {
    $gameSelfSwitches.setValue([$gameMap._mapId, target._eventId, Game_Event.prototype.selfswitch], true);
    if (this.isCollisionEvent(target)) {this.collisionTool(target)};
    if (this.isHookshotEvent(target)) {this.collisionHookshot(target)};   
    if (target === this.user()) {this.collisionUser(target)};
    if (!this.isPiercing()) {this.durationOne()};
    if (target.battler()) {this.setInvunerableDuration(target)};
};

It seems to finally work!

As a bonus, since "Game_Event.prototype.selfswitch" is just a variable, you presumably could use this in a Jump to Label function as well as Self Switches, or pretty much anything else! I still have to do a lot of testing with the code and with eventing to make that work out, but this was the big hurdle in this project, I think.

Thank you so much for the help! I'll add more to the thread (without doubleposting) as I find out more, but for now, I think I'm gonna get some sleep 🙂



Edit: It doesn't work, actually.

If I have "collision_id : 10 : A" and then "collision_id : 7 : B" in an event, then trigger it with a tool, it runs the B event even if i use the Tool with ID 10 (Hookshot). It seems the variable is just being overwritten as it runs through the event, and when it gets to the "Jump To Label" script I have, "B" is the latest value of the variable.

This is way more complicated than I expected. Does anyone have any ideas or advice on how to approach this? I've included the patch file I'm working with (as-is; a lot of it is borrowed code so I claim no ownership or credit for it), if anyone would like to take a look. It's a bit messy.

I'll bump this once it's been 72 hours.
Just to put it out there to save your fingers a bit (and make it a bit more readable) - when you're only doing one thing after an "if", you don't need to type braces around it. Conditionals automatically apply to the next single statement.

Also, it's best practice to use getter functions when provided. So $gameMap.mapId() and target.eventId(), rather than accessing the properties directly - that minimizes any possibility of your code conflicting with other plugins.

Code:
                    Game_Event.prototype.selfswitch = (String(comment[2]));
There's no need to call String() on that, it already is one.

Code:
    $gameSelfSwitches.setValue([$gameMap._mapId, target._eventId, Game_Event.prototype.selfswitch], true);

As a bonus, since "Game_Event.prototype.selfswitch" is just a variable...
This is not good usage. When you do that, you're creating a new property on the Game_Event class. Every time you check the tool comments it's going to globally redefine that property for all events running in your game.

If you want to store which switch it's toggling on the event that's being targeted, you should store it as a property on that event. If there's a reason you want it globally available, you'd be better off using one of your game variables.
Restart must have already wrote this into the hookshot function in CrossEngine because the hookshot pulls enemies to you in CrossEngine.

E: Seems like Restart's version only works on enemy events and only in ABS mode, so it would just be a matter of editing it for your use case
Sorry for the late response, I've been trying to figure some things out on my end. So far I've seemingly managed to get a lot of the features I want in? Though I have no idea how good or practical my amateur code is lol. I've managed to:
  • Have enemies be pulled towards the player (thanks to AquaEcho's suggestion and some tweaked CrossEngine code)
  • Prevented enemies from being pulled towards the player if doing so would place the enemy on an invalid tile
  • Made collision_id events (neither enemy_id nor collision_hookshot events) that are activated by the Hookshot, automatically stop and retract the Hookshot when hit, so it doesn't pierce through
  • Allowed a distinguishing between "light" and "heavy" enemies, which are either pulled towards the player or pull the player towards them respectively
  • Made "collision labels" stored in an array similar to their Tool IDs, rather than a single global variable (I think I did what you suggested, ATT_Turan)
I appreciate all the help and the suggestions 🙂 I just have one final problem, and then my Hookshot tweaks plugin will finally be complete. (Barring needing to clean messy code ofc)

When I grapple towards an enemy or pull an enemy towards me, there's a delay of about three seconds before the Chrono Engine battle starts, during which the player can just run away. I suppose this could be treated as a "stun" effect, but what I want is to have grappling an enemy automatically engage a battle. (Preferably with some kind of initiative bonus or something as well, but I'll cross that bridge when I get there.)

I imagine this "stagger" comes from Chrono's ABS mode, where the player would need to be prevented from spamming attacks like the Hookshot on enemies? But I'm working with ATB mode, not ABS, so I either need to carve this part of the code out or figure out how to force a battle to start when an enemy is grappled.

I've tried to solve this myself with no luck. I believe the "Game_Event.prototype.updateRasEvent()" function is close to what I want? But I have no idea how to call it in the context I want; it just spits errors whenever I try.

Any advice or help is appreciated! And sorry for another long post 😅 I've attached the latest version of my patch, in all its spaghetti-code glory.
When I grapple towards an enemy or pull an enemy towards me, there's a delay of about three seconds before the Chrono Engine battle starts, during which the player can just run away
Have you tried modifying the hookshot event page? I believe there are comments that adjust cooldowns/wait times after you use a tool event
I actually did get it figured out, yeah! The hookshot event page doesn't seem to affect enemy "stun" times, but under ToolEvent.prototype.collisionBattler, you can have battler._ras.knockback[1] changed to whatever you'd like; I set mine to 10 and now enemy encounters start immediately after grappling them 🙂

I do still have to figure out how to apply this to regular events as well as enemies, plus adding "collision_hookshot" to an enemy event actually freezes the enemy when you grapple it, and it never runs the battle event at all.



EDIT: I figured it out! Add this under ToolEvent.prototype.checkToolComments:

JavaScript:
if (!this._tool.enabled && comment[0].toLowerCase() == "collision_hookshot"){
                    if (comment[1] == "pull") {
                        this._user.hookshotPull = true;
                    };
                    this._user.hookshotEvent = true;
                };

This under ToolEvent.prototype.executeCollision:

JavaScript:
if (this.isHookshotEvent(target)) {
        if (target._user.hookshotPull === true) {
            if (this.checkHookshotClearance(target)) {this.knockbackHookshot(target)};
        } else {
            this.collisionHookshot(target);
        };
    };

And then I copied some code from setKnockbackDirection to make a new function, ToolEvent.prototype.checkHookshotClearance:

JavaScript:
ToolEvent.prototype.checkHookshotClearance = function(target) {
    if (this._tool.hookshot.enabled && $gameSystem.isAbsMode()) {
        if ($gamePlayer.direction() === 2) {
            var ex = $gamePlayer.x;
            var ey = $gamePlayer.y + 1;
        } else if ($gamePlayer.direction() === 4) {
            var ex = $gamePlayer.x - 1;
            var ey = $gamePlayer.y;        
        } else if ($gamePlayer.direction() === 6) {    
            var ex = $gamePlayer.x + 1;
            var ey = $gamePlayer.y;      
        } else {
            var ex = $gamePlayer.x;
            var ey = $gamePlayer.y - 1;
        };
    if ($gameMap.isPassable(ex, ey) && !this.isCollidedWithCharacters(ex, ey)) {return true;};
    };
};

And now any event with the comment "collision_hookshot : pull" will be pulled towards the player, rather than pulling the player towards the event!

The only thing left that I want to change is to allow the player to grapple towards certain "heavy" enemies, rather than pulling those enemies to the player, and then starting a fight. Currently, any event with both "collision_hookshot" and "enemy_id" comments will completely freeze up if hit with the hookshot. Will edit this post again if I figure that out on my own, but any help is appreciated 🙂

Original thread: https://forums.rpgmakerweb.com/threads/chrono-engine-have-hookshot-pull-items-to-the-player.161719/