[XP] Blood Mage 1.80

Started by fugibo, March 08, 2008, 09:56:19 am

Previous topic - Next topic

fugibo

March 08, 2008, 09:56:19 am Last Edit: November 11, 2009, 05:57:25 pm by game_guy
Blood Mage Script
Authors: LongFellow
Version: 1.80
Type: Special Skill Effect
Key Term: Battle Add-on



Introduction

This script allows you to have spells consume HP instead of MP. It comes in very useful for making strategic characters :P


Features


  • Consume HP instead of MP
  • Can turn the effect off for certain skills
  • Easy Configuration
  • Lightweight



Screenshots

n/a for this sort of script



Script
Post this above Blizzard's scripts and below the defaults:

The Script: ShowHide
Code: Blood Mage v 1.80

=begin
 "Blood Mage" Script for RMXP, v 1.80
 by WcW

 Introduction:
   This script was made by request for Akkein (aka Akkrin) at
   http://forum.chaos-project.com/. Make sure to credit him and
   all others listed in the "Credits/Thanks" section below if you
   use this script. For detailed instructions on how to use this script,
   please see the section "Directions" below. For small mods that can
   be done, see the "Tips/Modifying this Script" section below.

 Features:
 *   Allows for the consumption of HP rather than SP for skills
 *   Can be configured to set "Blood Mage" state based on class,
     actor, state, or by default on some skills
 *   Can set behavior for when an actor has too little HP for a
     skill, and can set a minimum percentage of HP an actor must
     have to use skills
 *   As of 1.8, no bug-free (hopefully! ;))
 *   Compatible with SP-cost add-ons and RTAB
 *   Small code; less than 100 lines if you cut out all commeting
     and white space
     
 Version History:
 1.0: Release
   1.02: Undocumented bug fixes
 1.12: Bug fix (checked for SP in addition to HP)
 1.22: "Bloodkill" added, allowing for you to disable "suicide" moves
 1.32: Blizzard gave me some optimized code
   1.33: Undocumented bug fix
 1.43: Modified some code, added new features
   1.44: Fixed status window refresh
   1.45: Fixed bug where Blood Skills were unaffected by SP cost modifications
   1.46: Fixed bug where no HP was consumed if the actor had 0 SP
 1.56: Added the option to disable bloodmage for some skills
   1.57: More RTAB compatibility (a la Blizzard)
   1.58: Fixed bugs (once again, a la Blizzard)
   1.59: Fixed $game_system.bloodmage_not error
 1.70: New testing version; direct predecessor and base of 1.8x series;
       better coding, new options, improved compatibility
   1.71: Undocumented bug fix
   1.72: Fixed RTAB error
   1.73: Improved comments, optimized skill_can_use?(id), added overcharging
         option, fixed an as-yet undiscovered bug (actors with too little HP
         could use a blood skill anyway)
   1.73b: Fixed a careless mistake
 1.80: All bugs fixed, bloodstates added, all commenting redone, flagged
       as stable, $WCW_BLOOD_MAGE added ;)
       
 Roadmap:
 1.85: BlizzABS compatibility, enemies as blood mages, and "dryusers" (users
       who will never use blood skills)
 
 Directions:
   You should place this script below all of the default RMXP scripts (these
   should end in Scene_Debug) and above any of Blizzard's scripts.
   
   All of the instructions below are either referring to the code directly
   after this comment-block, or the code inside Game_System within this script.
   
   - If you want to use RTAB with this script, change
     "WCW_BLOODMAGE_RTAB = false" to "WCW_BLOODMAGE_RTAB = true". This enables
     a small workaround for a quirk in RTAB (make_skill_action_result takes
     an argument, whereas it does not in the DBS)
   - To set an actor to be a bloodmage by default, add his ID between the
     brackets next to "@wcw_bloodusers =" below, and separate all IDs with
     commas. To remove a user from the group, simply delete their ID. To add
     a Blood-User in-game, use a Call Script event command with the code
     "$game_system.wcw_bloodusers.push <id>", replacing <id> with the
     actor's ID. To remove them, use "$game_system.wcw_bloodusers.delete <id>",
     likewise replacing <id> with the actor's ID.
   - To set a class to Blood Mage, add the ID between the brackets beside
     "@wcw_bloodmages =" below, once again separating them with commas.
     To remove a class, simply remove the ID. To add in-game, use Call Script
     with "$game_system.wcw_bloodmages.push <id>", replacing <id> with the ID.
     To remove a class, use "$game_system.wcw_bloodmages.delete <id>".
   - To add a Blood State, add the ID of the state between the brackets next
     to "@wcw_bloodstates =" below, separating each ID with a comma. To
     remove a state, simply remove the ID. To do the same in-game, use
     "$game_system.wcw_bloodstates.push <id>" and
     "$game_system.wcw_bloodstates.delete <id>".
   - To add a skill which always consumes HP rather than MP, add its ID
     between the brackets next to "@wcw_bloodskills = " below, separating
     each ID with commas. To remove the skill, remove the ID. To do the
     same in-game, use "$game_system.wcw_bloodskills.push <id>" and
     "$game_system.wcw_bloodskills.delete <id>".
   - To add a skill that will consume SP even when used by a Bloodmage,
     add its ID between the brackets next to "@wcw_dryskills =" below,
     separating each with a comma. To remove the skill, remove the ID.
     To do the same in-game, use "$game_system.wcw_dryskills.push <id>" and
     "$game_system.wcw_dryskills.delete <id>".
   - To allow a Blood Mage to die when they use a skill the require more
     HP than they have, replace "false" with "true" next to "@wcw_blood_die = "
     below. To reverse this, replace "true" with "false". TO do the same
     in-game, use "$game_system.wcw_blood_die = true" and
     "$game_system.wcw_blood_die = false".
   - To have a Bloodmage be left with 1 HP after they overcharge, replace
     "false" with "true" on the line with "@wcw_blood_overcharge". To do the
     same in-game, use "$game_system.wcw_blood_overcharge = true" or
     "$game_system.wcw_blood_overcharge = false". For this to work, the
     option above must be set to "false".
   - To set the minimum % HP a Blood Mage must have to use a Blood Skill,
     set the number between 0 and 1 next to "@wcw_blood_limit = " below. To do
     the same in-game, use "$game_system.wcw_blood_limit = <% in decimal>".

 Tips/Modifying this Script:
   * To change how much a Blood Mage is left with after overcharging,
     replace the "battler.hp = 1" in make_skill_action_effect in Scene_Battle
     with "battler.hp = <expression>", and the "return @hp > 1" in
     skil_can_use? in Game_Battler with "return @hp > <expression>".
   * To make $game_system.wcw_blood_limit be a static amount rather than
     percentage, replace "(self.hp * $game_system.wcw_blood_limit).to_i"
     in skill_can_use? in Game_battler with "$game_system.wcw_blood_limit".
   * To check for Blood Mage, use "if $WCW_BLOOD_MAGE". To check the version,
     use "if $WCW_BLOOD_MAGE > <your_version>".
     
 Compatibility:
   Tested with SP Cost Mod from Blizzard's Tons of Add-Ons and the
   Default Battle System. If you find any issues, please report them
   at http://forum.chaos-project.com/, in the Blood Mage thread, which
   will most likely be in the "RMXP Script Database" forum.
   
 Credits:
   Blizzard, for helping me learn to script, pointing out a bug, and
     optimizing code
   Fantasist, for getting me to come back to RMXP
   Akkrin, for giving me the Blood Mage idea
   Myself, for scripting it
   Cid, for reporting two errors ;)
   omegapirate2000, for confirming Cid's error (more the merrier :P)
   game_guy, for giving me an idea (overcharging)

 Enjoy |:]
