The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => VXA Scripts Database => Topic started by: DoctorTodd on June 25, 2012, 10:41:52 PM

Title: DT's Difficulty
Post by: DoctorTodd on June 25, 2012, 10:41:52 PM
DT's Difficulty
Version: 1.0.0
Author: DoctorTodd
Date: 6/25/2012

Version History



Planned Future Versions


Description


 Lets the player select the games difficulty.

Features


Screenshots
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fdesmond.imageshack.us%2FHimg689%2Fscaled.php%3Fserver%3D689%26amp%3Bfilename%3Ddifscreenshot.png%26amp%3Bres%3Dlanding&hash=e8107b4724c96cf171f16f63c680ffc8dea5c6a7)


Instructions

Paste above main.
Call using SceneManager.call(Scene_Difficulty)

Script


Code: [Select]
#===============================================================================
#
# DT's Difficulty
# Author: DoctorTodd
# Date (06/24/2012)
# Version: (1.0.0) (VXA)
# Level: (Medium)
# Email: Todd@beacongames.com
#
#===============================================================================
#
# NOTES: 1)This script will only work with ace.
#        2)A difficulty must be selected before the first battle or the game WILL
#        CRASH.
#
#===============================================================================
#
# Description: Lets the player select the games difficulty.
#
# Credits: Me (DoctorTodd), D&P3 for saving bug fix.
#
#===============================================================================
#
# Instructions
# Paste above main.
#
#===============================================================================
#
# Free for any use as long as I'm credited.
#
#===============================================================================
#
# Editing begins 38 and ends on 71.
#
#===============================================================================
module TODDDIFFICULTY
 
  #Easy Text.
  EASYT = "Easy"
 
  #Normal Text.
  NORMALT = "Normal"
 
  #Heroic Text.
  HEROICT = "Heroic"
 
  #Hard Text.
  HARDT = "Hard"
 
  #Easy enemy parameters multiplier.
  EASYM = 0.5
 
  #Heroic enemy parameters multiplier (Normal is skipped since it's what put
  #you into the database).
  HEROICM = 1.5
 
  #Hard enemy parameters multiplier.
  HARDM = 2
 
  #The text above where the selection is made.
  TEXT = "Please select a difficulty:"
 
  #Menu command?
  MENU = true
 
  #Sound effect to play when difficulty is selected.
  SE = "Darkness8"
 
  #Switch to allow cancelling the difficulty selection.
  #MUST NOT BE ON WHEN SELECTING FOR THE FIRST TIME.
  SWITCH = 5

end
#==============================================================================
# ** Game_Enemy
#------------------------------------------------------------------------------
#  This class handles enemies. It used within the Game_Troop class
# ($game_troop).
#==============================================================================

class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # * Get Base Value of Parameter
  #--------------------------------------------------------------------------
  alias todd_difficulty_gmen_param_base param_base
  def param_base(param_id, *args)
  n1 = todd_difficulty_gmen_param_base(param_id, *args)
  n2 = case $game_system.todd_difficulty
  when 0 then TODDDIFFICULTY::EASYM
  when 1 then 1
  when 2 then TODDDIFFICULTY::HEROICM
  when 3 then TODDDIFFICULTY::HARDM
  end
  return n1 * n2
 end
end


#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles system data. It saves the disable state of saving and
# menus. Instances of this class are referenced by $game_system.
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :todd_difficulty            # save forbidden
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias todd_difficulty_gamesystem_init initialize
  def initialize
    @todd_difficulty = 0
    todd_difficulty_gamesystem_init
  end
end

#==============================================================================
# ** Window_DifficultySelection
#==============================================================================

class Window_DifficultySelection < Window_HorzCommand
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0)
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    Graphics.width/2 + 20
  end
  #--------------------------------------------------------------------------
  # * Get Digit Count
  #--------------------------------------------------------------------------
  def col_max
    return 4
  end
  #--------------------------------------------------------------------------
  # * Create Command List
  #--------------------------------------------------------------------------
  def make_command_list
    add_command(TODDDIFFICULTY::EASYT,     :easy)
    add_command(TODDDIFFICULTY::NORMALT,   :normal)
    add_command(TODDDIFFICULTY::HEROICT,    :heroic)
    add_command(TODDDIFFICULTY::HARDT, :hard)
  end
end
#==============================================================================
# ** Window_DifficultyName
#==============================================================================

class Window_DifficultyName < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, window_width, fitting_height(1))
    refresh
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return Graphics.width/2 + 20
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_text(15, -27, 400, 80, TODDDIFFICULTY::TEXT)
  end
end
#==============================================================================
# ** Scene_Difficulty
#==============================================================================

