Jump to content
Vis_Mage

Chance to Refund Item in Battle

Recommended Posts

Hey! :)

 

I was wondering if anyone could help me with a (hopefully simple) script request.

 

Pretty much, I'm hoping for a script that a % chance (possibly stored in a variable to allow for mid-game % changing) to have an item used within battle to be refunded (not used up), ideally with a message in the battle log saying "Got a Freebie!" or something of the nature.

 

A couple other cool features might be allowing to have items with different refund % (as notetags or listed in the script itself), or having equipment that could raise the odds, but I wouldn't worry about it if it proves to be difficult.

 

Thank you!

Share this post


Link to post
Share on other sites

D-Did I do it? Do I deserve a cookie?

Spoiler

#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#  A battler class with methods for sprites and actions added. This class 
# is used as a super class of the Game_Actor class and Game_Enemy class.
#==============================================================================
module FreebieItems
  MODIFIER = 20    #A.K.A. $game_variables[???]
  PROBABILITY = 10
  FREEBIES = [ #[item database id, goal]
  [10,5],
  [11,6],
  [12,7]
  ]
end

class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # * Use Skill/Item
  #    Called for the acting side and applies the effect to other than the user.
  alias freebieitemschance56t556    use_item
  #--------------------------------------------------------------------------
  def use_item(item)
    pay_skill_cost(item) if item.is_a?(RPG::Skill)
    if item.is_a?(RPG::Item)
      free = FreebieItems::FREEBIES
      num = 1 + rand(FreebieItems::PROBABILITY) + (FreebieItems::MODIFIER ? FreebieItems::MODIFIER : 0)
      free.size.times do |ooii|
        if item == $data_items[free[ooii][0]]
          if num <= free[ooii][1]
            consume_item(item)
          else
            $game_message.background = 1
            $game_message.position = 1
            $game_message.add("FREEBIE!!!")
            # fBG - [0] Normal, [1] Faded, [2] Transparent
            # fPos - [0] Top, [1] Middle, [2] Bottom
          end
          break
        end
      end
    end
    item.effects.each {|effect| item_global_effect_apply(effect) }
    freebieitemschance56t556(item)
  end
end

#==============================================================================
# ** BattleManager
#------------------------------------------------------------------------------
#  This module manages battle progress.
#==============================================================================

module BattleManager
  # * End Turn
  class << self
    alias freebie_turnend_54tet5    turn_end
    def self.turn_end
      if $game_variables[FreebieItems::MODIFIER] > 0
        $game_variables[FreebieItems::MODIFIER] -= 1
      end
      freebie_turnend_54tet5
    end
  end
end
 

 

EDIT: create a skill that affects an ally, and create a common event through the skill that targets the variable you'll use for the Freebie.

I have it going on a turn timer, each turn, the variable will decrease by 1.

Edited by BrandonKaminari
making it better

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×