Wounded Enemy Graphics
Version: 1.0a
Author: modern algebra
Date: July 29, 2011
Version History
- <Version 1.0a> 2011.08.29 - Changed the REGEXP to allow for the use of quotation marks to resolve ambiguities
- <Version 1.0> 2011.07.08 - Original Release
Description
This script allows you to change the graphics used for enemy battlers and depending on the amount of HP they have left. This allows you to make them look wounded when they get below a certain percentage of health
Features
- Allows you to replace the graphic of an enemy when they fall below a specified percentage of HP
- Can set individual and multiple thresholds for each enemy, allowing them to look progressively weaker
- Can also set the hue
Screenshots
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg94.imageshack.us%2Fimg94%2F2001%2Fwounded1.png&hash=bbb27ab7bce784efe971ce946f6495bb0c31aea7)
Instructions
Paste this script into its own slot above Main but below Materials in the Script Editor. If you are using the Note Editor and General Patch, then this script should go below it.
See the header of the script for instructions on use.
Script
#==============================================================================
# Wounded Enemy Graphics
# Version: 1.0a
# Author: modern algebra (rmrk.net)
# Date: July 29, 2011
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Description:
#
# This script allows you to change the graphics used for enemy battlers and
# depending on the amount of HP they have left. This allows you to make them
# look wounded when they get below a certain percentage of health
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Instructions:
#
# Paste this script into its own slot above Main but below Materials in the
# Script Editor. If you are using the Note Editor and General Patch, then
# this script should go below it.
#
# This script is easy to use. To setup a wounded graphic, all you need to do
# is put the following code in the notebox of an enemy:
#
# \WG[threshold, "filename", hue]
# threshold : this is an integer and it is the percentage of HP below
# which this graphic will be shown. If excluded, it defaults to the
# value you set at line 50.
# filename : the name of the battler graphic it changes to. You
# should use quotation marks to avoid ambiguity (especially with
# filenames that are numbers) but you can also omit them.
# hue : the hue the graphic is when it changes. Defaults to 0
# if excluded.
#
# EXAMPLES:
#
# \wg[20, "Slime"]
# The graphic would change to slime with hue 0 when the enemy goes below 20%
# health
#
# \Wg["54", 70]
# The graphic would change to that of 54 with hue 70 when the enemy's HP
# falls below whatever percentage you set at line 50 (by default, 15)
#
# \WG[40, Slime, 75]
# The graphic would change to Slime with hue 75 when the enemy goes below
# 40% health.
#==============================================================================
$imported = {} unless $imported
$imported["MAWoundedEnemyGraphics"] = true
# The below value is the default HP threshold to show a new graphic.
MAWEG_DEFAULT_THRESHOLD = 15
#==============================================================================
# ** RPG::Enemy
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# new method - wounded_graphics
# aliased method (if using Note Editor & Patch) - ma_reset_note_values
#==============================================================================
class RPG::Enemy
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Wounded Graphics
#``````````````````````````````````````````````````````````````````````````
# This method interprets the notes and returns an array with each battler
# in the form [threshold, battler_graphic, hue]
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def wounded_graphics
if !@wounded_graphics
@wounded_graphics = { 100 => [self.battler_name, self.battler_hue] }
self.note.gsub (/\\WG\[\s*(\d*?)\s*[,;]?\s*\"?([^,;\]\"]+)\"?[,;]?\s*(\d*?)\s*\]/i) {
threshold = $1.empty? ? MAWEG_DEFAULT_THRESHOLD : $1.to_i
@wounded_graphics[threshold] = [$2, $3.to_i]; ""
}
end
return @wounded_graphics
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Reset Note Values
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if self.method_defined? (:ma_reset_note_values)
alias mlg_woundgrp_resetnote_6th2 ma_reset_note_values
def ma_reset_note_values (*args)
mlg_woundgrp_resetnote_6th2 (*args) # Run Original Method
@wounded_graphics = nil
end
end
end
#==============================================================================
# ** Game_Enemy
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# aliased method - hp=
#==============================================================================
class Game_Enemy
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Set HP
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias mag_wound_sethp_6gz9 hp= unless self.method_defined? (:mag_wound_sethp_6gz9)
def hp= (*args, &block)
mag_wound_sethp_6gz9 (*args, &block) # Run Original Method
wg = enemy.wounded_graphics
return if wg.empty? || self.dead? # Ignore if no wounded set or dead
# Set battle graphics depending on whether the threshold has been reached
health_percent = (self.hp * 100) / self.maxhp
wg.keys.sort.each { |threshold|
if health_percent <= threshold
@battler_name, @battler_hue = *wg[threshold]
break
end
}
end
end
Credit
Support
Please post in this topic at RMRK for support, no matter how old the topic is. Do not PM me.
Known Compatibility Issues
Except for scripts that dramatically change battler graphics, this should be compatible with most other scripts. If using the Note Editor, then the General Compatibility Patch is required and both should be above this script in the Editor.
... I do not understand quite a bit of what's going on here: def wounded_graphics
if !@wounded_graphics
@wounded_graphics = { 100 => [self.battler_name, self.battler_hue] }
self.note.gsub (/\\WG\[(\d*?)[,;]?\s*([^,;\]]+)[,;]?\s*(\d*?)\]/i) {
threshold = $1.empty? ? MAWEG_DEFAULT_THRESHOLD : $1.to_i
hue = $3.empty? ? 0 : $3.to_i
@wounded_graphics[threshold] = [$2.to_s, hue]
}
end
return @wounded_graphics
end
Seriously, your notebox workings are amazing.
It would throw an error since it would be asking for a graphic named "Slime ". However, I'm not sure how I could safely avoid it. To do so, I couldn't just add a space to the [^,;\]] since I want it to capture battlers with two words in their name (like "Dark Knight"). I'd have to do it like this:
([^,;\]]+?)\s*[,;]?
But that creates a new problem since I need that code to be greedy. Otherwise the RegExp will have problems when trying to use graphics that end in numbers and where the user does not set the hue. Ie. a code like this:
\WG[20, Angel1]
Since I intentionally made the last argument optional, none of the [,;]?\s*... is necessary for the RegExp to be met so the code, when the middle argument isn't greedy, would separate the 1 from the Angel and give us a battler "Angel" with a hue of 1, which would cause an error.
Maybe the better solution would be to leave it as it is but include a code below to shear off any end spaces from $2? Then the code would be (also adding to it a couple other buffers since the code would have also been corrupted by putting spaces before the very end or before the first comma):
self.note.gsub (/\\WG\[(\d*?)\s*[,;]?\s*([^,;\]]+)[,;]?\s*(\d*?)\s*\]/i) {
threshold = $1.empty? ? MAWEG_DEFAULT_THRESHOLD : $1.to_i
hue = $3.to_i
filename = $2.dup
filename.slice! (/\s*\z/)
@wounded_graphics[threshold] = [filename, hue]
}
Do you think that would work or have I missed something?
Exhydra, stop being so smart and resourceful. It's making us all look bad. And by "us all", I mean "me".
Anyway, my outrageous suggestion. You could make the tags for threshold, graphic and hue different. i.e.
when /<(?:WG|wg)[ ](.*):[ ](\d+)>/i
case $1.upcase
when "THRESHOLD"
@threshold = $2.to_i
when "HUE"
@hue = $2.to_i
etc.
But don't listen to me, I'm sure every other person's ideas are much better than mine ;9