So i couldn't find any plugins to use mouse hover as input to trigger a common event, i'm making a point and click and wanted to fill the borders of the map with events, that, when triggered by the moouse hover input, would transfer to a different map, to emulate looking around. As a last resource i turned to chatgpt and it made me this script:
initially, it worked for the mouse hover input, but with the limit of just one common event, so i asked to rewrite it and add the option to put multiple common events, to do that i set in the parameters the note tag that links to a common event, and put that note tag on the event, but, this time, hovering with the mouse does nothing, what could be the problem here?
i already asked to rewrite a bunch of times and checked everything in the engine, thanks in advance!
JavaScript:
//=============================================================================
// HoverEventTrigger.js
//=============================================================================
/*:
* @plugindesc Triggers common events on mouse hover based on event note tags.
* @author Your Name
*
* @param Common Events
* @text Common Events Configuration
* @desc Configuration for triggering common events on mouse hover.
* @type struct<CommonEvent>[]
* @default []
*
* @help
* This plugin allows you to trigger different common events
* based on note tags assigned to events on the map.
*
* Note tags should be added to event notes in the following format:
* <triggerHover> or <customHover>
*
* Each common event is configured in the Plugin Manager parameters.
*/
/*~struct~CommonEvent:
* @param Note Tag
* @desc The note tag that identifies events triggering this common event on hover.
* @type text
*
* @param Common Event ID
* @desc The ID of the common event to trigger.
* @type number
* @min 1
*
* @param Cooldown Time
* @desc The cooldown period in frames for each common event.
* @type number
* @min 1
* @default 60
*/
(function() {
var pluginParams = PluginManager.parameters('HoverEventTrigger');
var commonEvents = JSON.parse(pluginParams['Common Events']);
var cooldowns = {};
document.addEventListener('mouseover', function(event) {
try {
console.log('Mouseover event:', event);
if (!SceneManager._scene || !SceneManager._scene.spriteset || !SceneManager._scene.spriteset.characterSprites) {
console.log('Scene or spriteset not fully initialized');
return; // Exit early if scene or spriteset is not fully initialized
}
var character = SceneManager._scene.spriteset.characterSprites.find(function(sprite) {
return sprite instanceof Sprite_Character && sprite.character === event.target;
});
if (character && character instanceof Sprite_Character) {
var event = character._character;
console.log('Hovered event:', event);
var noteTag = event.event().note.trim().replace(/<(?:.|\n)*?>/gm, '');
console.log('Event note tag:', noteTag);
var config = findConfigByNoteTag(noteTag);
console.log('Config for note tag:', config);
if (config && !cooldowns[event.eventId()]) {
console.log('Triggering Common Event ID:', config['Common Event ID']);
$gameTemp.reserveCommonEvent(config['Common Event ID']);
cooldowns[event.eventId()] = config['Cooldown Time'];
setTimeout(function() {
cooldowns[event.eventId()] = 0;
}, config['Cooldown Time'] * 1000);
}
}
} catch (error) {
console.error('Error in hover event trigger:', error);
}
});
function findConfigByNoteTag(noteTag) {
for (var i = 0; i < commonEvents.length; i++) {
if (commonEvents[i]['Note Tag'] === noteTag) {
return commonEvents[i];
}
}
return null;
}
})();
initially, it worked for the mouse hover input, but with the limit of just one common event, so i asked to rewrite it and add the option to put multiple common events, to do that i set in the parameters the note tag that links to a common event, and put that note tag on the event, but, this time, hovering with the mouse does nothing, what could be the problem here?
i already asked to rewrite a bunch of times and checked everything in the engine, thanks in advance!