Oh! Dear fizzly thank you very much!
Orange Custom Events
● ARCHIVED · READ-ONLY
-
-
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.
-
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) -
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 -
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. -
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 ^^ -
If you're going to add and remove them multiple times, isn't it better if you simply disable the event through a switch?
-
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 ^^