class Scene_Difficulty < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
    super
    create_command_window
    create_name_window
  end
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  def create_command_window
    @command_window = Window_DifficultySelection.new
    @command_window.set_handler(:easy,      method(:command_easy))
    @command_window.set_handler(:normal,     method(:command_normal))
    @command_window.set_handler(:heroic,     method(:command_heroic))
    @command_window.set_handler(:hard,    method(:command_hard))
    @command_window.set_handler(:cancel,    method(:return_scene))if $game_switches[TODDDIFFICULTY::SWITCH] == true
    @command_window.x = Graphics.width/2 - 170
    @command_window.y = Graphics.height/2 - 50
  end
  #--------------------------------------------------------------------------
  # * Create Difficulty Window
  #--------------------------------------------------------------------------
  def create_name_window
    @name_window = Window_DifficultyName.new
    @name_window.x = Graphics.width/2 - 170
    @name_window.y = Graphics.height/2 - 97
  end
  #--------------------------------------------------------------------------
  # * [easy] Command
  #--------------------------------------------------------------------------
  def command_easy
    $game_system.todd_difficulty = 0
    Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    return_scene
   end
  #--------------------------------------------------------------------------
  # * [normal] Command
  #--------------------------------------------------------------------------
  def command_normal
    $game_system.todd_difficulty = 1
    Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    return_scene
   end
  #--------------------------------------------------------------------------
  # * [heroic] Command
  #--------------------------------------------------------------------------
  def command_heroic
    $game_system.todd_difficulty = 2
      Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    return_scene
   end
  #--------------------------------------------------------------------------
  # * [hard] Command
  #--------------------------------------------------------------------------
  def command_hard
    $game_system.todd_difficulty = 3
        Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    return_scene
   end
 end
 if TODDDIFFICULTY::MENU == true
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs the menu screen processing.
#==============================================================================

class Scene_Menu < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  alias todd_dif_menu_add_menu_command create_command_window
  def create_command_window
    todd_dif_menu_add_menu_command
    @command_window.set_handler(:dif,      method(:command_dif))
  end
end
  #--------------------------------------------------------------------------
  # * [Difficulty] Command
  #--------------------------------------------------------------------------
  def command_dif
  SceneManager.call(Scene_Difficulty)
  end
end

if TODDDIFFICULTY::MENU == true
#==============================================================================
# ** Window_MenuCommand
#------------------------------------------------------------------------------
#  This command window appears on the menu screen.
#==============================================================================

class Window_MenuCommand < Window_Command
  #--------------------------------------------------------------------------
  # * Add Main Commands to List
  #--------------------------------------------------------------------------
  alias todd_dif_menu_command_add_to_menu add_main_commands
  def add_main_commands
     todd_dif_menu_command_add_to_menu
    add_command("Difficulty",   :dif,   main_commands_enabled)
  end
 end
end



Credit/Thanks



Support


Post here for quickest support, or send an email to Todd@beacongames.com.

Known Compatibility Issues

This script is incompatible with every ABS (Sapphire, XAS, ect... ).

Author's Notes


This is actually my second attempt at a script like this, a few months ago I tried to modify the enemy parameters in Game_Battler and I kept getting an error so I quit. I just now realized that it would have also modified the actors, making the entire script completely pointless.

Restrictions

Check the header of the script.
Title: Re: DT's Difficulty
Post by: Wiimeiser on June 26, 2012, 02:22:08 AM
How could this work with Yanfly's Enemy Levels and System Game Options? Maybe add an option to change levels rather than stat? Also I'd swap Hard and Heroic(at least in name, Heroic sounds way harder). Just sayin'.
Title: Re: DT's Difficulty
Post by: DoctorTodd on June 26, 2012, 02:30:47 AM
System options, yes. Enemy levels, May be. I chose the names based upon halo 3 (except for hard). Either way you get to customize the name.
Title: Re: DT's Difficulty
Post by: Revtattertot on June 26, 2012, 03:05:27 AM
This script seems really good for like a Touhou game, don't you think?
Title: Re: DT's Difficulty
Post by: DoctorTodd on June 26, 2012, 03:39:49 AM
I've never played one, so may be.  :)
Title: Re: DT's Difficulty
Post by: pacdiggity on June 27, 2012, 12:08:03 PM
Just looked through a bit of your code, and while I do say that there's nothing wrong with what you've done, there are more efficient and safer ways for what you've done. Mainly, the core adjustment made with this script, the Game_Enemy#param_base method you overwrote. You may have thought about how to alias this method, and there's nothing wrong with not seeing it; it's not as clear as most methods are.

Code: [Select]
class Game_Enemy < Game_Battler
  alias todd_difficulty_gmen_param_base param_base
  def param_base(param_id, *args)
  n1 = todd_difficulty_gmen_param_base(param_id, *args)
  n2 = case $difficulty
  when 0 then TODDDIFFICULTY::EASYM
  when 1 then 1
  when 2 then TODDDIFFICULTY::HEROICM
  when 3 then TODDDIFFICULTY::HARDM
  end
  return n1 * n2
 end
end

Would be the way I'd do it. There's nothing necessarily wrong with the way you've done it, I'm simply paranoid about overwriting methods.
Title: Re: DT's Difficulty
Post by: Wiimeiser on June 27, 2012, 12:48:50 PM
I also noticed there's no way to call the scene... Unless I'm missing something?
Title: Re: DT's Difficulty
Post by: pacdiggity on June 27, 2012, 01:06:02 PM
You can call the scene with Scene_Difficulty.new in a script call, and there is also an option to include it in the main menu.
Title: Re: DT's Difficulty
Post by: DoctorTodd on June 27, 2012, 06:27:10 PM
@Pacman Alright I'll check to make sure there's a safer way next time.

