I want to duplicate an event into a RegionId

Hello!
I want a bottle deposit to appear randomly on the map. It should appear where I've set a RegionId. A new bottle deposit should appear every few minutes. Do you know how I can do this?

I tried this code, but it didn't work. It is from Chatgpt becouse I can't coding:

(() => {
// Einstellungen
const EVENT_ID_TO_COPY = 1; // ID des zu kopierenden Events
const TARGET_REGION_ID = 2; // Ziel-Region-ID, in der dupliziert werden soll
const TARGET_MAP_ID = $gameMap.mapId(); // Aktuelle Karten-ID

// Funktion: Event-Duplikate erstellen
function duplicateEventInRegion(eventId, regionId, mapId) {
const mapData = $dataMap;
if (!mapData) {
console.error("Kartendaten konnten nicht geladen werden.");
return;
}

const eventToCopy = mapData.events[eventId];
if (!eventToCopy) {
console.error(`Event mit ID ${eventId} nicht gefunden.`);
return;
}

// Alle Ziel-Koordinaten suchen
const targetCoordinates = [];
for (let x = 0; x < mapData.width; x++) {
for (let y = 0; y < mapData.height; y++) {
if ($gameMap.regionId(x, y) === regionId) {
targetCoordinates.push({ x, y });
}
}
}

// Event-Daten duplizieren
targetCoordinates.forEach((coord) => {
// Neue Event-ID berechnen (sicherstellen, dass sie nicht mit bestehenden IDs kollidiert)
const newEventId = mapData.events.length;
const newEvent = JSON.parse(JSON.stringify(eventToCopy)); // Tiefenkopie erstellen
newEvent.id = newEventId; // Neue Event-ID
newEvent.x = coord.x; // Ziel-X-Koordinate setzen
newEvent.y = coord.y; // Ziel-Y-Koordinate setzen
mapData.events.push(newEvent); // Event hinzufügen
});

// Karte neu laden, um Änderungen anzuzeigen
$gamePlayer.reserveTransfer(mapId, $gamePlayer.x, $gamePlayer.y, $gamePlayer.direction(), 0);
console.log(`Event mit ID ${eventId} wurde auf Region ${regionId} dupliziert.`);
}

// Script ausführen
duplicateEventInRegion(EVENT_ID_TO_COPY, TARGET_REGION_ID, TARGET_MAP_ID);
})();
It is from Chatgpt
This is probably a large part of your issue. You'd be better off just asking for help from people who do know how to code. There are people on the forums who are often more than willing to help, either for free or for very reasonable fees depending on complexity
This might help you:

It is from Chatgpt becouse I can't coding:
then you have something in common - Chatgpt can't code either, it pretends to be able to do so by randomly putting together code snippets from its database hoping that the result will do something.

all AI currently available anywhere work by randomly putting together weighted code snippets (weighted to fit the searchwords) and then running the equivalent of a lexical and grammatical check over the result.
I believe Visustella's events and move core has a spawn to region command as well.
This might help you:


Thank you very much! It works perfect!

Thanks to everyone else as well for the kind help.

Have a nice day 🙂

Original thread: https://forums.rpgmakerweb.com/threads/i-want-to-duplicate-an-event-into-a-regionid.173737/