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
708
Reaction score
240
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,162
Reaction score
4,297
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

I was planning to release a useless plugin for april fools, but then I thought I let it be.
Tfw every dev around me is using Live2D in their MV games and make me question my skills repeatedly.

Spending the day reworking my maps, especially the first "biome". This time it's not even in the dark. :LZSwink:
Activity on the forums has increased lately, probably because of people staying home. The amount of work for moderators has increased lol.
At this point I've gotten so tired of April Fools on the internet that last year I just refused to even post anything on the RMW Social Media on April Fools in protest. Considering doing it again.

Forum statistics

Threads
95,521
Messages
929,774
Members
125,786
Latest member
Caramon
Top