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
19
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
652
Reaction score
188
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
19
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,050
Reaction score
4,260
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

Broke: Dont move. -boring. -passive. -uncreative. Woke: Bewegen Sie Nicht! +authoritative. +foreign. +reminds your son that he's a garden gnome now.
My girlfriend left a note on the fridge saying 'This isn't working, goodbye.' I opened the refrigerator and it works just fine. Weird.
BCj
Could someone translate something from Japanese to English for me?

Forum statistics

Threads
94,386
Messages
920,548
Members
124,165
Latest member
Zflooder
Top