[XP] Gold Variance

Started by chaucer, June 09, 2013, 05:38:18 am

Previous topic - Next topic

chaucer

Gold Variance
Authors: Chaucer
Version: 1.0
Type: Battle Add-on
Key Term: Battle Add-on



Introduction
  • Adds Variance to gold so obtained ammount is random based on %




Features


  • Random gold gain from enemies

  • Easy to configure





Screenshots
N/A


Demo
N/A


Script
Spoiler: ShowHide

=begin
***********************************************************************
***********************************************************************
* [Gold Variance]
* Author : Chaucer
* Version 1.0
***********************************************************************
*Intro: This script change the way to get gold instead of static number
*       gold will be gained with a variance.
*
*Example: Before: Enemy ID killed = 60 gold every time.
*         After:  Eney ID killed = 60-75 gold(randomly).
*
*Features: Adds Variance to gold
*
*Instructions: Place below Scene_Debug but above everything else.
*              search for var to set the ratio var = 25 preset.
*
*Compatibility: no known issues except with scripts that rewrite gold
*               gained method.
*
*Credits: None required unless felt like
*        
=end

#==============================================================================
# ** Scene_Battle (part 2)
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle
 
 def start_phase5
   # Shift to phase 5
   @phase = 5
   # Play battle end ME
   $game_system.me_play($game_system.battle_end_me)
   # Return to BGM before battle started
   $game_system.bgm_play($game_temp.map_bgm)
   # Initialize EXP, amount of gold, and treasure
   exp = 0
   gold = 0
   #var = パーセントの変数は整数を使用してくださいされて
   var = 25
   treasures = []
   # Loop
   for enemy in $game_troop.enemies
     # If enemy is not hidden
     unless enemy.hidden
       #amplified gold
       gold_m = [enemy.gold * var / 100, 1].max
       gold_m += rand(gold_m+1) + rand(gold_m+1) - gold_m
       # Add EXP and amount of gold obtained
       exp += enemy.exp
       gold += enemy.gold + gold_m
       # Determine if treasure appears
       if rand(100) < enemy.treasure_prob
         if enemy.item_id > 0
           treasures.push($data_items[enemy.item_id])
         end
         if enemy.weapon_id > 0
           treasures.push($data_weapons[enemy.weapon_id])
         end
         if enemy.armor_id > 0
           treasures.push($data_armors[enemy.armor_id])
         end
       end
     end
   end
   # Treasure is limited to a maximum of 6 items
   treasures = treasures[0..5]
   # Obtaining EXP
   for i in 0...$game_party.actors.size
     actor = $game_party.actors[i]
     if actor.cant_get_exp? == false
       last_level = actor.level
       actor.exp += exp
       if actor.level > last_level
         @status_window.level_up(i)
       end
     end
   end
   # Obtaining gold
   $game_party.gain_gold(gold)
   # Obtaining treasure
   for item in treasures
     case item
     when RPG::Item
       $game_party.gain_item(item.id, 1)
     when RPG::Weapon
       $game_party.gain_weapon(item.id, 1)
     when RPG::Armor
       $game_party.gain_armor(item.id, 1)
     end
   end
   # Make battle result window
   @result_window = Window_BattleResult.new(exp, gold, treasures)
   # Set wait count
   @phase5_wait_count = 100
 end
end





Instructions
Place below Scene_Debug
Directions Inside Script


Compatibility
not compatible anything that rewrites gained gold method


Credits and Thanks


  • Chaucer

  • Credits not needed anyone could make this.




Author's Notes

Hope it helps someone

KK20

I encourage you to find a more compatible approach to this system. Challenge yourself.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

chaucer

i tried doing this different ways I'm not very good with scripting as i don't have much time to practice. I'd been looking for something to do this for a while, but couldn't find anything. I'll try and find a better way of making this happen but as of right now this was the only way i could get to work. Also i felt i'd attempt to contribute to the community here,  feel free to delete this post if you want or leave it, cya.

LiTTleDRAgo

instead rewriting phase5 Scene_Battle, isn't it easier to modify Window_BattleResult to modify the gold?

not tested: ShowHide

class Window_BattleResult < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias random_gold_drop_init initialize
  def initialize(exp, gold, treasures)
    random_gold_drop_init(exp, gold, treasures)
    inc = rand((gold.to_f * 25 / 100).to_i)
    @gold = gold + inc
    $game_party.gain_gold(inc)
    refresh
  end
end

G_G

While that would work Drago, you'd still have to modify phase5 to prevent the party from gaining another batch of gold.

LiTTleDRAgo

in the script, party only receive the surplus (not all the gold) so its okay

Quoteinc = rand((gold.to_f * 25 / 100).to_i)
    @gold = gold + inc
    $game_party.gain_gold(inc)

KK20

