[Request] "Refund badge"-type script?

SpherianGames

Villager
Member
Joined
Oct 21, 2018
Messages
24
Reaction score
4
First Language
English
Primarily Uses
RMXP
Hi, all! If you've played the original Paper Mario, there's an item called the Refund badge. If you have it equipped, then you'll get some coins back each time you use an item during battle, equal to a percentage of the item's sale price. I'd like to add a similar accessory to my game, so I thought I'd ask you scripting wizards for help. :kaothx:

Like I said, it should only work for items used in battle, and I think it'd be neat to have a sound effect play and some text pop up (like damage numbers, but saying "+500 gold!" or whatever) to signify when it happens. Let me know if any of this sounds possible, and thanks for the help!
 

SpherianGames

Villager
Member
Joined
Oct 21, 2018
Messages
24
Reaction score
4
First Language
English
Primarily Uses
RMXP
Bump. Anyone?
I'd also be willing to pay a commission fee.
 

SpherianGames

Villager
Member
Joined
Oct 21, 2018
Messages
24
Reaction score
4
First Language
English
Primarily Uses
RMXP
Is this impossible to do with common events?
Yes, sadly. I need to set a price for each item, and then pay it when that item is used. There's no conditional branch for using an item, which means I'd need to attach a separate common event to each one. But many of my items already have common events linked to them, so that won't work. :confused:

Plus, I'm not sure how I'd make it so the effect only triggers in battle, without a script.
 

glaphen

Veteran
Veteran
Joined
Jan 13, 2019
Messages
205
Reaction score
64
First Language
English
Primarily Uses
RMMV
You can do it with yanfly action sequences, add a conditional if item is equipped then play common event, before that at any time in sequence or after conditional set a specific variable to be equal to whatever you want for that item, common event gives you money based off variable.
 

SpherianGames

Villager
Member
Joined
Oct 21, 2018
Messages
24
Reaction score
4
First Language
English
Primarily Uses
RMXP
You can do it with yanfly action sequences, add a conditional if item is equipped then play common event, before that at any time in sequence or after conditional set a specific variable to be equal to whatever you want for that item, common event gives you money based off variable.
Isn't that an MV script? I don't think it'll work with XP.
 

glaphen

Veteran
Veteran
Joined
Jan 13, 2019
Messages
205
Reaction score
64
First Language
English
Primarily Uses
RMMV
Isn't that an MV script? I don't think it'll work with XP.
Oh my bad, but you can still probably do it with a simple addition to wherever it calls items to be used in battle in the base scripts to make a condition if the user is equipped with whatever that armor ID is, just set a variable to that items ID or something then call that common event on every item, or even in that edit after that variable was set.

