So, the plugin is something ive been trying to make and cant seem to get what i want it to do. I want help configuring it and have the same affect in the harvest moon or rune factory games with romance options, theres 6 hearts, each heart is 1000 points of affection, the max affection is 6000 so 6 hearts in total, with five stages of each heart,
empty
1/4
1/2
3/4
and full
any help with this plugin could help,
empty
1/4
1/2
3/4
and full
any help with this plugin could help,
JavaScript:
/*:
* @plugindesc Displays a heart meter based on affection points in events with a <HeartMeter: varID> note tag.
* @author Ponimeimei & SilverWire
*
* @help
* Add the following note tag to the main event notetag to display a heart meter:
*
* <HeartMeter: affectionVar>
*
* - affectionVar: ID of the variable where affection points are stored.
*/
(function() {
const maxHearts = 6; // Maximum number of hearts
const heartImages = {
0: 'EmptyHeart',
1: '1-4Heart',
2: 'HalfHeart',
3: '3-4Heart',
4: 'FullHeart'
};
const heartSprites = {}; // Store heart sprites by event ID
// Load heart images into memory
function preloadHeartImages() {
Object.values(heartImages).forEach(image => {
ImageManager.loadPicture(image);
});
}
// Retrieve the affection variable ID from event's notetags
function getAffectionVarId(event) {
const note = event.event().note;
const regex = /<HeartMeter:\s*(\d+)>/i;
const match = note.match(regex);
return match ? Number(match[1]) : null;
}
// Initialize heart sprites for an event
function initializeHeartSprites(eventId) {
heartSprites[eventId] = [];
for (let i = 0; i < maxHearts; i++) {
const sprite = new Sprite();
sprite.bitmap = ImageManager.loadPicture(heartImages[0]); // Set to EmptyHeart
sprite.visible = false; // Hide initially
SceneManager._scene.addChild(sprite);
heartSprites[eventId].push(sprite);
}
}
// Determine heart state based on affection points
function determineHeartState(affectionPoints, maxAffection) {
const affectionPerHeart = maxAffection / maxHearts;
const fullHearts = Math.floor(affectionPoints / affectionPerHeart);
const remainder = affectionPoints % affectionPerHeart;
// Calculate the heart state
const heartStates = Array(maxHearts).fill(0);
for (let i = 0; i < fullHearts && i < maxHearts; i++) {
heartStates[i] = 4; // Full heart
}
// Check remainder for partial hearts
if (fullHearts < maxHearts) {
if (remainder > affectionPerHeart * 0.75) {
heartStates[fullHearts] = 3; // 3/4 heart
} else if (remainder > affectionPerHeart * 0.5) {
heartStates[fullHearts] = 2; // 1/2 heart
} else if (remainder > affectionPerHeart * 0.25) {
heartStates[fullHearts] = 1; // 1/4 heart
}
}
return heartStates;
}
// Update heart sprites based on affection points
function updateHeartSprites(event) {
const eventId = event.eventId();
const affectionVarId = getAffectionVarId(event);
// Logging for debugging
console.log(`Event ID: ${eventId}, Affection Var ID: ${affectionVarId}`);
if (affectionVarId === null || !event.page()) {
hideHeartSprites(eventId);
return;
}
const affectionPoints = $gameVariables.value(affectionVarId);
const maxAffection = 6000; // Define the maximum affection points
const heartStates = determineHeartState(affectionPoints, maxAffection);
// Show and update heart sprites
if (!heartSprites[eventId]) initializeHeartSprites(eventId);
heartSprites[eventId].forEach((sprite, index) => {
sprite.bitmap = ImageManager.loadPicture(heartImages[heartStates[index]]);
sprite.visible = true; // Make heart visible
sprite.x = event.screenX() + (index * 32); // Position hearts
sprite.y = event.screenY() - 48; // Above the event
// Logging for each heart update
console.log(`Heart ${index + 1}: ${heartStates[index]}, Affection Points: ${affectionPoints}`);
});
}
// Hide all heart sprites for an event
function hideHeartSprites(eventId) {
if (heartSprites[eventId]) {
heartSprites[eventId].forEach(sprite => {
sprite.visible = false;
});
}
}
// Update heart meters every frame
function updateHeartMeters() {
$gameMap.events().forEach(event => {
if (isPlayerCloseToEvent(event)) {
updateHeartSprites(event);
} else {
hideHeartSprites(event.eventId());
}
});
}
// Check if the player is within range of the event
function isPlayerCloseToEvent(event) {
const playerX = $gamePlayer.x;
const playerY = $gamePlayer.y;
const eventX = event.x;
const eventY = event.y;
return Math.abs(playerX - eventX) <= 2 && Math.abs(playerY - eventY) <= 2;
}
// Hook into Scene_Map's update method
const _Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
_Scene_Map_update.call(this);
updateHeartMeters();
};
// Preload heart images when the game starts
const _Scene_Boot_start = Scene_Boot.prototype.start;
Scene_Boot.prototype.start = function() {
_Scene_Boot_start.call(this);
preloadHeartImages();
};
})();