A more eloquent way of detecting events around a player?

Status
Not open for further replies.

aporokizzu

anti-kumbaya
Member
Joined
Jan 14, 2020
Messages
16
Reaction score
20
First Language
english
Primarily Uses
RMMV
Salutations-

I have the following function:

JavaScript:
    $.IsNearEnough = function(event1_id, event2_id) {

        let result = false;
        let temp = [];

        // get player's coordinates
        let px = $gamePlayer.x;
        let py = $gamePlayer.y;

        // list events within a 3-tile perimeter of player's coordinates
        temp[0] = $gameMap.eventIdXy(px, py - 1);
        temp[1] = $gameMap.eventIdXy(px, py + 1);
        temp[2] = $gameMap.eventIdXy(px - 1, py);
        temp[3] = $gameMap.eventIdXy(px + 1, py);
        temp[4] = $gameMap.eventIdXy(px - 1, py - 1);
        temp[5] = $gameMap.eventIdXy(px + 1, py - 1);
        temp[6] = $gameMap.eventIdXy(px - 1, py + 1);
        temp[7] = $gameMap.eventIdXy(px + 1, py + 1);
        temp[8] = $gameMap.eventIdXy(px, py - 2);
        temp[9] = $gameMap.eventIdXy(px, py + 2);
        temp[10] = $gameMap.eventIdXy(px - 2, py);
        temp[11] = $gameMap.eventIdXy(px + 2, py);
        temp[12] = $gameMap.eventIdXy(px - 2, py - 2);
        temp[13] = $gameMap.eventIdXy(px + 2, py - 2);
        temp[14] = $gameMap.eventIdXy(px - 2, py + 2);
        temp[15] = $gameMap.eventIdXy(px + 2, py + 2);
        temp[16] = $gameMap.eventIdXy(px, py - 3);
        temp[17] = $gameMap.eventIdXy(px, py + 3);
        temp[18] = $gameMap.eventIdXy(px - 3, py);
        temp[19] = $gameMap.eventIdXy(px + 3, py);
        temp[20] = $gameMap.eventIdXy(px - 3, py - 3);
        temp[21] = $gameMap.eventIdXy(px + 3, py - 3);
        temp[22] = $gameMap.eventIdXy(px - 3, py + 3);
        temp[23] = $gameMap.eventIdXy(px + 3, py + 3);

        // check if events sought are within that list
        for (temp[24] = 0; temp[24] < 24; temp[24]++) {

            if (temp[temp[24]] === event1_id) temp[25] = true;
            if (temp[temp[24]] === event2_id) temp[26] = true;

        };

        if (temp[25] == true && temp[26] == true) result = true;

        return result;

    };
It checks around the player's current X and Y coordinates for two specific events. It works, but IMO it is ugly. Would anyone know if there is a more elegant / efficient way to accomplish what I am attempting?

Thanks in advance.
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
665
Reaction score
195
First Language
Javascript
Primarily Uses
RMMV
Like these?
http://www.yanfly.moe/wiki/Event_Proximity_Activate_(YEP) (now cost $1.00 though)
 
Last edited:

aporokizzu

anti-kumbaya
Member
Joined
Jan 14, 2020
Messages
16
Reaction score
20
First Language
english
Primarily Uses
RMMV
Like these?
http://www.yanfly.moe/wiki/Event_Proximity_Activate_(YEP) (now cost $1.00 though)
most excellent. thank you!

now works with:
JavaScript:
    $.IsNearEnough = function(event1_id, event2_id) {

        let result = false;

        if (Galv.DETECT.event(event1_id,3,false) == true && Galv.DETECT.event(event2_id,3,false) == true) result = true;

        return result;

    };
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
6,068
Reaction score
4,265
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Profile Posts

welp, the stock market went down by 7% because of corona today. Time to buy stocks?
Man, being able to edit my game WHILE testplaying it is like the most convenient thing EVER. Thank you, MV...it even makes up for the OGG thing. Well, almost.
Back in the old days, long before I was born, salted crisps - or potato chips, for you yanks - came unsalted and had a little pouch of salt to manually shake on it. Of course, things are more efficient now, but Walker's still brought back the old 'Salt 'N' Shake' style a couple years ago. Dunno why, but if I had to guess, I'd say it's because the nostalgia crowd were getting salty.
Guys I just want to sit around and work on my game! *gets lots and lots of money shoveled at him* Game, I don't recall a game. What game? :LZSexcite:

Forum statistics

Threads
94,550
Messages
921,832
Members
124,415
Latest member
Wijikk
Top