RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Wounded Enemy Graphics

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
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



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


Code: [Select]
#==============================================================================
#    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


  • modern algebra

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.
« Last Edit: July 29, 2011, 10:09:24 PM by modern algebra »

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Flawles scripting as always, MA! I wish my REGEXP skills were as good as yours :P

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Most Missed Member2014 Zero to Hero2014 Best IRC Quote2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
... I do not understand quite a bit of what's going on here:
Code: [Select]
  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's like a metaphor or something i don't know

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
Hey Modern,
Can you tell me what happens if I put \WG[40, Slime ,75] in the note for an enemy?

*hugs*
« Last Edit: July 14, 2011, 08:05:04 AM by Zeriab »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
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:

Code: [Select]
([^,;\]]+?)\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):

Code: [Select]
      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?
« Last Edit: July 14, 2011, 01:01:37 PM by modern algebra »

****
Hey... my name's... Sashikinaroji...
Rep:
Level 83
fear me...
I think a simpler way to do it would be to have the spaces be the EoS and then use underscores between words then have the script check the string for an underscore and make the underscores into spaces... Or I've just done what my professor tells me what I always do and made a simple problem complex... I've never been good with that.

And this isn't exactly my language of choice, neither...
Ok, DON'T EXPECT HELP FROM ME~! I will perhaps rant a bit, but don't expect me to do graphics for you, even if I say I will... I won't.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Slicing the filename's spaces at the end seems like the best method. Or you could just keep the error message telling the user that they did something wrong if your lazy.

Also something like \wg[ 80, Slime , 75 ] with a space in front of the damaged percent would return an empty threshold, hue and filename and produce no error so if you're really paranoid you can check for spaces before the threshold.
« Last Edit: July 14, 2011, 09:05:56 PM by cozziekuns »

*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
Or perhaps put the name in quotations?

\WG[20, "Death Angel", 1]

Then there would be an easy start and end point, and you'd get to keep the spaces?

\\WG\[(\d*?)\s*[,;]?\s*\"([^,;\]]+)\"[,;]?\s*(\d*?)\s*\]

Don't mind me ... fiddling with this Regex Creator I found while trying to figure out how this arcane language works ...

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
@Sashi - that wouldn't work since we'd want filenames to be able to have underscores in them, and automatically removing them would mean that a filename "Angel_1" for instance, could never be recognized. Besides, the error we are trying to resolve is one that would essentially be a user error (in the sense that it would occur because the user weren't following format). Our goal should, therefore, be the loosening of unnecessary format restrictions and imposing a stricter format with underscores would not really resolve it.

@Exhydra - Quotations would certainly work, though we'd need to include \" in the [^,;\]]. To some extent, it also comes within my enforcing a stricter format objection, but it would be a fine way to solve the problem in a simpler way.

@cozzie - thanks for the headsup; you're right and I am really paranoid :)
« Last Edit: July 14, 2011, 10:31:24 PM by modern algebra »

*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
Hm, when I parsed the the regex, it seemed to work alright. Well, I was just looking to remove the quotations from the returned value of the file name so that there wouldn't be a need to take an extra step of chopping them off.

At any rate, slowly learning these ancient runes called regex ...  D;
« Last Edit: July 14, 2011, 10:37:45 PM by Exhydra »

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
Never mind, you're right about that. I was thinking about something else, but yeah - you wouldn't need to include the \".

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Most Missed Member2014 Zero to Hero2014 Best IRC Quote2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
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.
Code: [Select]
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
it's like a metaphor or something i don't know

*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
Eh, there's plenty of good ways to go about reigning in the possible errors. My suggestion isn't amazing. :P  Adding a piece of text to the script instructions telling the user not to add extra, unneeded spaces would work just as well. Maybe toss in an error message too ... it could read : 'Stop being silly.'

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
You have all missed this ambiguity: \wg[40, 30]
What should happen when you have two arguments and the filename is a number?
You need to make a decision as to whether it will be percentage and filename or filename and hue.

I could take the decision for you and give you somethingl like this:
/\\WG\[(\s*(\d+?)\s*[,;])?\s*([^,;\]]+?)\s*([,;]\s*(\d+)\s*)?\]/i

Mind you, while a filename cannot start with a space it can end with spaces (before the extension which you do not include)
One way to accomodate for that possibility is to add a case using quotation marks, now requiring quotation marks both places "My pic" and disallowing My pic" and "My pic is fairly bothersome the easiest way probably being something like this: (Maybe it's ok to allow those two cases)

/\\WG\[(\s*(\d+?)\s*[,;])?\s*([^,;\]]+?)\s*([,;]\s*(\d+)\s*)?\]|\\WG\[(\s*(\d+?)\s*[,;])?\s*\"([^,;\]]+?)\"\s*([,;]\s*(\d+)\s*)?\]/i


Of course you can split up and have several regex checks rather than compressing all the possibilities into one.

I hope this have giving you some ideas for solving the problem.

*hugs*

***
Rep:
Level 74
I'm baaack!
If this works with tankentai ATB and can be used for dead enemes then I'll will definatley use this script.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
It probably works for Tankentai. It won't for dead enemies unless you fiddle with the collapse stuff.