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.

Need a small change on a scene mining script (RPG XP)

Ummmm.... hello, Im new here.
I've a Mining script from an unkown author. But its scripted very Very VERY poorly.
It allowes to create a mining scenario. You can give certain events a mining tag via names like mine2 and assign them with items that can be farmed.
When our hero mines a picture will appear that displays as a background. (line 123 bitmap = RPG::Cache.picture("MiningBackground"))
The problem is, that the background picture is only determinable once and for all, so it will be displayed for all locations. But my locations look differnt of course. LOL.
However, I want the background picture to be able to be determined several times. I want to assign different MiningBackGround locations for different locations.
If its up to me. I would bound the MiningBackGround picture to the map id of the mapss. But I dont know how

Code:
=begin

 

                  ||

                  \/

==> INSTRUCTIONS <==

                  /\

                  ||

 

1. Make a new attribute called pick

2. Make some weapons that are picks, and give them the attribute pick,

    their attack determines their effectiveness at mining, between 50 and 250 is good.

3. Make sure your classes can use the picks

4. Make some items to be things that are mined, and go to the mining scene initialization

5. Go to the mining window initialization

6. In the tileset editor, set the terrain tags of some tiles to 1 through 7, this gives them a mining level.

    Higher level mines should have better items in them.

7. In scene map, call mining  has some instructions for you.

8. Import a background for your mining scene, like the one provided. (Put in pictures folder)

9. Import some pictures to the mining animations. (Put in pictures folder)

 

=end

 

#==============================================================================

#     Scene_Mining

#------------------------------------------------------------------------------

#     The scene with a character mining

#==============================================================================

 

class Scene_Mining

  #--------------------------------------------------------------------------

  #    Initialize

  #--------------------------------------------------------------------------

  def initialize(miner, level)

    @miner = miner

    @level = level

    #These are the id's of the items in each mining level.

    @items = [[1, 1, 1, 1, 1, 2, 2, 3],

                    #Level one mines have a 5/8 chance of getting item id 1, 2/8 for item id 2, and 1/8 for item id 3

                    [149, 149, 149, 149],

                    #Level two mines have a 1/4 chance of getting item id 2, 2/4 for item id 3, and 1/4 for item id 3

                    [2, 3, 3, 3, 4],

                    #You get the point,  change these to what you'd like. Good items should be in high level mines.

                    [3, 3, 4, 4, 4, 4, 4, 5, 5, 6],

                    [5, 5, 5, 5, 6, 6, 7],

                    [5, 6, 6, 7],

                    [6, 7, 7, 7]]

  end

  #--------------------------------------------------------------------------

  #    Main

  #--------------------------------------------------------------------------

  def main

    @help_window = Window_Help.new

    @help_window.set_text("Eine Taste drücken um abzubauen!", 1)

    @mining_window = Window_Mining.new(@miner, @level)

    Graphics.transition

    loop do

      Graphics.update

      Input.update

      update

      if $scene != self

        break

      end

    end

    Graphics.freeze

    @help_window.dispose

    @mining_window.dispose

  end

  #--------------------------------------------------------------------------

  #    Update

  #--------------------------------------------------------------------------

  def update

    if Input.trigger?(Input::C)

      @help_window.set_text("Am abbuen...", 1)

      if @mining_window.mine

        item = $data_items[@items[@level - 1][rand(@items[@level - 1].size)]]

        @help_window.set_text("Du hast " + item.name + " gefunden!", 1)

        @mining_window.find(item)

      end

      @mining_window.set_strength

      @help_window.set_text("", 1)

    end

    if Input.trigger?(Input::B)

      $game_system.se_play($data_system.cancel_se)

      $scene = Scene_Map.new

    end

    @mining_window.update

  end

end

 

#==============================================================================

#     Window_Mining

#------------------------------------------------------------------------------

#     The Window that has the mining stuff

#==============================================================================

 

