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.

[Resolved] How could I change item shop prices?

Status
Not open for further replies.
Hi!
I would like to know how could I create a conditional branch (in a script)? I would like to get a result like this:

if you're currently in map001, increase the item shop prices (2x).
if you're currently in map003, set the prices to normal (1x)
if you're currently in map005, set prices to 0.5x

How would I call the script to do such a thing?

Thanks in advance for your help.
 
Just made this for you. :D

Code:
class Game_System::MapCostEffects
  Starting_Item_Effects = {}
  Starting_Weapon_Effects = {}
  Starting_Armor_Effects = {}
  attr_accessor :items
  attr_accessor :weapons
  attr_accessor :armors
  attr_reader :map_item_effects
  attr_reader :map_weapon_effects
  attr_reader :map_armor_effects
  def initialize
    @items = 1.0
    @weapons = 1.0
    @armors = 1.0
    @map_item_effects = Starting_Item_Effects
    @map_weapon_effects = Starting_Weapon_Effects
    @map_armor_effects = Starting_Armor_Effects
  end
  def setup(map_id)
    if @map_item_effects.has_key?(map_id)
      @items = @map_item_effects[map_id]
    end
    if @map_weapon_effects.has_key?(map_id)
      @weapons = @map_weapon_effects[map_id]
    end
    if @map_armor_effects.has_key?(map_id)
      @armors = @map_armor_effects[map_id]
    end
  end
  def set_item_effect(map_id, effect)
    if effect.nil?
      @map_item_effects.delete(map_id)
      return
    end
    @map_item_effects[map_id] = effect
  end
  def set_weapon_effect(map_id, effect)
    if effect.nil?
      @map_weapon_effects.delete(map_id)
      return
    end
    @map_weapon_effects[map_id] = effect
  end
  def set_armor_effect(map_id, effect)
    if effect.nil?
      @map_armor_effects.delete(map_id)
      return
    end
    @map_armor_effects[map_id] = effect
  end
end

class Game_System
  attr_reader :map_cost_effects
  alias_method :seph_mapcosteffects_gmsys_init, :initialize
  def initialize
    seph_mapcosteffects_gmsys_init
    @map_cost_effects = MapCostEffects.new
  end
end

class Game_Map
  alias_method :seph_macpcosteffects_gmmap_setup, :setup
  def setup(map_id)
    $game_system.map_cost_effects.setup(map_id)
    seph_macpcosteffects_gmmap_setup(map_id)
  end
end

class RPG::Item
  alias_method :seph_mapcosteffects_rpgitem_price, :price
  def price
    n = seph_mapcosteffects_rpgitem_price
    n = Integer(n * $game_system.map_cost_effects.items)
    return n
  end
end

class RPG::Weapon
  alias_method :seph_mapcosteffects_rpgwpn_price, :price
  def price
    n = seph_mapcosteffects_rpgwpn_price
    n = Integer(n * $game_system.map_cost_effects.weapons)
    return n
  end
end

class RPG::Armor
  alias_method :seph_mapcosteffects_rpgarm_price, :price
  def price
    n = seph_mapcosteffects_rpgarm_price
    n = Integer(n * $game_system.map_cost_effects.armors)
    return n
  end
end


Ok. This does several things:
~ Lets you set item, weapons and armors price differently by a percent by map defaults
~ Lets you change your map defaults
~ Lets you change the item, weapons and armors price percents without the map switch (however, switching to a map with a price defined, the price will revert to the map default).


Ok, so lets start with setting you map defaults.
Code:
  Starting_Item_Effects = {}
  Starting_Weapon_Effects = {}
  Starting_Armor_Effects = {}

Lets say you want to add the following defaults:
~ Map 1 - Items Price x 1.4, Weapons x 0.8, Armors x 1.3
~ Map 3 - Items Price x 0.5
~ Map 4 - Weapons Price x 1.1, Armors x 1.2

Below the lines I gave you above, you would add this:
Code:
# Map 1 - Items Price x 1.4, Weapons x 0.8, Armors x 1.3
  Starting_Item_Effects[1] = 1.4
  Starting_Weapon_Effects[1] = 0.8
  Starting_Armor_Effects[1] = 1.3
# Map 3 - Items Price x 0.5
  Starting_Item_Effects[3] = 0.5
# Map 4 - Weapons Price x 1.1, Armors x 1.2
  Starting_Weapon_Effects[4] = 1.1
  Starting_Armor_Effects[4] = 1.2

Just like that. :thumb:


Changing the defaults mid-game, just use:
Code:
$game_system.map_cost_effects.set_item_effect(map_id, effect)
$game_system.map_cost_effects.set_weapon_effect(map_id, effect)
$game_system.map_cost_effects.set_armor_effect(map_id, effect)

Just use nil to erase a map effect. For instance, if later in the game, map 4's weapons would cost 0.8, you would use the set_weapon_effect line, with 4 as the map_id and 0.8 as the effect. Likewise, you didn't want map 3 to have an item effect, use the set_item_effect line with nil as the effect.


Finally, you can change the price manually:
Code:
$game_system.map_cost_effects.items = x.x
$game_system.map_cost_effects.weapons = x.x
$game_system.map_cost_effects.armors = x.x


Enjoy!
 
Well, this lets me think you are a very kind person, but I still have some questions. Why if I already included the SDK 2.3 and MACL2.1, no aliasing method works and shows me an error message?
Later I thought it may be just fine if I just included a # to make it a comment so I could disable the aliasing method. I was completely wrong.