@Wiimeiser What Pacman said, I'll update the topic to include it.
Title: Re: DT's Difficulty
Post by: D&P3 on July 05, 2012, 10:59:17 AM
Seems like a good idea :)

I've got suggestion to allow changing the battle theme depending on which difficulty is selected :D
Of course that's only if the creator actually wants to allow the battle theme to be changed.
Title: Re: DT's Difficulty
Post by: DoctorTodd on July 05, 2012, 06:02:54 PM
I can probably add that feature today.  :)

I may do it tomorrow, I tried it today and this happened.  :P
Title: Re: DT's Difficulty
Post by: D&P3 on July 09, 2012, 03:29:42 PM
Whoa, that's no good :-\

I don't work with VXA, is it the same method when changing the battle theme?



Actually this reminds me of someone at my Uni who constantly manages to crash visual studio, not memory leaks, but actually breaks the program.
It's become a usual thing to blame him whenever something goes wrong on anyone's game :P
Title: Re: DT's Difficulty
Post by: Wiimeiser on July 09, 2012, 03:55:39 PM
What maker do you use?
Title: Re: DT's Difficulty
Post by: DoctorTodd on July 09, 2012, 06:04:32 PM
lol  ;D

I forgot about working on this, I'll try to release the new version this week.
Title: Re: DT's Difficulty
Post by: DoctorTodd on July 20, 2012, 11:52:07 PM
I still haven't done the battle themes yet, I've been busy. I don't know when I can get to it, sorry. Any way this script is incompatible with every ABS (Sapphire, XAS, ect... ). You can run the game but you will not be able to load.
Title: Re: DT's Difficulty
Post by: Helladen on July 23, 2012, 09:35:05 AM
I like KGC's difficulty script better, too bad someone doesn't convert it to Ace.
Title: Re: DT's Difficulty
Post by: username78 on July 27, 2012, 03:33:13 PM
When I use the the script call Scene_Difficulty.new, it doesn't call the screen up. I know you can have it in the menu (which I plan to) but I want to make it so you choose at the very beginning and the screen won't come up. Can anyone help me with this?
Title: Re: DT's Difficulty
Post by: DoctorTodd on July 27, 2012, 03:36:24 PM
Code: [Select]
SceneManager.call(Scene_Difficulty)
Title: Re: DT's Difficulty
Post by: username78 on July 28, 2012, 03:52:43 AM
Thank you!
Title: Re: DT's Difficulty
Post by: username78 on August 13, 2012, 02:24:39 AM
Unfortunatly, I seem to have run into another problem. Let's say I pick a difficulty (it doesn't matter in this case) and I walk around, get into fights and it works fine. I save and then load the fine, get into a fight and again, it works fine. But when I completely close the game, load a file and go into a battle, the game crashes. I know why it crashes. The error is the error when a difficulty has not been chosen which leads to me to the question for this script to work, does the difficulty have to be chosen every time the game is opened? I can't seem to find a solution to this (it crashes every time) so if you could help me out I would really appreciate it.
Thank you
Title: Re: DT's Difficulty
Post by: DoctorTodd on August 13, 2012, 02:28:30 AM
I managed to recreate the problem, I'll try to fix it tomorrow since I have to head to bed.
Title: Re: DT's Difficulty
Post by: username78 on August 13, 2012, 02:42:16 AM
Thanks for helping with this.
Title: Re: DT's Difficulty
Post by: DoctorTodd on August 14, 2012, 02:13:37 AM
Sorry I wasn't able to try and fix it today, I'm been pretty busy but I may be able to fix it this week.
Title: Re: DT's Difficulty
Post by: username78 on August 15, 2012, 03:43:17 PM
No problem, take your time!
Title: Re: DT's Difficulty
Post by: DoctorTodd on August 17, 2012, 11:00:21 PM
I'm sorry for making you wait so long, here's a fixed version.
Turns out all I had to do was add $difficulty = $difficulty to battle manager.
Code: [Select]
#===============================================================================
#
# DT's Difficulty
# Author: DoctorTodd
# Date (06/24/2012)
# Version: (1.0.0) (VXA)
# Level: (Medium)
# Email: Todd@beacongames.com
#
#===============================================================================
#
# NOTES: 1)This script will only work with ace.
#        2)A difficulty must be selected before the first battle or the game WILL
#        CRASH.
#
#===============================================================================
#
# Description: Lets the player select the games difficulty.
#
# Credits: Me (DoctorTodd)
#
#===============================================================================
#
# Instructions
# Paste above main.
#
#===============================================================================
#
# Free for any use as long as I'm credited.
#
#===============================================================================
#
# Editing begins 38 and ends on 71.
#
#===============================================================================
module TODDDIFFICULTY
 
  #Easy Text.
  EASYT = "Easy"
 
  #Normal Text.
  NORMALT = "Normal"
 
  #Heroic Text.
  HEROICT = "Heroic"
 
  #Hard Text.
  HARDT = "Hard"
 
  #Easy enemy parameters multiplier.
  EASYM = 0.5
 
  #Heroic enemy parameters multiplier (Normal is skipped since it's what put
  #you into the database).
  HEROICM = 1.5
 
  #Hard enemy parameters multiplier.
  HARDM = 2
 
  #The text above where the selection is made.
  TEXT = "Please select a difficulty:"
 
  #Menu command?
  MENU = true
 
  #Sound effect to play when difficulty is selected.
  SE = "Darkness8"
 
  #Switch to allow cancelling the difficulty selection.
  #MUST NOT BE ON WHEN SELECTING FOR THE FIRST TIME.
  SWITCH = 5