=end

$WCW_BLOOD_MAGE = 1.8

#----------------------------------------------------------------------------
# * CONFIG (redefinition of Game_System class)
#     Configuration section :)
#----------------------------------------------------------------------------
# To use with RTAB, change false in the line below to true.
WCW_BLOODMAGE_RTAB = false

class Game_System

 # Defines getter's and setter's for configuration variables
attr_accessor :wcw_bloodusers, :wcw_bloodmages, :wcw_bloodstates,
               :wcw_bloodskills, :wcw_dryskills, :wcw_blood_die,
               :wcw_blood_overcharge, :wcw_blood_limit
               
# Backs up the old initialize method
alias init_wcw_bloodmage_later initialize

#------------------------------------------------------------------------
# - initialize
# First method called :P
#------------------------------------------------------------------------
def initialize

# This variable stores the ID's of all classes which should consume
# HP over MP.
@wcw_bloodusers = [1]
# This variable stores the ID's of all actors that act as
# bloodmages, even though their class is not a bloodmage.
@wcw_bloodmages = []
   # This variable stores the IDs of all states which cause an actor to
   # consumer HP rather than MP.
   @wcw_bloodstates = []

# This variable stores the ID's of all skills which will act as
# bloodmage skills, even if the actor using it isn't a bloodmage
@wcw_bloodskills = []
# This variable stores the ID's of all skills which will not cause
# a bloodmage to lose HP if they use them.
@wcw_dryskills = [57]