But now there is no variance, only a percent bonus so to speak. If the party would normally get 1000 gold, assuming 25% variance, they should gain an amount between 750 - 1250. Your fix limits this to 1000 - 1250.

Then you must consider the amount of gold the party has before adding the variance to it. What if the party has max gold (9999999) before the battle, Phase 5 adds (I don't know...) 10000 gold, and after calculating variance the party should happen to get 7500 gold, you can't do a simple $game_party.gain_gold(-2500) because now the party lost money for winning.

I actually have the solution already, but I'll hide it for now unless someone requests it or someone else figures it out. It's very similar to what you have posted Drago.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Blizzard

I agree, it has to be done in phase5 of Scene_Battle for the exact same reasons that KK20 already pointed out. That part of the scripts is a weakpoint in that regard, because it wasn't coded in a modular way. Way too much stuff crunched into one method.
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.

LiTTleDRAgo

June 10, 2013, 11:06:49 pm #8 Last Edit: November 03, 2015, 10:34:37 am by LiTTleDRAgo
how about this?

Spoiler: ShowHide
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================
class Scene_Battle
  #--------------------------------------------------------------------------
  # * Constant
  #--------------------------------------------------------------------------
  VAR = 25   
  #--------------------------------------------------------------------------
  # * Alias Listing
  #--------------------------------------------------------------------------
  $@ || alias_method(:phase5_random_gold,:start_phase5)
  #--------------------------------------------------------------------------
  # * Start After Battle Phase
  #--------------------------------------------------------------------------
  def start_phase5(*args)
    gold = 0
    for enemy in $game_troop.enemies
      inc = rand((enemy.gold * VAR / 100).round) * [-1,1][rand(2)]
      gold += enemy.gold + inc.round unless enemy.hidden
      enemy.instance_variable_set(:@gold,0)
    end
    [$game_party.gain_gold(gold), phase5_random_gold(*args)]
    @result_window.instance_variable_set(:@gold,gold)
    @result_window.refresh
  end
end

#==============================================================================
# ** Game_Enemy
#------------------------------------------------------------------------------
#  This class handles enemies. It's used within the Game_Troop class
#  ($game_troop).
#==============================================================================
class Game_Enemy
  #--------------------------------------------------------------------------
  # * Alias Listing
  #--------------------------------------------------------------------------
  $@ || alias_method(:random_gold, :gold)
  #--------------------------------------------------------------------------
  # * Get Gold
  #--------------------------------------------------------------------------
  define_method(:gold) {@gold || random_gold}
end

G_G

You're still gonna gain extra gold. Because you're calling the old method. You're going to have to rewrite the method.

LiTTleDRAgo

it's already tested

party gold = 0
enemy = ghost * 3 @1000 G (total 3000 G)
after win 01 gold = 2830 G (get 2830 G)
after win 02 gold = 5981 G (get 3151 G)
after win 03 gold = 9044 G (get 3063 G)

KK20

++ for figuring out something different (and better) than mine.
Spoiler: ShowHide

class Game_Temp
  attr_accessor :gold_b4_battle_result
  alias init_gb4br initialize
  def initialize
    init_gb4br
    @gold_b4_battle_result = 0
  end
end

class Scene_Battle
  alias get_party_gold_b4_adding start_phase5
  def start_phase5
    $game_temp.gold_b4_battle_result = $game_party.gold
    get_party_gold_b4_adding
  end
end

class Window_BattleResult < Window_Base
  alias add_gold_variance initialize
  def initialize(exp, gold, treasures)
    add_gold_variance(exp, gold, treasures)
    @gold += rand(@gold * 25 / 100 + 1) * [-1,1][rand(2)]
    $game_temp.gold_b4_battle_result += @gold
    dif = $game_temp.gold_b4_battle_result - $game_party.gold
    $game_party.gain_gold(dif)
    refresh
  end
end

My way was designed to calculate the party's gold in another variable (stored before phase5 begins) and add/subtract the difference to $game_party.gold after the default method added the base amount.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

G_G

Quote from: LiTTleDRAgo on June 11, 2013, 01:23:13 am
it's already tested

party gold = 0
enemy = ghost * 3 @1000 G (total 3000 G)
after win 01 gold = 2830 G (get 2830 G)
after win 02 gold = 5981 G (get 3151 G)
after win 03 gold = 9044 G (get 3063 G)


Oh! Sorry, I completely missed the fact that you set the enemy's gold to 0. Sorry about that. >.< Nice job. :3

chaucer

cool, nice work i just started working on mine right now but i see you all already solved it. I'll still use what I've made for my project but nice work. :) i guess back to learning ruby language take care.

djskagnetti

Sorry for Necro, but LiTTleDRAgo's does not work if gold is 1.  It makes it a fraction of 1, so you can get like .9484283 gold, for instance.

KK20's code works, though.