end
#==============================================================================
# ** Game_Enemy
#------------------------------------------------------------------------------
#  This class handles enemies. It used within the Game_Troop class
# ($game_troop).
#==============================================================================

class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # * Get Base Value of Parameter
  #--------------------------------------------------------------------------
  def param_base(param_id)
  case $difficulty
  when 0
  enemy.params[param_id] * TODDDIFFICULTY::EASYM
  when 1
  enemy.params[param_id]
  when 2
  enemy.params[param_id] * TODDDIFFICULTY::HEROICM
  when 3
  enemy.params[param_id] * TODDDIFFICULTY::HARDM
  else
  enemy.params[param_id]
  end
 end
end
#==============================================================================
# ** BattleManager
#------------------------------------------------------------------------------
#  This module manages battle progress.
#==============================================================================

module BattleManager
  #--------------------------------------------------------------------------
  # * Setup
  #--------------------------------------------------------------------------
  def self.setup(troop_id, can_escape = true, can_lose = false)
    init_members
    $difficulty = $difficulty
    $game_troop.setup(troop_id)
    @can_escape = can_escape
    @can_lose = can_lose
    make_escape_ratio
  end
end
#==============================================================================
# ** Window_DifficultySelection
#==============================================================================

class Window_DifficultySelection < Window_HorzCommand
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0)
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    Graphics.width/2 + 20
  end
  #--------------------------------------------------------------------------
  # * Get Digit Count
  #--------------------------------------------------------------------------
  def col_max
    return 4
  end
  #--------------------------------------------------------------------------
  # * Create Command List
  #--------------------------------------------------------------------------
  def make_command_list
    add_command(TODDDIFFICULTY::EASYT,     :easy)
    add_command(TODDDIFFICULTY::NORMALT,   :normal)
    add_command(TODDDIFFICULTY::HEROICT,    :heroic)
    add_command(TODDDIFFICULTY::HARDT, :hard)
  end
end
#==============================================================================
# ** Window_DifficultyName
#==============================================================================

class Window_DifficultyName < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, window_width, fitting_height(1))
    refresh
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return Graphics.width/2 + 20
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_text(15, -27, 400, 80, TODDDIFFICULTY::TEXT)
  end
end
#==============================================================================
# ** Scene_Difficulty
#==============================================================================

class Scene_Difficulty < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
    super
    create_command_window
    create_name_window
  end
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  def create_command_window
    @command_window = Window_DifficultySelection.new
    @command_window.set_handler(:easy,      method(:command_easy))
    @command_window.set_handler(:normal,     method(:command_normal))
    @command_window.set_handler(:heroic,     method(:command_heroic))
    @command_window.set_handler(:hard,    method(:command_hard))
    @command_window.set_handler(:cancel,    method(:return_scene))if $game_switches[TODDDIFFICULTY::SWITCH] == true
    @command_window.x = Graphics.width/2 - 170
    @command_window.y = Graphics.height/2 - 50
  end
  #--------------------------------------------------------------------------
  # * Create Difficulty Window
  #--------------------------------------------------------------------------
  def create_name_window
    @name_window = Window_DifficultyName.new
    @name_window.x = Graphics.width/2 - 170
    @name_window.y = Graphics.height/2 - 97
  end
  #--------------------------------------------------------------------------
  # * [easy] Command
  #--------------------------------------------------------------------------
  def command_easy
    $difficulty = 0
    Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    return_scene
   end
  #--------------------------------------------------------------------------
  # * [normal] Command
  #--------------------------------------------------------------------------
  def command_normal
    $difficulty = 1
    Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    return_scene
   end
  #--------------------------------------------------------------------------
  # * [heroic] Command
  #--------------------------------------------------------------------------
  def command_heroic
    $difficulty = 2
      Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    return_scene
   end
  #--------------------------------------------------------------------------
  # * [hard] Command
  #--------------------------------------------------------------------------
  def command_hard
    $difficulty = 3
        Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    return_scene
   end
 end
 if TODDDIFFICULTY::MENU == true
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs the menu screen processing.
#==============================================================================

class Scene_Menu < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  alias todd_dif_menu_add_menu_command create_command_window
  def create_command_window
    todd_dif_menu_add_menu_command
    @command_window.set_handler(:dif,      method(:command_dif))
  end
end
  #--------------------------------------------------------------------------
  # * [Difficulty] Command
  #--------------------------------------------------------------------------
  def command_dif
  SceneManager.call(Scene_Difficulty)
  end