I continued disabling several lines like the has_key?(effect) lines, but then another error showed up.

I kept doing such things until I notice I got an undefined map width error message. I opened the script editor again and it showed the game map script line where the error was produced. Of course I know the game map is not the cause.

What could be the real cause of these error messages?
mmm, it seems to be very late... See ya!
 
OK, disabling lines should never be a good choice...
It seems like effect was not defined.

http://img155.imageshack.us/img155/9710/effectfb1.png[/IMG]

def setup(map_id)
if @map_item_effects.has_key?(effect)
@items = @map_item_effects[map_id]
end
if @map_weapon_effects.has_key?(effect)
@weapons = @map_weapon_effects[map_id]
end
if @map_armor_effects.has_key?(effect)
@armors = @map_armor_effects[map_id]
end
end
def set_item_effect(map_id, effect)
if effect.nil?
@map_item_effects.delete(map_id)
return
end
@map_item_effects[map_id] = effect
end
def set_weapon_effect(map_id, effect)
if effect.nil?
@map_weapon_effects.delete(map_id)
return
end
@map_weapon_effects[map_id] = effect
end
def set_armor_effect(map_id, effect)
if effect.nil?
@map_armor_effects.delete(map_id)
return
end
@map_armor_effects[map_id] = effect
end
end

Thanks in advance!
 
Well, I should tell you that this is an awesome script.

The Starting_Items_Effects Hash works fine and it's the same for the rest of them.
$game_system.map_cost_effects.items = x.x script call is quite useful.

Edit:
Well now the only problem I'm having is the map cost effect settings, I mean, set it up by the current map. I know I can use the Starting_****_Effects, but I couldn't change it mid-game. I know this is secondary, so take your time. there is no hurry.

[But I'm still having problems with $game_system.map_cost_effects.weapons = x.x since it doesn't fit in the script call command window even if I don't leave any spaces.
I know I can use an interpreter class to reduce the size of the script call command to something that will fit on the window, but nothing happened after I tried to do it on my own.
The something happens when I use $game_system.map_cost_effects.set_armor_effect(map_id, effect) that doesn't allow the game to change the price effect. I entered (4, 100) but the price is still the default one, 1x.]

Thanks a lot, Seph, for this useful script.
 
Ok. Here's what I have now:
Code:
class Game_System::MapCostEffects
  Starting_Item_Effects = {}
  Starting_Weapon_Effects = {}
  Starting_Armor_Effects = {}
  attr_accessor :items
  attr_accessor :weapons
  attr_accessor :armors
  attr_reader :map_item_effects
  attr_reader :map_weapon_effects
  attr_reader :map_armor_effects
  def initialize
    @items = 1.0
    @weapons = 1.0
    @armors = 1.0
    @map_item_effects = Starting_Item_Effects
    @map_weapon_effects = Starting_Weapon_Effects
    @map_armor_effects = Starting_Armor_Effects
  end
  def setup(map_id)
    if @map_item_effects.has_key?(map_id)
      @items = @map_item_effects[map_id]
    end
    if @map_weapon_effects.has_key?(map_id)
      @weapons = @map_weapon_effects[map_id]
    end
    if @map_armor_effects.has_key?(map_id)
      @armors = @map_armor_effects[map_id]
    end
  end
  def set_item_effect(map_id, effect)
    if effect.nil?
      @map_item_effects.delete(map_id)
      return
    end
    @map_item_effects[map_id] = effect
    if $game_map.map_id == map_id
      @items = effect
    end
  end
  def set_weapon_effect(map_id, effect)
    if effect.nil?
      @map_weapon_effects.delete(map_id)
      return
    end
    @map_weapon_effects[map_id] = effect
    if $game_map.map_id == map_id
      @weapons = effect
    end
  end
  def set_armor_effect(map_id, effect)
    if effect.nil?
      @map_armor_effects.delete(map_id)
      return
    end
    @map_armor_effects[map_id] = effect
    if $game_map.map_id == map_id
      @armors = effect
    end
  end
end

class Game_System
  attr_reader :map_cost_effects
  alias_method :seph_mapcosteffects_gmsys_init, :initialize
  def initialize
    seph_mapcosteffects_gmsys_init
    @map_cost_effects = MapCostEffects.new
  end
end

class Game_Map
  alias_method :seph_macpcosteffects_gmmap_setup, :setup
  def setup(map_id)
    $game_system.map_cost_effects.setup(map_id)
    seph_macpcosteffects_gmmap_setup(map_id)
  end
end

class RPG::Item
  alias_method :seph_mapcosteffects_rpgitem_price, :price
  def price
    n = seph_mapcosteffects_rpgitem_price
    n = Integer(n * $game_system.map_cost_effects.items)
    return n
  end
end

class RPG::Weapon
  alias_method :seph_mapcosteffects_rpgwpn_price, :price
  def price
    n = seph_mapcosteffects_rpgwpn_price
    n = Integer(n * $game_system.map_cost_effects.weapons)
    return n
  end
end

class RPG::Armor
  alias_method :seph_mapcosteffects_rpgarm_price, :price
  def price
    n = seph_mapcosteffects_rpgarm_price
    n = Integer(n * $game_system.map_cost_effects.armors)
    return n
  end
end


Now, if you have a long line of code, just separate it by objects and method calls (just look for the . marks)
Code:
gs = $game_system
mce = gs.map_cost_effects
mce.weapons = x.x



So, is there still problems?
 
Status
Not open for further replies.

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