# If this variable is set to "true," bloodmages will be able to kill
# themselves if they use to much HP (it will use more HP than the
# actor has, even if it is not enough for the skill.) If it is
# set to false, they will only be able to use the skills until it
# would put them below $game_system.wcw_blood_limit.
@wcw_blood_die = false
# If this variable is set to "true," (and the one above is false),
# then when an actor uses a blood skill that costs more HP than he
# currently has, it will simply reduce his HP to one. (STILL IN
# TESTING).
@wcw_blood_overcharge = false
# This number must be set from 0 to 1. It signifies the minimum
# percent of HP an actor must have to use a skill if
# $game_system.wcw_blood_die is set to "false. 0 is default,
# and means the actor can use skills until his HP is 1.
@wcw_blood_limit = 0

   # Do everything else that is normally done :P
   return init_wcw_bloodmage_later

 end

end

#----------------------------------------------------------------------------
# * Bulk of the code (redefinition of some Game_Battler code)
#----------------------------------------------------------------------------
class Game_Battler

# Backs up skill_can_use?(skill_id)
alias skill_can_use_wcw_bloodmage_later skill_can_use? #lol, long name :P
 
 #------------------------------------------------------------------------
# - wcw_is_bloodmage?()
# Checks to see if actor is a bloodmage.
#------------------------------------------------------------------------
def wcw_is_bloodmage?
return self.is_a?(Game_Actor) && (
$game_system.wcw_bloodusers.include?(self.class_id) ||
$game_system.wcw_bloodmages.include?(self.id) ||
     @states.any? {|s| $game_system.wcw_bloodstates.include?(s)})
end

#------------------------------------------------------------------------
# - wcw_bloodmages_applies?(skill_id)
# Checks to see whether a given skill is a bloodskill when used by
# the actor.
#------------------------------------------------------------------------
def wcw_bloodmage_applies?(skill_id)
   return (wcw_is_bloodmage? && (!
$game_system.wcw_dryskills.include?(skill_id))) ||
$game_system.wcw_bloodskills.include?(skill_id)
end

#------------------------------------------------------------------------
# - skill_can_use?(skill_id)
# Checks to see if a skill can be used
#------------------------------------------------------------------------
def skill_can_use?(skill_id)

# Go ahead and pass it on if the actor isn't a bloodmage or the
# skill isn't a bloodskill
unless wcw_bloodmage_applies?(skill_id)
return skill_can_use_wcw_bloodmage_later(skill_id)
end

   # Get HP Cost, check other factors
   mysp = @sp
   @sp = $data_skills[skill_id].sp_cost
   return false unless skill_can_use_wcw_bloodmage_later(skill_id)
   @sp = mysp

   # Check HP
   if $game_system.wcw_blood_die
     return true
   elsif $game_system.wcw_blood_overcharge
     return @hp > 1
   else
     cost = (($tons_version >= 6.54) && $game_system.SP_COST_MOD) ?
         BlizzCFG.get_cost_mod(@states, $data_skills[skill_id].sp_cost) :
         $data_skills[skill_id].sp_cost
     print cost
     return (self.hp - cost) >((self.maxhp*$game_system.wcw_blood_limit).to_i)
   end

 end