end

if TODDDIFFICULTY::MENU == true
#==============================================================================
# ** Window_MenuCommand
#------------------------------------------------------------------------------
#  This command window appears on the menu screen.
#==============================================================================

class Window_MenuCommand < Window_Command
  #--------------------------------------------------------------------------
  # * Add Main Commands to List
  #--------------------------------------------------------------------------
  alias todd_dif_menu_command_add_to_menu add_main_commands
  def add_main_commands
     todd_dif_menu_command_add_to_menu
    add_command("Difficulty",   :dif,   main_commands_enabled)
  end
 end
end
Title: Re: DT's Difficulty
Post by: username78 on August 20, 2012, 03:01:29 AM
Works perfectly, thank you so much!!
Title: Re: DT's Difficulty
Post by: DoctorTodd on August 20, 2012, 12:03:30 PM
Your welcome, sorry about that bug.
Title: Re: DT's Difficulty
Post by: DoctorPsycho7 on January 08, 2013, 11:27:35 PM
Hey, so I have a question regarding difficulty and saving / loading.

For the purposes of my game, I disabled the ability to select the difficulty from the main menu (Just because I don't want my friends to say they "beat" my game on a super hard difficulty by playing easy-mode all the way through and then switching the difficulty on the last boss).

Problem with my situation is that I have the difficulty selection at the start of the game, and the script will run fine when it comes to the initial run.

However, I noticed that when I save and close the game out entirely, the game seems to essentially "forget" what difficulty I originally selected, and will then just use normal difficulty by default.

Is there some piece of code or way to ensure that the game will remember what difficulty I've chosen, instead of having it revert back to normal mode every time I load up the game?
Title: Re: DT's Difficulty
Post by: DoctorTodd on January 09, 2013, 12:01:59 AM
I'll try to get around fixing it, I'm really busy right now. Unfortunately RPG Maker doesn't have a simple command like PlayerPrefs.SetInt("Difficulty", 1). I tried for a little while using a bunch of stuff in the data manager but it doesn't seem to work.
Title: Re: DT's Difficulty
Post by: D&P3 on January 09, 2013, 12:16:14 AM
Code: [Select]
#===============================================================================
#
# DT's Difficulty
# Author: DoctorTodd
# Date (06/24/2012)
# Version: (1.0.0) (VXA)
# Level: (Medium)
# Email: Todd@beacongames.com
#
#===============================================================================
#
# NOTES: 1)This script will only work with ace.
#        2)A difficulty must be selected before the first battle or the game WILL
#        CRASH.
#
#===============================================================================
#
# Description: Lets the player select the games difficulty.
#
# Credits: Me (DoctorTodd)
#
#===============================================================================
#
# Instructions
# Paste above main.
#
#===============================================================================
#
# Free for any use as long as I'm credited.
#
#===============================================================================
#
# Editing begins 38 and ends on 71.
#
#===============================================================================
module TODDDIFFICULTY
 
  #Easy Text.
  EASYT = "Easy"
 
  #Normal Text.
  NORMALT = "Normal"
 
  #Heroic Text.
  HEROICT = "Heroic"
 
  #Hard Text.
  HARDT = "Hard"
 
  #Easy enemy parameters multiplier.
  EASYM = 0.5
 
  #Heroic enemy parameters multiplier (Normal is skipped since it's what put
  #you into the database).
  HEROICM = 1.5
 
  #Hard enemy parameters multiplier.
  HARDM = 2
 
  #The text above where the selection is made.
  TEXT = "Please select a difficulty:"
 
  #Menu command?
  MENU = true
 
  #Sound effect to play when difficulty is selected.
  SE = "Darkness8"
 
  #Switch to allow cancelling the difficulty selection.
  #MUST NOT BE ON WHEN SELECTING FOR THE FIRST TIME.
  SWITCH = 5

end
#==============================================================================
# ** Game_Enemy
#------------------------------------------------------------------------------
#  This class handles enemies. It used within the Game_Troop class
# ($game_troop).
#==============================================================================

class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # * Get Base Value of Parameter
  #--------------------------------------------------------------------------
  alias todd_difficulty_gmen_param_base param_base
  def param_base(param_id, *args)
  n1 = todd_difficulty_gmen_param_base(param_id, *args)
  n2 = case $game_system.todd_difficulty
  when 0 then TODDDIFFICULTY::EASYM
  when 1 then 1
  when 2 then TODDDIFFICULTY::HEROICM
  when 3 then TODDDIFFICULTY::HARDM
  end
  return n1 * n2
 end
end


#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles system data. It saves the disable state of saving and
# menus. Instances of this class are referenced by $game_system.
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :todd_difficulty            # save forbidden
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias todd_difficulty_gamesystem_init initialize
  def initialize
    @todd_difficulty = 0
    todd_difficulty_gamesystem_init
  end
end

#==============================================================================
# ** Window_DifficultySelection
#==============================================================================

class Window_DifficultySelection < Window_HorzCommand
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0)
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    Graphics.width/2 + 20
  end
  #--------------------------------------------------------------------------
  # * Get Digit Count
  #--------------------------------------------------------------------------
  def col_max
    return 4
  end
  #--------------------------------------------------------------------------
  # * Create Command List
  #--------------------------------------------------------------------------
  def make_command_list
    msgbox_p($game_system.todd_difficulty)
    add_command(TODDDIFFICULTY::EASYT,     :easy)
    add_command(TODDDIFFICULTY::NORMALT,   :normal)
    add_command(TODDDIFFICULTY::HEROICT,    :heroic)
    add_command(TODDDIFFICULTY::HARDT, :hard)
  end
