VXAce Hime Gold Formula question. And can I make it global?

So, I found Hime Gold Formula script and I want it to multiply the gold received from every troop based on the chosen difficulty level of the game.

The easier the difficulty, the lower percentage of gold you obtain from battle. Thus, you are rewarded with more gold on higher difficulties, where your stats are less and it requires more XP to level up. And I am using switches to control the difficulty level and I want to use those same switches to determine gold awarded amounts.

Basically I got this setup here for the noteboxes (inform me if I am wrong):
Ruby:
<gold formula>
if s[2]      # Child difficulty
  gold * 0.5
elsif s[3]   # Easy difficulty
  gold
elsif s[4]   # Medium difficulty
  gold * 1.5
elsif s[5]   # Hard difficulty
  gold * 2
else
  gold        # fallback if no switch is ON
end
</gold formula>


Now I do not think I need the fallback as one of these switches turns on when you select the difficulty at the start of the game, but I was told to have it.


Is this correct for the gold formula?


Also, is there a scriptlet or something I can under the Hime Gold Formulas to make this code global so I do not have to input it into literally every enemy noteboxes? I do not trust the one that GPT shoved in my face, so I want to make sure its right.


Please and thank you very much for any information.
Hello,

There are many ways to change how much gold is gained, you can for instance change gold_rate or gold_total methods in Game_Troop, but since you want to have non-integer ratios, it might be better to change method goldin Game_Enemy.

Here is a script that reproduces the scriptlet you've given, but with a global scope to enemies:
Ruby:
class Game_Enemy
  alias difficulty_gold gold
  def gold
    g = difficulty_gold
    s = $game_switches
    if s[2]
      (g * 0.5).to_i #ensure the number is not decimal
    elsif s[3]
      g
    elsif s[4]
      (g * 1.5).to_i
    elsif s[5]
      g * 2
    else
      g
    end
  end
end #Game_Enemy

However, it's pretty bad, there is a lot of code repetition.
Now I do not think I need the fallback as one of these switches turns on when you select the difficulty at the start of the game, but I was told to have it.
You can remove it if you are 100% sure one of them is true. But if you remove the else case and did not properly set up your game, then it will crash on gold rewards.



Since your difficulty system is exclusive, you might want to opt for a variable instead of multiple switches. By having a variable setting the difficulty, you will have the guarantee of not having two difficulties at the same time and one difficulty activated. Then, if you want to check if a difficulty is on, you can do $game_variable[id] == difficulty_level

Since your gold formula is linear, it's quite easy to synthetize it into this script (assuming a variable controls the difficulty):
Ruby:
module DifficultyGold
  DIFF_VAR = 10   #id of the difficulty variables
                  #with values between 0 and MAX_VAR_VAL
  MAX_DIFF = 3    #max difficulty, keep it above 0
 
  MIN_R    = 0.5 #gold ratio on difficulty 0
  MAX_R    = 2   #gold ratio on max difficulty
end #DifficultyGold

class Game_Enemy
  include DifficultyGold
 
  #new method:
  def gold_ratio
    return MIN_R if MAX_DIFF == 0
    MIN_R + (MAX_R - MIN_R)/MAX_DIFF.to_f * $game_variables[DIFF_VAR]
  end
 
  alias difficulty_gold gold
  def gold
    (difficulty_gold * gold_ratio).to_i
  end
end #Game_Enemy

With variables values being: 0 for child, 1 for easy, 2 for medium, 3 for hard
Thank you for your reply.

Does that first scriptlet still require Hime's Gold Formulas script, or is that a standalone scriptplet?
Both scriplets are standalone.

Original thread: https://forums.rpgmakerweb.com/threads/hime-gold-formula-question-and-can-i-make-it-global.181340/