end

#----------------------------------------------------------------------------
# * Code to make sure bloodmages consume HP instead of MP
#----------------------------------------------------------------------------
class Scene_Battle

# Backs up make_skill_action_result
alias make_skl_act_res_wcw_bldmg_later make_skill_action_result

#----------------------------------------------------------------------------
# - make_skill_action_result(battler=nil)
# Execute skill
#----------------------------------------------------------------------------
def make_skill_action_result(battler = @active_battler)
   mysp = battler.sp
   
# RTAB Compatibility Workaround
if WCW_BLOODMAGE_RTAB
make_skl_act_res_wcw_bldmg_later battler
else
make_skl_act_res_wcw_bldmg_later
end

# Reduce HP, and put the SP back where it should be :P
if battler.wcw_bloodmage_applies?(@skill.id)
     cost = ($tons_version && $game_system.SP_COST_MOD) ?
       BlizzCFG.get_cost_mod(battler.states, $data_skills[@skill.id].sp_cost) :
       $data_skill[@skill.id].sp_cost
# Set HP to 1 if overcharging; else, subtract cost
if (battler.hp < cost) && $game_system.wcw_blood_overcharge
battler.hp = 1
else
battler.hp -= cost
end
battler.sp = mysp
end
# Refresh Status Window
@status_window.refresh
end

end



Instructions
Inside the script.


Compatibility
None found yet. However, it most likely will have compatibility issues with most CBSes.


Credits and Thanks


  • Blizzard, for teaching me how to script and pointing out a bug, plus giving me some optimized code
  • Fantasist, for bringing me back to the RMXP community to do this
  • Akkrein, for giving me the idea
  • Cid, for reporting two errors (keep up the good work ;))
  • Omegapirate2000, for confirming an error (and possibly reporting another with stable :gasp:)
  • game_guy, for suggesting a feature



Author's Notes

Enjoy! Also, report all errors and compatibility issues in THIS THREAD, not in a new topic. And please do report them ;)

Blizzard

March 08, 2008, 10:05:28 am #1 Last Edit: March 08, 2008, 10:08:34 am by BlizzHard
I remember debugging and optimizing v1.0 for Tons, but I never came to add it. xD How about applying the right form?

EDIT:
#==============================================================================
# Blood Mage Magic Script v 1.0.0
# by WcW & Akkrin
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# - code reviewed, optimized, integrated into Tons of Add-ons, freed from
#   potential bugs and beta tested by Blizzard
# - compatible with RTAB and skill cost modifying scripts (by Blizzard)
# - this add-on is part of Tons of Add-ons with full permission of the original
#   author(s)
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Introduction:
#
# I made this script for Akkein(Akkrin) at http://forum.chaos-project.com at
# his request. If he has allowed you to use this, enjoy. If he has not, ask
# him.
#
# Features:
#
# - Allows for certain classes to use up their HP instead of MP when using
#   spells.
# - Lightweight.
#
# Instructions:
#
# Add the IDs of all your "Blood Mage" classes to the [] thingy in the
# CONFIG section.
#
# Compatibility:
#
# This has no known compatibility issues. Might not be compatible with CBS-es.
# If you find any problems, please post them at http://forum.chaos-project.com
#
# WcW, Signing Off
#==============================================================================

#------------------------------------------------------------------------------
# * CONFIG
#     Configuration section
#------------------------------------------------------------------------------

BLOODMAGES = [] # Between the "[" and "]", add the ID of each class the you
                # want to be a blood mage and seperate each with a comma.

# Below lies the code

#------------------------------------------------------------------------------
# * Battle Scene
#------------------------------------------------------------------------------