end
#==============================================================================
# ** Window_DifficultyName
#==============================================================================

class Window_DifficultyName < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, window_width, fitting_height(1))
    refresh
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return Graphics.width/2 + 20
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_text(15, -27, 400, 80, TODDDIFFICULTY::TEXT)
  end
end
#==============================================================================
# ** Scene_Difficulty
#==============================================================================

class Scene_Difficulty < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
    super
    create_command_window
    create_name_window
  end
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  def create_command_window
    @command_window = Window_DifficultySelection.new
    @command_window.set_handler(:easy,      method(:command_easy))
    @command_window.set_handler(:normal,     method(:command_normal))
    @command_window.set_handler(:heroic,     method(:command_heroic))
    @command_window.set_handler(:hard,    method(:command_hard))
    @command_window.set_handler(:cancel,    method(:return_scene))if $game_switches[TODDDIFFICULTY::SWITCH] == true
    @command_window.x = Graphics.width/2 - 170
    @command_window.y = Graphics.height/2 - 50
  end
  #--------------------------------------------------------------------------
  # * Create Difficulty Window
  #--------------------------------------------------------------------------
  def create_name_window
    @name_window = Window_DifficultyName.new
    @name_window.x = Graphics.width/2 - 170
    @name_window.y = Graphics.height/2 - 97
  end
  #--------------------------------------------------------------------------
  # * [easy] Command
  #--------------------------------------------------------------------------
  def command_easy
    $game_system.todd_difficulty = 0
    Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    return_scene
   end
  #--------------------------------------------------------------------------
  # * [normal] Command
  #--------------------------------------------------------------------------
  def command_normal
    $game_system.todd_difficulty = 1
    Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    return_scene
   end
  #--------------------------------------------------------------------------
  # * [heroic] Command
  #--------------------------------------------------------------------------
  def command_heroic
    $game_system.todd_difficulty = 2
      Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    return_scene
   end
  #--------------------------------------------------------------------------
  # * [hard] Command
  #--------------------------------------------------------------------------
  def command_hard
    $game_system.todd_difficulty = 3
        Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    return_scene
   end
 end
 if TODDDIFFICULTY::MENU == true
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs the menu screen processing.
#==============================================================================

class Scene_Menu < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  alias todd_dif_menu_add_menu_command create_command_window
  def create_command_window
    todd_dif_menu_add_menu_command
    @command_window.set_handler(:dif,      method(:command_dif))
  end
end
  #--------------------------------------------------------------------------
  # * [Difficulty] Command
  #--------------------------------------------------------------------------
  def command_dif
  SceneManager.call(Scene_Difficulty)
  end
end

if TODDDIFFICULTY::MENU == true
#==============================================================================
# ** Window_MenuCommand
#------------------------------------------------------------------------------
#  This command window appears on the menu screen.
#==============================================================================

class Window_MenuCommand < Window_Command
  #--------------------------------------------------------------------------
  # * Add Main Commands to List
  #--------------------------------------------------------------------------
  alias todd_dif_menu_command_add_to_menu add_main_commands
  def add_main_commands
     todd_dif_menu_command_add_to_menu
    add_command("Difficulty",   :dif,   main_commands_enabled)
  end
 end
end

Saves now :)
Look into attrs if you ever make a comeback to Ruby :D
Also replaced the Param_Base with Pacman's method :pacman:
Title: Re: DT's Difficulty
Post by: DoctorPsycho7 on January 09, 2013, 12:24:18 AM
Man, you're some kind of coding wizard or something to figure out the issue so quickly.

One thing that I'm noticing when I'm trying out your script though: when I initially start a new game / character, there are two windows that popup (one immediately after another) that both just say "0". I can hit okay for both of them and there don't seem to be any errors created, but is there some way to hide those windows?

Again though, thank you very much for your hard work and getting back to me on this issue so fast.
Title: Re: DT's Difficulty
Post by: pacdiggity on January 09, 2013, 12:28:55 AM
Also replaced the Param_Base with Pacman's method :pacman:

 :gracie:

Also it seems you forgot to take out your 'everything's working' check, Chris. DoctorPsycho, find the line that says:
Code: [Select]
    msgbox_p($game_system.todd_difficulty)
and delete it. I think that's it.
Title: Re: DT's Difficulty
Post by: DoctorTodd on January 09, 2013, 12:31:57 AM
Thanks for fixing it D&P3!

