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);
})();
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);
})();