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
721
Reaction score
249
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,191
Reaction score
4,302
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 Posts

Latest Profile Posts

Basically Everyone: Dont make a long game the first time. Me: I guess i'll make a REALLY long game in that case >:p
I've developed a habit of thanking cleaning ladies for their work.
Sorry Aerith... I will abandon your shoes... :guffaw:
Spent a whole bunch of time today reworking the area in the video because someone said it was too illusory. So I reworked it so it changes less, moved the grass up to the same level as the player.... And found enough extra resources to make the grass moves when the player touches it. Also lots more water, because it looks amazing. I'll probably put up a short updated video later today.
I never noticed how NOISY birds can be in the morning..

Forum statistics

Threads
95,769
Messages
931,740
Members
126,169
Latest member
Nktn18
Top