Variable-based Victory MEs

Variable-Based Victory MEs
Version: 1


Introduction
This script allows developers to set victory MEs depending on the value of a game variable. Useful if you want your project's victory ME changed when the player has progressed pretty far in the game.

Features
  • Set variable ID and control victory MEs through the variable's value.

Screenshots
No screencaps.

Demo
No demo.

Script
  1. =begin
  2. ╔══════════════════════════════════════════════════════════════════════════════╗
  3. ║ Variable-Based Battle Victory MEs                                            ║
  4. ║ by PK8                                                                       ║
  5. ║ September 29th, 2009                                                         ║
  6. ║ http://rmvxp.com                                                             ║
  7. ╟──────────────────────────────────────────────────────────────────────────────╢
  8. ║ ■ Table of Contents                                                          ║
  9. ║ ├─ Author's Notes                - Line 16─18                                ║
  10. ║ ├─ Introduction & Description    - Line 20─23                                ║
  11. ║ ├─ Features                      - Line 25,26                                ║
  12. ║ ├─ How to Use                    - Line 28─35                                ║
  13. ║ ├─ Methods Aliased               - Line 37,38                                ║
  14. ║ └─ Thanks                        - Line 40─42                                ║
  15. ╟──────────────────────────────────────────────────────────────────────────────╢
  16. ║ ■ Author's Notes                                                             ║
  17. ║ After working on Individual Troop Victory MEs, I wanted to work on this      ║
  18. ║ script. I was pretty bored so yeah.                                          ║
  19. ╟──────────────────────────────────────────────────────────────────────────────╢
  20. ║ ■ Introduction & Description                                                 ║
  21. ║ This script allows developers to set victory MEs depending on the value of a ║
  22. ║ game variable. Useful if you want your project's victory ME changed when the ║
  23. ║ player has progressed pretty far in the game.                                ║
  24. ╟──────────────────────────────────────────────────────────────────────────────╢
  25. ║ ■ Features                                                                   ║
  26. ║ ─ Set variable ID and control victory MEs through the variable's value.      ║
  27. ╟──────────────────────────────────────────────────────────────────────────────╢
  28. ║ ■ How to Use                                                                 ║
  29. ║ Varba_Victory_Var: Set game variable ID.                                     ║
  30. ║                                                                              ║
  31. ║ Varba_Victory[variable id value] = ["file", volume, pitch]                   ║
  32. ║ ^ Sets victory ME based on the value of the variable ID.                     ║
  33. ║                                                                              ║
  34. ║ Note: If you're using Individual Troop Victory MEs, please paste this script ║
  35. ║       above it. It's so Individual Troop Victory MEs can override this script║
  36. ╟──────────────────────────────────────────────────────────────────────────────╢
  37. ║ ■ Methods Aliased                                                            ║
  38. ║ ─ start_phase5 of Scene_Battle                                               ║
  39. ╟──────────────────────────────────────────────────────────────────────────────╢
  40. ║ ■ Thanks                                                                     ║
  41. ║ ─ If it weren't for JoeYoung's original request, I wouldn't have worked on   ║
  42. ║   this script.                                                               ║
  43. ╚══════════════════════════════════════════════════════════════════════════════╝
  44. =end
  45.  
  46. #------------------------------------------------------------------------------
  47. # * Customise
  48. #------------------------------------------------------------------------------
  49. class PK8
  50.   Varba_Victory = {} # Do not touch this.
  51.  
  52.   Varba_Victory_Var = 2 # Set variable ID.
  53.  
  54.   # The value of PK8::Varba_Victory_Var controls the battle theme.
  55.   #          [id] = [Music File, Volume, Pitch]
  56.   Varba_Victory[1] = ["002-Victory02", 100, 100]
  57.   Varba_Victory[2] = ["003-Victory03", 100, 100]
  58. end
  59.  
  60. #==============================================================================
  61. # ** Scene_Battle
  62. #------------------------------------------------------------------------------
  63. #  This class performs battle screen processing.
  64. #==============================================================================
  65. class Scene_Battle
  66.   alias_method(:pk8_var_battle_victoryme_start_phase_5, :start_phase5)
  67.   def start_phase5
  68.     pk8_var_battle_victoryme_start_phase_5
  69.     start_var_battle_victoryme
  70.   end
  71.  
  72.   #----------------------------------------------------------------------------
  73.   # * Start Troop Victory
  74.   #----------------------------------------------------------------------------
  75.   def start_var_battle_victoryme
  76.     PK8::Varba_Victory.each_key { | i |
  77.     # If Variable ID value equals the key.
  78.     if $game_variables[PK8::Varba_Victory_Var] == i
  79.       if PK8::Varba_Victory[i][0] != nil and !PK8::Varba_Victory[i][0].empty?
  80.         # Sets ME volume to 100 if nil.
  81.         PK8::Varba_Victory[i][1] = 100 if PK8::Varba_Victory[i][1] == nil
  82.         # Sets ME pitch to 100 if nil.
  83.         PK8::Varba_Victory[i][2] = 100 if PK8::Varba_Victory[i][2] == nil
  84.         # Plays ME.
  85.         Audio.me_play("Audio/ME/#{PK8::Varba_Victory[i][0]}",
  86.         PK8::Varba_Victory[i][1], PK8::Varba_Victory[i][2])
  87.       end
  88.       break
  89.     end }
  90.   end
  91. end