Quote
Look into attrs if you ever make a comeback to Ruby
I'll make sure to. Though I highly doubt I will. Now that I'm using Unity and Ruby was never really my language. I learned more with JavaScript then 1/20 of the time I spent with Ruby.
Title: Re: DT's Difficulty
Post by: DoctorPsycho7 on January 09, 2013, 12:39:00 AM
And that takes care of my popup problem! Thank you to all three of you guys for your superb help. You're fantastic.
Title: Re: DT's Difficulty
Post by: D&P3 on January 09, 2013, 12:44:36 AM
Also it seems you forgot to take out your 'everything's working' check, Chris. DoctorPsycho, find the line that says:
Code: [Select]
    msgbox_p($game_system.todd_difficulty)
and delete it. I think that's it.
That was a derp on my part :|
My excuse is that I was multitasking on scripts :P
Title: Re: DT's Difficulty
Post by: pacdiggity on January 09, 2013, 12:45:10 AM
No need to worry, I've lost count of how many times I've done that :P
Title: Re: DT's Difficulty
Post by: drakenkanon on April 03, 2013, 12:22:22 PM
Is there any way to get this script working for ABS systems? This sounds awesome, and I was very sad when I read that it was uncompatible with ABS systems.

Kind regards,
Drakenkanon
Title: Re: DT's Difficulty
Post by: DoctorTodd on April 03, 2013, 08:39:25 PM
I only tested it with Khas' ABS. Try it any way, this was a while ago and the ABS may haven't have been the issue. The problem was the game didn't load at all, the problem went away after I removed Khas' ABS but it came back. So it may actually work fine. I can't actually help you with this since I don't have RPG Maker any more.
Title: Re: DT's Difficulty
Post by: stucko on May 16, 2013, 11:34:27 AM
Hey DoctorTodd, I've just put the script in, but right at the start of my game, just before it calls the script, this box appears with a 0 in it and an ok button. After pressing ok, the box disappears, then reappears. When i press ok again, it disappears, and the script loads. I've attached a screenshot of it. Just wondering if you've ever encountered this error and might know a way around it. Would be really thankful for any help  :)
Title: Re: DT's Difficulty
Post by: DoctorTodd on May 16, 2013, 12:24:54 PM
Also it seems you forgot to take out your 'everything's working' check, Chris. DoctorPsycho, find the line that says:
Code: [Select]
    msgbox_p($game_system.todd_difficulty)
and delete it. I think that's it.
Doing this will fix it.
Title: Re: DT's Difficulty
Post by: stucko on May 16, 2013, 09:27:03 PM
thanks. everything's fine now  :)
Title: Re: DT's Difficulty
Post by: Mushu on June 22, 2013, 09:47:12 PM
I really like this script, I'm going to use it.

Edit: Is there a way the game can check the difficulty? That way you could make some way to reward harder difficulties more.
Title: Re: DT's Difficulty
Post by: DoctorTodd on June 22, 2013, 10:13:55 PM
There is now. The variable ID in the settings will contain the difficulty number (0-3).
Code: [Select]
#===============================================================================
#
# DT's Difficulty
# Author: DoctorTodd
# Date (06/24/2012)
# Version: (1.0.0) (VXA)
# Level: (Medium)
# Email: Todd@beacongames.com
#
#===============================================================================
#
# NOTES: 1)This script will only work with ace.
#        2)A difficulty must be selected before the first battle or the game WILL
#        CRASH.
#
#===============================================================================
#
# Description: Lets the player select the games difficulty.
#
# Credits: Me (DoctorTodd), D&P3 for saving bug fix.
#
#===============================================================================
#
# Instructions
# Paste above main.
#
#===============================================================================
#
# Free for any use as long as I'm credited.
#
#===============================================================================
#
# Editing begins 38 and ends on 71.
#
#===============================================================================
module TODDDIFFICULTY
 
  #Easy Text.
  EASYT = "Easy"
 
  #Normal Text.
  NORMALT = "Normal"
 
  #Heroic Text.
  HEROICT = "Heroic"
 
  #Hard Text.
  HARDT = "Hard"
 
  #Easy enemy parameters multiplier.
  EASYM = 0.5
 
  #Heroic enemy parameters multiplier (Normal is skipped since it's what put
  #you into the database).
  HEROICM = 1.5
 
  #Hard enemy parameters multiplier.
  HARDM = 2
 
  #The text above where the selection is made.
  TEXT = "Please select a difficulty:"
 
  #Menu command?
  MENU = true
 
  #Sound effect to play when difficulty is selected.
  SE = "Darkness8"
 
  #Switch to allow cancelling the difficulty selection.
  #MUST NOT BE ON WHEN SELECTING FOR THE FIRST TIME.
  SWITCH = 5

  #Variable ID that contains the current difficulty.
  VARIABLE = 1

end
#==============================================================================
# ** Game_Enemy
#------------------------------------------------------------------------------
#  This class handles enemies. It used within the Game_Troop class
# ($game_troop).
#==============================================================================