Like I just tried in a new project in Game_Battler3 I just stuck in $game_variables[1] = item.id in a random spot in application of item effects and now it sets variable 1 to the item id, not gonna dig how to get users equipment for an engine I don't use but if you could figure out the code you can just stick it above with an if and end with an end, now common event knows, otherwise you could always check in common event if it is equipped or something but, wouldn't know if the user is the one with it. As for multiple common events at once, not sure how XP works but even if it doesn't let you play 2 with the script call you could always make it call the common events based off that variable at the end of that common event. Though it did do it for out of combat as well, so probably different place for battle only. Actually simple to solve saw $gametemp in battle thing at top of page. Here is what I did. I don't know javascript at all and especially ruby.
Code:
  def item_effect(item)
    # Clear critical flag
    self.critical = false
    # If item scope is for ally with 1 or more HP, and your own HP = 0,
    # or item scope is for ally with 0 HP, and your own HP = 1 or more
    if ((item.scope == 3 or item.scope == 4) and self.hp == 0) or
       ((item.scope == 5 or item.scope == 6) and self.hp >= 1)
      # End Method
      return false
    end
    # Clear effective flag
    effective = false
    # Set effective flag if common ID is effective
    effective |= item.common_event_id > 0
    # Determine hit
    hit_result = (rand(100) < item.hit)
    # Set effective flag is skill is uncertain
    effective |= item.hit < 100
    # If hit occurs
    if $game_temp.in_battle
    $game_variables[1] = item.id
    end
    if hit_result == true
      # Calculate amount of recovery
      recover_hp = maxhp * item.recover_hp_rate / 100 + item.recover_hp
      recover_sp = maxsp * item.recover_sp_rate / 100 + item.recover_sp
      if recover_hp < 0
        recover_hp += self.pdef * item.pdef_f / 20
        recover_hp += self.mdef * item.mdef_f / 20
        recover_hp = [recover_hp, 0].min
      end
      # Element correction
      recover_hp *= elements_correct(item.element_set)
      recover_hp /= 100
      recover_sp *= elements_correct(item.element_set)
      recover_sp /= 100
      # Dispersion
      if item.variance > 0 and recover_hp.abs > 0
        amp = [recover_hp.abs * item.variance / 100, 1].max
        recover_hp += rand(amp+1) + rand(amp+1) - amp
      end
      if item.variance > 0 and recover_sp.abs > 0
        amp = [recover_sp.abs * item.variance / 100, 1].max
        recover_sp += rand(amp+1) + rand(amp+1) - amp
      end
      # If recovery code is negative
      if recover_hp < 0
        # Guard correction
        if self.guarding?
          recover_hp /= 2
        end
      end
      # Set damage value and reverse HP recovery amount
      self.damage = -recover_hp
      # HP and SP recovery
      last_hp = self.hp
      last_sp = self.sp
      self.hp += recover_hp
      self.sp += recover_sp
      effective |= self.hp != last_hp
      effective |= self.sp != last_sp
      # State change
      @state_changed = false
      effective |= states_plus(item.plus_state_set)
      effective |= states_minus(item.minus_state_set)
      # If parameter value increase is effective
      if item.parameter_type > 0 and item.parameter_points != 0
        # Branch by parameter
        case item.parameter_type
        when 1  # Max HP
          @maxhp_plus += item.parameter_points
        when 2  # Max SP
          @maxsp_plus += item.parameter_points
        when 3  # Strength
          @str_plus += item.parameter_points
        when 4  # Dexterity
          @dex_plus += item.parameter_points
        when 5  # Agility
          @agi_plus += item.parameter_points
        when 6  # Intelligence
          @int_plus += item.parameter_points
        end
        # Set to effective flag
        effective = true
      end
      # If HP recovery rate and recovery amount are 0
      if item.recover_hp_rate == 0 and item.recover_hp == 0
        # Set damage to empty string
        self.damage = ""
        # If SP recovery rate / recovery amount are 0, and parameter increase
        # value is ineffective.
        if item.recover_sp_rate == 0 and item.recover_sp == 0 and
           (item.parameter_type == 0 or item.parameter_points == 0)
          # If state is unchanged
          unless @state_changed
            # Set damage to "Miss"
            self.damage = "Miss"
          end
        end
      end
    # If miss occurs
    else
      # Set damage to "Miss"
      self.damage = "Miss"
    end
    # If not in battle
    unless $game_temp.in_battle
      # Set damage to nil
      self.damage = nil
    end
    # End Method
    return effective
  end
 
Last edited:

SpherianGames