class Window_Mining < Window_Base

  #--------------------------------------------------------------------------

  #    Initialize

  #--------------------------------------------------------------------------

  def initialize(miner, level)

    super(0, 64, 640, 416)

    self.contents = Bitmap.new(width - 32, height - 32)

    @miner = miner

    @level = level

    @speed = -0.012 * @miner.agi + 10.6

    @strength = -1

    @plus = 1

    case @miner.id #What is the id of the actor mining?

    when 1 #If it's actor number one, 

      @graphic = RPG::Cache.picture("civ4miner") #Use this picture as their graphic

    when 2 #If it's actor number two, 

      @graphic = RPG::Cache.picture("civ4miner") #Use this picture as their graphic

    else

      @graphic = RPG::Cache.picture("civ4miner")#otherwise use this one! You can add more whens...

    end

    refresh

  end

  #--------------------------------------------------------------------------

  #    Refresh

  #--------------------------------------------------------------------------

  def refresh

    self.contents.clear

    bitmap = RPG::Cache.picture("MiningBackground")

    self.contents.blt(0, 0, bitmap, Rect.new(0, 0, 608, 384))

    draw_bar

    bitmap = @graphic

    cw = bitmap.width / 5

    ch = bitmap.height

    src_rect = Rect.new(0, 0, cw, ch)

    self.contents.blt(430 - cw / 2, 350 - ch, bitmap, src_rect)

  end

  #--------------------------------------------------------------------------

  #    Mine

  #--------------------------------------------------------------------------

  def mine

    Audio.se_play("Audio/SE/103-Attack15", 100, 250 / @speed)

    for i in 0..3

      self.contents.clear

      bitmap = RPG::Cache.picture("MiningBackground")

      self.contents.blt(0, 0, bitmap, Rect.new(0, 0, 608, 384))

      draw_bar

      bitmap = @graphic

      cw = bitmap.width / 5

      ch = bitmap.height

      src_rect = Rect.new(i * cw, 0, cw, ch)

      self.contents.blt(430 - cw / 2, 350 - ch, bitmap, src_rect)

      wait(@speed)

    end

    wait(@speed * 2)

    refresh

    if rand(324 + 3 * @strength - @miner.atk + @miner.str / 10) > 324 - @miner.atk + (40 * @level + 20) / 10

      return true

    end

    return false

  end

  #--------------------------------------------------------------------------

  #    Wait

  #--------------------------------------------------------------------------

  def wait(time)

    time = 1 if time < 1

    for i in 0..time

      Graphics.update

    end

  end

  #--------------------------------------------------------------------------

  #    Find

  #--------------------------------------------------------------------------

  def find(item)

    self.contents.clear

    bitmap = RPG::Cache.picture("MiningBackground")

    self.contents.blt(0, 0, bitmap, Rect.new(0, 0, 608, 384))

    draw_bar

    bitmap = @graphic

    cw = bitmap.width / 5

    ch = bitmap.height

    src_rect = Rect.new(4 * cw, 0, cw, ch)

    self.contents.blt(430 - cw / 2, 350 - ch, bitmap, src_rect)

    bitmap = RPG::Cache.icon(item.icon_name)

    self.contents.blt(418, 328 - ch, bitmap, Rect.new(0, 0, 24, 24))

    Audio.me_play("Audio/ME/Victory1")

    $game_party.gain_item(item.id, 1)

    wait(80)

    refresh

  end

  #--------------------------------------------------------------------------

  #    Update

  #--------------------------------------------------------------------------

  def update

    super

    @strength += @plus

    if @strength > 27

      set_strength

    end

    draw_bar

  end

  #--------------------------------------------------------------------------

  #    Draw Bar

  #--------------------------------------------------------------------------

  def draw_bar

    self.contents.fill_rect(Rect.new(2, 2, 12, 380), Color.new(0, 0, 0))

    height = @strength * (@strength + 1) / 2

    for i in 0..height

      self.contents.fill_rect(Rect.new(3, 381 - i, 10, 1), Color.new(i * 128 / (height + 1),

            i * 128 / (height + 1), i * 128 / (height + 1)))

    end

  end

  #--------------------------------------------------------------------------

  #    Set Strength

  #--------------------------------------------------------------------------

  def set_strength

    @strength = 0.0

    @plus = (rand(41) + 80.0) / 100.0

  end

end

 
 
change:

bitmap = RPG::Cache.picture("MiningBackground"))

to

bitmap = RPG::Cache.picture("MiningBackground_" + $game_map.map_id))

I think that should work. Then save your pictures as MiningBackground_1, MiningBackground_2, etc.
 
If I do exactly as you say, I get a Synthax Error just when I try to start the game on line 123.
However, in your version above I think you have put too many "(" because you have 2 of them, in the script its only 1. I mean on the end.
So I've also tried using bitmap = RPG::Cache.picture("MiningBackground_" + $game_map.map_id)
but when I try to mine with that I get a error on the same line (123( with the message being cannot convert fixnum into string.
Both dont work. Btw. I think the "+" in your code should not have a space before it. But im not sure.
Still, thanks for replying.
 
Worked, but I've a question left.
Can you tell me how the item assignment for the each mining levels work? I really dont know how to it. Its not explained very well.


Code:
class Scene_Mining

  #--------------------------------------------------------------------------

  #    Initialize

  #--------------------------------------------------------------------------

  def initialize(miner, level)

    @miner = miner

    @level = level

    #These are the id's of the items in each mining level.

    @items = [[1, 1, 1, 1, 1, 2, 2, 3],

                    #Level one mines have a 5/8 chance of getting item id 1, 2/8 for item id 2, and 1/8 for item id 3

                    [149, 149, 149, 149],

                    #Level two mines have a 1/4 chance of getting item id 2, 2/4 for item id 3, and 1/4 for item id 3

                    [2, 3, 3, 3, 4],

                    #You get the point,  change these to what you'd like. Good items should be in high level mines.

                    [3, 3, 4, 4, 4, 4, 4, 5, 5, 6],

                    [5, 5, 5, 5, 6, 6, 7],

                    [5, 6, 6, 7],

                    [6, 7, 7, 7]]

This is the assignment code, but I really dont know how it works.
And the number 149 you can see is just a I tem that I chose.
Thanks btw.
 
Hmm, it looks like you fill it with the items that you should be able to mine when you are that mining level, and they can be duplicated.

So,

@items = [[0, 0, 0], # this is level 1
#Level one mines have a 5/8 chance of getting item id 1, 2/8 for item id 2, and 1/8 for item id 3
[0, 0, 0], # this is level 2
[0, 0, 0], # this is level 3
[0, 0, 0], # this is level 4
[0, 0, 0], # this is level 5
[0, 0, 0]] # this is level 6


In each of those blocks, [0, 0, 0], you put the items you can mine at that level.

So let's say gold is really rare, coal is uncommon, and stone is really common. If gold is item 1, coal is item 2, and stone is item 3, you would do:

[1, 2, 2, 2, 3, 3, 3, 3, 3, 3]


That would make you have a good chance of getting 3, a smaller chance of getting 2, and a really rare chance of getting 1.


I think.
 

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