赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 0 |
经验 | 0 |
最后登录 | 2025-5-9 |
在线时间 | 2 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 26
- 在线时间
- 2 小时
- 注册时间
- 2025-5-5
- 帖子
- 3
|
= =这玩意我拿哈基米写了一堆。奇怪为啥不支持上传JS文件。
复制给你了。
/*:
* @plugindesc Displays an image on the right side of the screen based on the party leader's HP.
* @author Your Name
*
* @param Image Full HP
* @desc Image file name (in img/pictures) for Full/High HP.
* @default
* @require 1
* @dir img/pictures/
* @type file
*
* @param Threshold Medium HP
* @desc HP percentage threshold (0-100) below which Medium HP image is shown.
* @default 50
* @type number
* @min 0
* @max 100
*
* @param Image Medium HP
* @desc Image file name (in img/pictures) for Medium HP.
* @default
* @require 1
* @dir img/pictures/
* @type file
*
* @param Threshold Low HP
* @desc HP percentage threshold (0-100) below which Low HP image is shown.
* @default 25
* @type number
* @min 0
* @max 100
*
* @param Image Low HP
* @desc Image file name (in img/pictures) for Low HP.
* @default
* @require 1
* @dir img/pictures/
* @type file
*
* @param Threshold Critical HP
* @desc HP percentage threshold (0-100) below which Critical HP image is shown.
* @default 10
* @type number
* @min 0
* @max 100
*
* @param Image Critical HP
* @desc Image file name (in img/pictures) for Critical HP.
* @default
* @require 1
* @dir img/pictures/
* @type file
*
* @param Image Zero HP
* @desc Image file name (in img/pictures) for Zero HP (optional).
* @default
* @require 1
* @dir img/pictures/
* @type file
*
* @param Offset X
* @desc Horizontal offset from the right edge of the screen.
* @default 0
* @type number
*
* @param Offset Y
* @desc Vertical offset from the top of the screen.
* @default 0
* @type number
*
* @help
* This plugin displays an image on the right side of the screen during map
* movement and battles. The image changes based on the HP percentage of
* the party leader (first actor in the party).
*
* The image is hidden when the system menu or any other menu scene is open.
*
* Place your images in the img/pictures folder.
*
* Configure the HP thresholds and corresponding image file names in the
* plugin parameters. The thresholds are checked from lowest to highest.
*
* Example:
* - If HP is exactly 0, show Zero HP image (if specified).
* - Else if HP% is < Threshold Critical, show Critical image.
* - Else if HP% is < Threshold Low, show Low image.
* - Else if HP% is < Threshold Medium, show Medium image.
* - Else, show Full HP image.
*
* The image is positioned relative to the top-right corner of the screen
* based on the X and Y offsets. X is offset *from* the right edge.
*
* Plugin Command: None.
*
*/
(function() {
const parameters = PluginManager.parameters('YourPluginName'); // <<< IMPORTANT: Replace 'YourPluginName' with your actual file name!
const imageFull = String(parameters['Image Full HP'] || '');
const thresholdMedium = Number(parameters['Threshold Medium HP'] || 50);
const imageMedium = String(parameters['Image Medium HP'] || '');
const thresholdLow = Number(parameters['Threshold Low HP'] || 25);
const imageLow = String(parameters['Image Low HP'] || '');
const thresholdCritical = Number(parameters['Threshold Critical HP'] || 10);
const imageCritical = String(parameters['Image Critical HP'] || '');
const imageZero = String(parameters['Image Zero HP'] || '');
const offsetX = Number(parameters['Offset X'] || 0);
const offsetY = Number(parameters['Offset Y'] || 0);
// --- Custom Sprite Class ---
// This sprite will handle displaying the image and updating itself
function Sprite_LeaderImage() {
this.initialize(...arguments);
}
Sprite_LeaderImage.prototype = Object.create(Sprite.prototype);
Sprite_LeaderImage.prototype.constructor = Sprite_LeaderImage;
Sprite_LeaderImage.prototype.initialize = function() {
Sprite.prototype.initialize.call(this);
this._currentHpState = null; // Tracks the current HP state ('full', 'medium', etc.)
this._lastLeaderHp = -1; // Tracks the leader's last known HP
this._lastLeaderMhp = -1; // Tracks the leader's last known MHP
this.anchor.x = 1; // Set anchor point to the right edge of the sprite
this.anchor.y = 0; // Set anchor point to the top edge of the sprite
this.x = Graphics.width - offsetX; // Position from the right edge
this.y = offsetY; // Position from the top edge
this.visible = false; // Start hidden
};
// Update method called every frame
Sprite_LeaderImage.prototype.update = function() {
Sprite.prototype.update.call(this);
this.updateVisibility(); // Check if the sprite should be visible
if (this.visible) {
this.updateImage(); // If visible, check and update the image
} else {
// If not visible, ensure the bitmap is cleared to save memory/prevent drawing issues
if (this.bitmap) {
this.bitmap = null;
this._currentHpState = null; // Reset state when hidden
}
}
};
// Determines if the sprite should be visible based on the current scene
Sprite_LeaderImage.prototype.updateVisibility = function() {
const scene = SceneManager._scene;
// Visible in Map and Battle scenes
let shouldBeVisible = (scene instanceof Scene_Map || scene instanceof Scene_Battle);
// Hide if no party leader exists
if (!$gameParty.members()[0]) {
shouldBeVisible = false;
}
this.visible = shouldBeVisible;
};
// Checks the leader's HP and updates the displayed image if necessary
Sprite_LeaderImage.prototype.updateImage = function() {
const leader = $gameParty.members()[0];
if (!leader) {
// Should already be handled by updateVisibility, but double check
this._currentHpState = null;
this.bitmap = null;
return;
}
const hp = leader.hp;
const mhp = leader.mhp;
// Only update the image if HP or MHP has changed since the last check
if (hp === this._lastLeaderHp && mhp === this._lastLeaderMhp && this._currentHpState !== null) {
// No change, do nothing
return;
}
this._lastLeaderHp = hp;
this._lastLeaderMhp = mhp;
let newState = null;
let imageName = '';
if (hp <= 0) { // Handle 0 HP specifically first
newState = 'zero';
imageName = imageZero;
} else if (mhp > 0) { // Calculate percentage only if MHP is valid
const hpPercent = (hp / mhp) * 100;
if (hpPercent < thresholdCritical) {
newState = 'critical';
imageName = imageCritical;
} else if (hpPercent < thresholdLow) {
newState = 'low';
imageName = imageLow;
} else if (hpPercent < thresholdMedium) {
newState = 'medium';
imageName = imageMedium;
} else {
newState = 'full';
imageName = imageFull;
}
} else { // Handle case where MHP is 0 (e.g., actor not properly initialized)
newState = 'zero'; // Or some other default state
imageName = imageZero; // Or a default empty image
}
// Load the new image only if the determined state has changed
if (newState !== this._currentHpState) {
this._currentHpState = newState;
if (imageName) {
// Load the new bitmap from the pictures folder
this.bitmap = ImageManager.loadPicture(imageName);
} else {
// If no image name is set for this state, clear the bitmap
this.bitmap = null;
}
}
};
// --- Alias Spriteset_Map and Spriteset_Battle to add the sprite ---
// Alias the createUpperLayer method in Spriteset_Map
const _Spriteset_Map_createUpperLayer = Spriteset_Map.prototype.createUpperLayer;
Spriteset_Map.prototype.createUpperLayer = function() {
_Spriteset_Map_createUpperLayer.call(this); // Call the original method
this.createLeaderImageSprite(); // Add our custom sprite
};
// Alias the createUpperLayer method in Spriteset_Battle
const _Spriteset_Battle_createUpperLayer = Spriteset_Battle.prototype.createUpperLayer;
Spriteset_Battle.prototype.createUpperLayer = function() {
_Spriteset_Battle_createUpperLayer.call(this); // Call the original method
this.createLeaderImageSprite(); // Add our custom sprite
};
// Helper function to create and add the sprite (shared by Map and Battle spritesets)
Spriteset_Base.prototype.createLeaderImageSprite = function() {
// Check if the sprite already exists to avoid adding duplicates
if (!this._leaderImageSprite) {
this._leaderImageSprite = new Sprite_LeaderImage();
// Add it to the Spriteset's children
this.addChild(this._leaderImageSprite);
}
};
})();
切记文件名一定是YourPluginName 我也不知道为什么换个名字就失效了。 |
|