Expand to see the code.


Instructions
Instructions are in the script.

FAQ
Awaiting question.

Compatibility
Aliases start_phase5 of Scene_Battle.

Credits and Thanks
If it weren't for JoeYoung's original request, I wouldn't have made this script.

Author's Notes
After working on Individual Troop Victory MEs, I wanted to work on this script. I was pretty bored so yeah.

Terms and Conditions
Credit me. :3
I've told you about a few things in IRC a few days ago already, but let's give ya some advanced critique here, shall we... I hope it helps ya ^^"

Content Hidden Spoiler
So yeah, I've already told you I don't like the PK8 class, because it's simply not needed - even in a script with 500 lines plus, you should be able to point people to the places within your script where they can make customizations - nevermind a script with an effective < 30 lines of code.
I also heavily dislike the naming, not because I don't like your nickname, but because it doesn't say anything about the purpose of the class itself. That's a very important thing in scripts, for reasons like interchangeability and understanding.

Now just for a second, imagine I'm with the supporting team of those customization classes at the top of scripts (which definately exist, even though it's ineffective), guess what I'd have a problem with? Exactly, this line:
  1. Varba_Victory = {} # Do not touch this.
Expand to see the code.
Pretty pointless to put a variable like that in the CUSTOMIZATION area, isn't it? It belongs into Scene_Battle.initialize, and under no circumstances is meant to be a constant, considering you change it later in the script...

You can argue about if it's making sense to call a seperate method from start_phase_5... personally, I'd put the whole start_var_battle_victoryme method in the aliased start_phase_5. Nevertheless, your alias name again is not quite efficient, since it's way longer than expected. Calling it 'varbame_start_phase_5' is perfectly sufficient, for example. Note how you don't use your previous notation of 'Varba' here anymore, which is additionally confusing.

The core method's comment says Troop Victory :/

Within your core method, you got your identation messed up... it's supposed to be like this (your commenting is good, but I took it out for the purpose of adding my own in there):
  1.  def start_var_battle_victoryme
  2.     PK8::Varba_Victory.each_key { | i |
  3.       if $game_variables[PK8::Varba_Victory_Var] == i # should be the other way round, as you try to compare i with the variable... just cosmetics really though
  4.         if PK8::Varba_Victory[i][0] != nil and !PK8::Varba_Victory[i][0].empty?
  5.           PK8::Varba_Victory[i][1] = 100 if PK8::Varba_Victory[i][1] == nil
  6.           PK8::Varba_Victory[i][2] = 100 if PK8::Varba_Victory[i][2] == nil
  7.           Audio.me_play("Audio/ME/#{PK8::Varba_Victory[i][0]}", PK8::Varba_Victory[i][1], PK8::Varba_Victory[i][2]) # yep, single line!
  8.         end
  9.         break
  10.       end
  11.     }
  12.   end
Expand to see the code.


So much for the improvement part, let's note some positive aspects to it... most of these origin from it being quite a short script altogether, which of course make it easily overviewable and understandable. It's also well commented (I prefer behind-the-coding commenting, but it's a matter of what one'S used to really), with the exception of the Troop header still being in there... you have a good compatibility noting which you definately should keep up. And yeah, after all, it's a small yet useful script to enhance RMXPs base range of functionality, which is stuff we should get more.


So yeah, I hope you don't think I wanna make ya look bad or anything ^^" because I don't. Just trying to help ya out here.


Keep up the good work.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=68374