Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Lose random gold and EXP on exit

Basically I want the party to be able to escape most(95%) of the time at the cost of gold and experience (experience rand(8) gold rand(20) or such







So far Ive tried and nothign happens
under scene_battle 2

if success
$game_party.lose_gold(rand(100))
for actor in $game_party.actors
if actor.exist?
actors_exp -= rand(8)
end
end
@gold_window.refresh
# Play escape SE
$game_system.se_play($data_system.escape_se)
# Return to BGM before battle started
$game_system.bgm_play($game_temp.map_bgm)
# Battle ends

battle_end(1)
# If escape is failure
else
# Clear all party member actions
$game_party.clear_actions
# Start main phase
start_phase4
 
Code:
class Game_Party
  attr_accessor :escaping_gold_cost
  attr_accessor :escaping_exp_cost
  alias_method :seph_escapingcost_gmprty_init, :initialize
  def initialize
    seph_escapingcost_gmprty_init
    @escaping_gold_cost = 0...20
    @escaping_exp_cost = 0...8
  end
end

class Scene_Battle
  alias_method :seph_escapingcost_scnbtl_be, :battle_end
  def battle_end(result)
    seph_escapingcost_scnbtl_be
    if result == 1
      gc, ec = $game_party.escaping_gold_cost, $game_party.escaping_exp_cost
      gc = gc.to_a if gc.is_a?(Range)
      gc = gc[rand(gc.size)] if gc.is_a?(Array)
      $game_party.lose_gold(gc)
      ec = ec.to_a if ec.is_a?(Range)
      ec = ec[rand(ec.size)] if ec.is_a?(Array)
      $game_party.actors.each { |a| a.exp -= ec }
    end
  end
end

To alter your gold loss, use:
Code:
$game_party.escaping_gold_cost = n1..n2 or [n1, n2, ...] or n

To alter your exp loss, use:
Code:
$game_party.escaping_exp_cost = n1..n2 or [n1, n2, ...] or n

The first one, you declare a range. The number loss is a random number in that range (min is n1, max is n2). The second one is just an array filled with possible numbers. Fill it with whatever numbers you want. The last is just a direct number to loss. Like 8 or 20, but it isn't random here. For random, use a range or array.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top