Orange Custom Events

Hyouryuu-Na

Procrastinator
Veteran
Joined
Jun 15, 2017
Messages
779
Reaction score
1,741
First Language
Not English
Primarily Uses
RMMV
This is a really great plugin! The only one that fills entire regions with events I think. But I need a little help. My map is rather large and I want to despawn some events from certain regions when the player is not near to decrease lag. Say, I use $gameMap.spawnMapEventFrom(9, 7, 4, true); to spawn event 7 from map 9 in region 4. How do I despawn these events? Yes, I know there's a plugin command: delete this event. But for simplifying things I want to use a script call if possible. Any help is appreciated.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,502
Reaction score
3,622
First Language
Java's Crypt
Primarily Uses
RMMZ
I think I didn't add any easy script call for that, so you'll need to do this:

JavaScript:
for (var x = 0; x < $gameMap.width()) {
    for (var y = 0; y < $gameMap.height()) {
        var regionId = $gameMap.regionId(x, y);

        if (regionId === 4) {
            var events = $gameMap.eventsXy(x, y);
            if (events) {
                for (var i = 0; i < events.length) {
                    $gameSystem.removeCustomEvent($gameMap._mapId, events[i]._eventId);
                    events[i].erase();
                }
            }
        }
    }
}

The $gameSystem.removeCustomEvent... line is only needed if the event is not temporary, which doesn't seem to be your case, so you can remove it.

(I wrote this from memory and didn't try in-game, so there may be some errors)
 

Hyouryuu-Na

Procrastinator
Veteran
Joined
Jun 15, 2017
Messages
779
Reaction score
1,741
First Language
Not English
Primarily Uses
RMMV
The events got removed but they don't respawn :/ Here's how I checked if the player is in a region. If not in the region, the events get removed. But they're supposed to be back if player re-enters the region, unless I'm doing something wrong.
◆If:Script:$gamePlayer.regionId()==27
◆Script:$gameSelfSwitches.setValue([this._mapId, 309, 'A'], true);
:Script:$gameSelfSwitches.setValue([this._mapId, 275, 'A'], false);
◆If:Desk_load ≠ 1
◆Script:/*for (i=0; i<=100; i++){
:Script:Yanfly.SpawnEventInRegion(9, 7, 4, true)}*/
:Script:$gameMap.spawnMapEventFrom(9, 7, 4, true);
◆Script:console.log($gamePlayer.regionId());
◆Control Variables:#0010 Desk_load = 1

:End

:Else
◆Script:$gameSelfSwitches.setValue([this._mapId, 309, 'A'], false);
◆Script:for (var x = 0; x < $gameMap.width(); x++) {
:Script: for (var y = 0; y < $gameMap.height(); y++) {
:Script: var regionId = $gameMap.regionId(x, y);
:Script:if (regionId === 4) {
:Script: var events = $gameMap.eventsXy(x, y);
:Script: if (events) {
:Script: for (var i = 0; i < events.length; i++) {
:Script: $gameSystem.removeCustomEvent($gameMap._mapId, events._eventId);
:Script: events.erase();
:Script:}}} }}
◆Control Variables:#0010 Desk_load = 0

:End
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,502
Reaction score
3,622
First Language
Java's Crypt
Primarily Uses
RMMZ
The events got removed but they don't respawn :/ Here's how I checked if the player is in a region. If not in the region, the events get removed. But they're supposed to be back if player re-enters the region, unless I'm doing something wrong.
◆If:Script:$gamePlayer.regionId()==27
◆Script:$gameSelfSwitches.setValue([this._mapId, 309, 'A'], true);
:Script:$gameSelfSwitches.setValue([this._mapId, 275, 'A'], false);
◆If:Desk_load ≠ 1
◆Script:/*for (i=0; i<=100; i++){
:Script:Yanfly.SpawnEventInRegion(9, 7, 4, true)}*/
:Script:$gameMap.spawnMapEventFrom(9, 7, 4, true);
◆Script:console.log($gamePlayer.regionId());
◆Control Variables:#0010 Desk_load = 1

:End

:Else
◆Script:$gameSelfSwitches.setValue([this._mapId, 309, 'A'], false);
◆Script:for (var x = 0; x < $gameMap.width(); x++) {
:Script: for (var y = 0; y < $gameMap.height(); y++) {
:Script: var regionId = $gameMap.regionId(x, y);
:Script:if (regionId === 4) {
:Script: var events = $gameMap.eventsXy(x, y);
:Script: if (events) {
:Script: for (var i = 0; i < events.length; i++) {
:Script: $gameSystem.removeCustomEvent($gameMap._mapId, events._eventId);
:Script: events.erase();
:Script:}}} }}
◆Control Variables:#0010 Desk_load = 0

:End
> ◆Script:console.log($gamePlayer.regionId());

is this line being logged when you re-enter the region?
If it is, then the problem is on the script, if it isn't, then the problem is on the event.
 

Hyouryuu-Na

Procrastinator
Veteran
Joined
Jun 15, 2017
Messages
779
Reaction score
1,741
First Language
Not English
Primarily Uses
RMMV
Yes, it gets logged everytime I re-enter region 27, along with some other regions (made a console log run in the else branch too, if that's important)
I wanted to use this plugin since it's less laggy than Yanfly's. My character gets stuck for 2 whole seconds when I use that one... Well, maybe it is a problem with my event :/ Thanks for helping ^^
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,502
Reaction score
3,622
First Language
Java's Crypt
Primarily Uses
RMMZ
If you're going to add and remove them multiple times, isn't it better if you simply disable the event through a switch?
 

Hyouryuu-Na

Procrastinator
Veteran
Joined
Jun 15, 2017
Messages
779
Reaction score
1,741
First Language
Not English
Primarily Uses
RMMV
I thought about that but aren't the events still physically there, just invisible? Does that reduce lag? I was thinking that I could remove the events entirely from current map and then spawn them again when needed. But it's okay :) I solved my issue. Thank you for your time ^^
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Lots of artists very active right now :)
I'll try all of my gestures.

This Is Vasily. I like him very much
If any composer here would like me to use their music as background on my plugin videos, just let me know.
Wee icons I've been making. I've totaled probably around 30 of them now! I'm trying to see if I can make a little spin on the status buff and nerf status effect icons. Want to add a bit of flair while making sure they are effective at communicating what's needed.

Forum statistics

Threads
103,082
Messages
997,123
Members
134,546
Latest member
rasdf
Top