Villager
Member
Joined
Oct 21, 2018
Messages
24
Reaction score
4
First Language
English
Primarily Uses
RMXP
Here is what I did. I don't know javascript at all and especially ruby.
Code:
  def item_effect(item)
    # Clear critical flag
    self.critical = false
    # If item scope is for ally with 1 or more HP, and your own HP = 0,
    # or item scope is for ally with 0 HP, and your own HP = 1 or more
    if ((item.scope == 3 or item.scope == 4) and self.hp == 0) or
       ((item.scope == 5 or item.scope == 6) and self.hp >= 1)
      # End Method
      return false
    end
    # Clear effective flag
    effective = false
    # Set effective flag if common ID is effective
    effective |= item.common_event_id > 0
    # Determine hit
    hit_result = (rand(100) < item.hit)
    # Set effective flag is skill is uncertain
    effective |= item.hit < 100
    # If hit occurs
    if $game_temp.in_battle
    $game_variables[1] = item.id
    end
    if hit_result == true
      # Calculate amount of recovery
      recover_hp = maxhp * item.recover_hp_rate / 100 + item.recover_hp
      recover_sp = maxsp * item.recover_sp_rate / 100 + item.recover_sp
      if recover_hp < 0
        recover_hp += self.pdef * item.pdef_f / 20
        recover_hp += self.mdef * item.mdef_f / 20
        recover_hp = [recover_hp, 0].min
      end
      # Element correction
      recover_hp *= elements_correct(item.element_set)
      recover_hp /= 100
      recover_sp *= elements_correct(item.element_set)
      recover_sp /= 100
      # Dispersion
      if item.variance > 0 and recover_hp.abs > 0
        amp = [recover_hp.abs * item.variance / 100, 1].max
        recover_hp += rand(amp+1) + rand(amp+1) - amp
      end
      if item.variance > 0 and recover_sp.abs > 0
        amp = [recover_sp.abs * item.variance / 100, 1].max
        recover_sp += rand(amp+1) + rand(amp+1) - amp
      end
      # If recovery code is negative
      if recover_hp < 0
        # Guard correction
        if self.guarding?
          recover_hp /= 2
        end
      end
      # Set damage value and reverse HP recovery amount
      self.damage = -recover_hp
      # HP and SP recovery
      last_hp = self.hp
      last_sp = self.sp
      self.hp += recover_hp
      self.sp += recover_sp
      effective |= self.hp != last_hp
      effective |= self.sp != last_sp
      # State change
      @state_changed = false
      effective |= states_plus(item.plus_state_set)
      effective |= states_minus(item.minus_state_set)
      # If parameter value increase is effective
      if item.parameter_type > 0 and item.parameter_points != 0
        # Branch by parameter
        case item.parameter_type
        when 1  # Max HP
          @maxhp_plus += item.parameter_points
        when 2  # Max SP
          @maxsp_plus += item.parameter_points
        when 3  # Strength
          @str_plus += item.parameter_points
        when 4  # Dexterity
          @dex_plus += item.parameter_points
        when 5  # Agility
          @agi_plus += item.parameter_points
        when 6  # Intelligence
          @int_plus += item.parameter_points
        end
        # Set to effective flag
        effective = true
      end
      # If HP recovery rate and recovery amount are 0
      if item.recover_hp_rate == 0 and item.recover_hp == 0
        # Set damage to empty string
        self.damage = ""
        # If SP recovery rate / recovery amount are 0, and parameter increase
        # value is ineffective.
        if item.recover_sp_rate == 0 and item.recover_sp == 0 and
           (item.parameter_type == 0 or item.parameter_points == 0)
          # If state is unchanged
          unless @state_changed
            # Set damage to "Miss"
            self.damage = "Miss"
          end
        end
      end
    # If miss occurs
    else
      # Set damage to "Miss"
      self.damage = "Miss"
    end
    # If not in battle
    unless $game_temp.in_battle
      # Set damage to nil
      self.damage = nil
    end
    # End Method
    return effective
  end
I'm not too keen to start messing with the base scripts, given how illiterate I am, but I'll see what I can do with this. Thanks a bunch! :LZSproud:
(My commission offer still stands though, if anyone is interested, LOL).
 

glaphen

Veteran
Veteran
Joined
Jan 13, 2019
Messages
205
Reaction score
64
First Language
English
Primarily Uses
RMMV
I'm not too keen to start messing with the base scripts, given how illiterate I am, but I'll see what I can do with this. Thanks a bunch! :LZSproud:
(My commission offer still stands though, if anyone is interested, LOL).
I remembered states can also be used to tell targets so I tried again, but realized XP is really dumb at getting the user of skill so I did a quick search and found this thread.
If you use this script and my above one to get item ID into a variable you can set up a common event like this.
CE1.pngCE2.pngCE3.png
If you need to run a second common event just put a conditional for the same variable and item that you want the common event for in the bottom before the control variable = 0, or copy the entire common event into the conditional.

For showing the gains you can just make pictures of the numbers in any way you want and fade them out I guess.

Oh and for my script you should remove the if battle and end so it's only adding
$game_variables[1] = item.id
into the item using code or else you won't be able to play second common events.
Though you did say only in battle so I guess you can use it and different common event out of battle.
 
Last edited:

A-Moonless-Night

WINTER IS COMING
Veteran
Joined
Mar 17, 2012
Messages
568
Reaction score
389
First Language
English
Primarily Uses
RMVXA
See how you go with this, haven't tested it too much:
Ruby:
module AMN_RB
  # IDs of armours that should act as 'Refund Badges'
  REFUND_BADGES = [5, 6]
 
  # Percentage of item's price to refund
  PERCENTAGE = 0.25
 
  # Minimum gold to refund
  REFUND_MIN = 1
 
  # Name of refund sound effect file (set to "" to not use)
  REFUND_SOUND = "006-System06"
 
end

class Game_Actor < Game_Battler

  def refund_badge?
    [@armor1_id, @armor2_id, @armor3_id, @armor4_id].any? do |id|
      AMN_RB::REFUND_BADGES.include?(id)
    end
  end
 
end