class Scene_Battle
 
  #----------------------------------------------------------------------------
  # * Make Skill Action Result
  #----------------------------------------------------------------------------
  alias make_skill_action_result make_skill_action_result_bloodmage_later
  def make_skill_action_result(battler = nil)
    if battler == nil
      battler, sp = @active_battler, @active_battler.sp
      make_skill_action_result_bloodmage_later
    else
      sp = battler.hp
      make_skill_action_result_bloodmage_later(battler)
    end
    if (battler.current_action.forcing || battler.skill_can_use?(@skill.id)) &&
        battler.is_a?(Game_Actor) && BLOODMAGES.include?(battler.class_id)
      battler.hp -= sp - battler.sp
      battler.sp = sp
      @status_window.refresh
    end
  end
 
end


Worx with RTAB. :3

EDIT: I suggest aliasing skill_can_use? for convenience so the player can use the skill even though he has not enough SP. *makes a note*
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

March 08, 2008, 10:13:06 am #2 Last Edit: March 08, 2008, 10:17:05 am by WcW
That better?

And I'll look into that, thanks, Blizz. BTW, why did you change your name?

EDIT:

Wait.. I'm confused... In my test bed for this script, skill_can_use? check to see if the skill is learned, I think that the Scene_Battle method I aliased checks the SP.

Blizzard

Nice. :) *powers up*

I changed it just for fun. I'll change it back later.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

Wait... where DOES it check to see if you have enough SP...?

Blizzard

skill_can_use? in Game_Battler. Just alias it.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

March 08, 2008, 10:29:25 am #6 Last Edit: March 08, 2008, 10:43:57 am by WcW
IM AND IDIOT, I WAS LOOKING IN GAME_ACTOR, SAW IT JUST SEEING IF IT WAS LEARNT AND THEN LOOKED AT THE MAKE_SKILL_RESULT, I EVEN SAW THE EFFING SUPER IN THE GAME_ACTOR'S METHOD, IM SUCH AN EFFING IDIOT

ill go fix that , that must be the other bug I found that I couldn't remember :P

EDIT:

Fix'd.

Nortos

gj on this script  I can't be bothered looking through it so can you tell me if compatible with blizz ABS :P

fugibo

Probably not, sorry. Maybe I could make a mod for BlizzABS, though.

Vell

interestin.. skills that use HP instead of MP... maybe I'll use this for Tenia Mala... another game/novel/possible anime/possible manga I'm DEFINITELY going to do in the future, (the game version atleast) will definitely need HP usin skills, I may use this one.

I find it funny that while I was viewing this the ad had a picture of a Blood Elf from WoW...

fugibo

0_o

Also, for the next update, I plan to add a slight aesthetical fix that makes it so that if a Blood Mage has 0 SP, it will show it as the regular color instead of red, an option that can make Blood Mages just display n/a for their SP during battle, and a a new option that lets you turn of HP consumption for certain skills.

Nortos

anyway I already planning on using this in my game maybe and have the only support char use her heatlh to use skills :P

Vell

yeah itll be cool if not ALL spells had to be HP consuming.

this time its a draenei...

Blizzard

No, it's not compatible with Blizz-ABS.

@WcW: Why don't you take my optimized version of your script that's also compatible with RTAB?
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

March 09, 2008, 07:18:46 pm #14 Last Edit: March 09, 2008, 10:43:16 pm by WcW
Oh, sorry, I'll fix that =)

EDIT:

Blizz, the only problem I can spot in your scripting awesomeness is the fact that you NEVER debug your code before hand.

EDIT:

Thanks alot, Blizz, now I'm gonna have to redo your code for the new features.  >:(

It's okay, though

EDIT:

Fix'd. Could someone please check to make sure that it is compatible with RTAB, though?

EDIT:

Major upgrade, lol

EDIT:

And now I know for certain that it is compatible with the latest version of RTAB that I got straight from the Cogwheel website.

Nortos

heh you updated it like 5 times today right?

Blizzard

Now, that's what I call fast development. O_o
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

In the last 3 or 4 days, actually about.... 12 version updates, so....

Blizzard

I wish I Blizz-ABS would go that fast or at least my own game.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

March 10, 2008, 02:21:13 pm #19 Last Edit: March 13, 2008, 01:35:32 pm by WcW
This is a real simple script, it should go pretty fast - and it only is because of how many bugs I found.

EDIT:

And there, yet another one fix'd

EDIT:

Two more fix'd