class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # * Get Base Value of Parameter
  #--------------------------------------------------------------------------
  alias todd_difficulty_gmen_param_base param_base
  def param_base(param_id, *args)
  n1 = todd_difficulty_gmen_param_base(param_id, *args)
  n2 = case $game_system.todd_difficulty
  when 0 then TODDDIFFICULTY::EASYM
  when 1 then 1
  when 2 then TODDDIFFICULTY::HEROICM
  when 3 then TODDDIFFICULTY::HARDM
  end
  return n1 * n2
 end
end


#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles system data. It saves the disable state of saving and
# menus. Instances of this class are referenced by $game_system.
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :todd_difficulty            # save forbidden
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias todd_difficulty_gamesystem_init initialize
  def initialize
    @todd_difficulty = 0
    todd_difficulty_gamesystem_init
  end
end

#==============================================================================
# ** Window_DifficultySelection
#==============================================================================

class Window_DifficultySelection < Window_HorzCommand
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0)
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    Graphics.width/2 + 20
  end
  #--------------------------------------------------------------------------
  # * Get Digit Count
  #--------------------------------------------------------------------------
  def col_max
    return 4
  end
  #--------------------------------------------------------------------------
  # * Create Command List
  #--------------------------------------------------------------------------
  def make_command_list
    add_command(TODDDIFFICULTY::EASYT,     :easy)
    add_command(TODDDIFFICULTY::NORMALT,   :normal)
    add_command(TODDDIFFICULTY::HEROICT,    :heroic)
    add_command(TODDDIFFICULTY::HARDT, :hard)
  end
end
#==============================================================================
# ** Window_DifficultyName
#==============================================================================

class Window_DifficultyName < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, window_width, fitting_height(1))
    refresh
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return Graphics.width/2 + 20
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_text(0, -27, 400, 80, TODDDIFFICULTY::TEXT)
  end
end
#==============================================================================
# ** Scene_Difficulty
#==============================================================================

class Scene_Difficulty < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
    super
    create_command_window
    create_name_window
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
  super

  end
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  def create_command_window
    @command_window = Window_DifficultySelection.new
    @command_window.set_handler(:easy,      method(:command_easy))
    @command_window.set_handler(:normal,     method(:command_normal))
    @command_window.set_handler(:heroic,     method(:command_heroic))
    @command_window.set_handler(:hard,    method(:command_hard))
    @command_window.set_handler(:cancel,    method(:return_scene))if $game_switches[TODDDIFFICULTY::SWITCH] == true
    @command_window.x = Graphics.width/2 - 170
    @command_window.y = Graphics.height/2 - 50
  end
  #--------------------------------------------------------------------------
  # * Create Difficulty Window
  #--------------------------------------------------------------------------
  def create_name_window
    @name_window = Window_DifficultyName.new
    @name_window.x = Graphics.width/2 - 170
    @name_window.y = Graphics.height/2 - 97
  end
  #--------------------------------------------------------------------------
  # * [easy] Command
  #--------------------------------------------------------------------------
  def command_easy
    $game_system.todd_difficulty = 0
    Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    $game_variables[TODDDIFFICULTY::VARIABLE] = 0
    return_scene
   end
  #--------------------------------------------------------------------------
  # * [normal] Command
  #--------------------------------------------------------------------------
  def command_normal
    $game_system.todd_difficulty = 1
    Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    $game_variables[TODDDIFFICULTY::VARIABLE] = 1
    return_scene
   end
  #--------------------------------------------------------------------------
  # * [heroic] Command
  #--------------------------------------------------------------------------
  def command_heroic
    $game_system.todd_difficulty = 2
      Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    $game_variables[TODDDIFFICULTY::VARIABLE] = 2
    return_scene
   end
  #--------------------------------------------------------------------------
  # * [hard] Command
  #--------------------------------------------------------------------------
  def command_hard
    $game_system.todd_difficulty = 3
    Audio.se_play("Audio/SE/" + TODDDIFFICULTY::SE, 100, 100)
    $game_variables[TODDDIFFICULTY::VARIABLE] = 3
    return_scene
   end
 end
 if TODDDIFFICULTY::MENU == true
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs the menu screen processing.
#==============================================================================

class Scene_Menu < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  alias todd_dif_menu_add_menu_command create_command_window
  def create_command_window
    todd_dif_menu_add_menu_command
    @command_window.set_handler(:dif,      method(:command_dif))
  end
end
  #--------------------------------------------------------------------------
  # * [Difficulty] Command
  #--------------------------------------------------------------------------
  def command_dif
  SceneManager.call(Scene_Difficulty)
  end
end

if TODDDIFFICULTY::MENU == true
#==============================================================================
# ** Window_MenuCommand
#------------------------------------------------------------------------------
#  This command window appears on the menu screen.
#==============================================================================

class Window_MenuCommand < Window_Command
  #--------------------------------------------------------------------------
  # * Add Main Commands to List
  #--------------------------------------------------------------------------
  alias todd_dif_menu_command_add_to_menu add_main_commands
  def add_main_commands
     todd_dif_menu_command_add_to_menu
    add_command("Difficulty",   :dif,   main_commands_enabled)
  end
 end
end
Title: Re: DT's Difficulty
Post by: Mushu on June 22, 2013, 10:17:13 PM
I don't know how I missed that. lol

This will make the game really flexible.  8)