class Scene_Battle

  alias amn_refund_scenebattle_makeitemactres make_item_action_result
  def make_item_action_result
    @item = $data_items[@active_battler.current_action.item_id]
    gold = nil
    if $game_party.item_can_use?(@item.id) && @active_battler.refund_badge?
      gold = ([@item.price.to_f * AMN_RB::PERCENTAGE, AMN_RB::REFUND_MIN].max).to_i
    end
    amn_refund_scenebattle_makeitemactres
    if gold && gold > 0
      $game_system.se_play(RPG::AudioFile.new(AMN_RB::REFUND_SOUND, 80))
      @help_window.set_text("+" + gold.to_s + $data_system.words.gold, 1)
    end
  end
 
end
It's been a while since I've done anything with XP!
 

SpherianGames

Villager
Member
Joined
Oct 21, 2018
Messages
24
Reaction score
4
First Language
English
Primarily Uses
RMXP
See how you go with this, haven't tested it too much:
Ruby:
module AMN_RB
  # IDs of armours that should act as 'Refund Badges'
  REFUND_BADGES = [5, 6]

  # Percentage of item's price to refund
  PERCENTAGE = 0.25

  # Minimum gold to refund
  REFUND_MIN = 1

  # Name of refund sound effect file (set to "" to not use)
  REFUND_SOUND = "006-System06"

end

class Game_Actor < Game_Battler

  def refund_badge?
    [@armor1_id, @armor2_id, @armor3_id, @armor4_id].any? do |id|
      AMN_RB::REFUND_BADGES.include?(id)
    end
  end

end

class Scene_Battle

  alias amn_refund_scenebattle_makeitemactres make_item_action_result
  def make_item_action_result
    @item = $data_items[@active_battler.current_action.item_id]
    gold = nil
    if $game_party.item_can_use?(@item.id) && @active_battler.refund_badge?
      gold = ([@item.price.to_f * AMN_RB::PERCENTAGE, AMN_RB::REFUND_MIN].max).to_i
    end
    amn_refund_scenebattle_makeitemactres
    if gold && gold > 0
      $game_system.se_play(RPG::AudioFile.new(AMN_RB::REFUND_SOUND, 80))
      @help_window.set_text("+" + gold.to_s + $data_system.words.gold, 1)
    end
  end

end
It's been a while since I've done anything with XP!
Well, I was about to say it works perfectly, until the battle ended, and I realized that I hadn't actually gained any gold, even though the UI said I had. ;^^

Any ideas? If not, thanks for helping anyway. And thank you too, Glaphen! You guys are wonderful here.
 

A-Moonless-Night

WINTER IS COMING
Veteran
Joined
Mar 17, 2012
Messages
568
Reaction score
389
First Language
English
Primarily Uses
RMVXA
Oops, I forgot to actually include that line, haha.
Ruby:
module AMN_RB
  # IDs of armours that should act as 'Refund Badges'
  REFUND_BADGES = [5, 6]
 
  # Percentage of item's price to refund
  PERCENTAGE = 0.25
 
  # Minimum gold to refund
  REFUND_MIN = 1
 
  # Name of refund sound effect file (set to "" to not use)
  REFUND_SOUND = "006-System06"
 
end

class Game_Actor < Game_Battler

  def refund_badge?
    [@armor1_id, @armor2_id, @armor3_id, @armor4_id].any? do |id|
      AMN_RB::REFUND_BADGES.include?(id)
    end
  end
 
end

class Scene_Battle

  alias amn_refund_scenebattle_makeitemactres make_item_action_result
  def make_item_action_result
    @item = $data_items[@active_battler.current_action.item_id]
    gold = nil
    if $game_party.item_can_use?(@item.id) && @active_battler.refund_badge?
      gold = ([@item.price.to_f * AMN_RB::PERCENTAGE, AMN_RB::REFUND_MIN].max).to_i
    end
    amn_refund_scenebattle_makeitemactres
    if gold && gold > 0
      $game_party.gain_gold(gold)
      $game_system.se_play(RPG::AudioFile.new(AMN_RB::REFUND_SOUND, 80))
      @help_window.set_text("+" + gold.to_s + $data_system.words.gold, 1)
    end
  end
 
end
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People in Italy panicking for this stupid coronavirus, it's nothing more than a flu and they are all acting like it's the black plague...
Blech. I hate coming up with stories. Making gameplay is fun but coming up with lore and reasons for these areas/mechanics just makes me sleepy.
40 card deck size, the plugin seems more sluggish.
Village theme I composed for a commission!

Forum statistics

Threads
94,567
Messages
921,939
Members
124,430
Latest member
Venator123
Top