Help - Search - Members - Calendar
Full Version: Submission: Fishing Script v1.0
RPG RPG Revolution Forums > Scripting > Script Tutorials > RGSS
Prexus
Just put in a new script above Main... following the instructions is a good idea. Animation is at the bottom of post.

CODE
#-------------------------------#
#        Fishing System         #
#-------------------------------#
# Written By: Prexus            #
# www.prexus.nearfantastica.org #
#-------------------------------#
# Information:
# If you have bait and a fishing rod, you can fish in water. Water is designated
# by a Terrain Tag which is not equal (!=) to 0. The skill level of the water
# is equal to the Terrain Tag's value.
#
# If the Lure is equipped (shield), it adds its evasion to the roll for success.
# The roll for success is as follows:
# Success = Random Number between 0 and Fishing Skill + Lure Bonus
#
# The Fishing level system is inherited from the Actor's base EXP table.
# Every time you successfully fish, you gain 1 EXP towards your fishing level.
# This only occurs if the water level is equal to your level, since you cannot
# fish in waters of higher level than you and waters lower level are too easy.
# Leveling in the fishing opens up more waters to you.
#
# Obviously the benefits of fishing are up to the creator of the game but by
# request I added a "Best Fish" field.
# I figure that a fish sells for about 1 Gold per Pound. Thus, any fish
# in the database weighs half its price. This is what is set to Best Fish and
# is compared when catching new fish.
#
# Instructions:
# Search the text "Animations" and do what is requested there.
#
# The first part you see (RFIT1 = [1,2,3] etc.) is defining the Random Fish/Item Tables.
# This is where you customize what items can be yeilded depending on the level of
# the waters you are trying to fish from (Defined by Terrain Tag in Tileset part
# of database editor.)
#
# The difference between RIT and RFT is that RIT only produces every so often.
#
# This is where you'd put weird things like old boots and stuff or rare items.
#
# Below that is the Bait ID which is set to the ID of the item in the database
# that you are using as Bait. There is only one kind of bait (or only needs to be)
# because Lures change the result of success rate not bait.
#
# Below that is the Element IDs of both the pole and the lures.
# Go to the Database and on the System tab add two new elements, one called Pole
# and one called Lure.
# Lures are shields so make a shield in the database for each type of Lure you
# want. The modifier is held in the shield's evasion.
# If you want the lure to increase the chance by 1, then evasion = 1
#
# The chance to succeed is as follows: Success = Random Number between 0 and Fishing Skill + Lure Bonus
# If Success is greater than or equal to the terrain tag of the water, success.
# Anyhow. FishingLevelNames is an array with the levels of fisherman.
# There are of course 8 levels.
#
# All you need to do now is press D in game and you'll see what you need ^^

#Naming Format: Random Fish Table = RFT, Random Item Table = RIT, followed by level number
# [ ] brackets encorperate the IDs of items you can get for each level and type.
# Random Fish table are just the random tables, Random Item Table results in a
# very rare result (generated by if two random numbers between 0 and 19 are equal)
RFT1 = [1, 2, 3]
RIT1 = [4]
RFT2 = [5, 6, 7]
RIT2 = [8]
RFT3 = [9, 10, 11]
RIT3 = [12]
RFT4 = [13, 14, 15]
RIT4 = [16]
RFT5 = [17, 18, 19]
RIT5 = [20]
RFT6 = [21, 22, 23]
RIT6 = [24]
RFT7 = [25, 26, 27]
RIT7 = [28]
RFT8 = [29, 30, 31]
RIT8 = [32]
# ID of the Bait item, there is only one kind of bait.
BaitID = 33
# Element ID of Fishing Pole. Create a new element id in Database > System and
# give that ID to a weapon under Element Set. That Item now acts as a fishing pole.
PoleElemID = 17
# Element ID of Lures. Same as above.
LureElemID = 18

# Names of advancements in fishing level (they go in order from 1-8)
FishingLevelNames = [
"Junior Fisherman",
"Apprentice Fisherman",
"Average Fisherman",
"Sport Fisherman",
"Famous Fisherman",
"Professional Fisherman",
"Master Fisherman",
"He-Who-Speak-To-Water"]

class Scene_Map
  def main
    @spriteset = Spriteset_Map.new
    @message_window = Window_Message.new
    # Added
    @fishing_window = Window_Fishing.new
    # End Added
    @window_wait_count = 0
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @spriteset.dispose
    @message_window.dispose
    # Added
    @fishing_window.dispose
    # End Added
    if $scene.is_a?(Scene_Title)
      Graphics.transition
      Graphics.freeze
    end
  end
  def update
    loop do
      $game_map.update
      $game_system.map_interpreter.update
      $game_player.update
      $game_system.update
      $game_screen.update
      unless $game_temp.player_transferring
        break
      end
      transfer_player
      if $game_temp.transition_processing
        break
      end
    end
    @spriteset.update
    @message_window.update
    # Added
    @fishing_window.update
    if @window_wait_count > 0
      @window_wait_count -= 1
      if @window_wait_count == 0
        @fishing_window.visible = false
      end
    end
    # End Added
    if $game_temp.gameover
      $scene = Scene_Gameover.new
      return
    end
    if $game_temp.to_title
      $scene = Scene_Title.new
      return
    end
    if $game_temp.transition_processing
      $game_temp.transition_processing = false
      if $game_temp.transition_name == ""
        Graphics.transition(20)
      else
        Graphics.transition(40, "Graphics/Transitions/" +
          $game_temp.transition_name)
      end
    end
    if $game_temp.message_window_showing
      return
    end
    if $game_player.encounter_count == 0 and $game_map.encounter_list != []
      unless $game_system.map_interpreter.running? or
             $game_system.encounter_disabled
        n = rand($game_map.encounter_list.size)
        troop_id = $game_map.encounter_list[n]
        if $data_troops[troop_id] != nil
          $game_temp.battle_calling = true
          $game_temp.battle_troop_id = troop_id
          $game_temp.battle_can_escape = true
          $game_temp.battle_can_lose = false
          $game_temp.battle_proc = nil
        end
      end
    end
    if Input.trigger?(Input::B)
      unless $game_system.map_interpreter.running? or
             $game_system.menu_disabled
        $game_temp.menu_calling = true
        $game_temp.menu_beep = true
      end
    end
    # Added
    if @window_wait_count == 0
      if Input.trigger?(Input::Z)
        call_fishing
      end
    end
    # End Added
    if $DEBUG and Input.press?(Input::F9)
      $game_temp.debug_calling = true
    end
    unless $game_player.moving?
      if $game_temp.battle_calling
        call_battle
      elsif $game_temp.shop_calling
        call_shop
      elsif $game_temp.name_calling
        call_name
      elsif $game_temp.menu_calling
        call_menu
      elsif $game_temp.save_calling
        call_save
      elsif $game_temp.debug_calling
        call_debug
      end
    end
  end
  # Added
  def call_fishing
    # Checks to see if anyone has a Fishing Rod. The first person found with one
    # is used for the system.
    for i in 0..$game_party.actors.size
      if $data_weapons[$game_party.actors[i].weapon_id] != nil
        if $data_weapons[$game_party.actors[i].weapon_id].element_set.include?(PoleElemID)
          actor = $game_party.actors[i]
          break
        end
      end
      if i == 3
        # Displays a message if nobody has pole.
        @fishing_window.catch_name("Nobody has Pole")
        @fishing_window.visible = true
        @window_wait_count = 50
        return
      end
    end
    # Takes direction of player and sets looking area to one block infront
    # animid is the ID of the animation you want to play.
    # "Animations"
    # When you press D, the game sets up an animation based on what direction
    # you are facing. With the script i've included a little water splash
    # animation however its up to you to decide how it looks.
    # The lines "animid = 102" is setting the animation to an animation ID.
    # Just change 102 or whatever is there to the ID of the animation
    # you wish to use. Remember, Animations target the player not the spot
    # infront of him.
    character = $game_player
    case character.direction
    when 2
      lookingx = character.x
      lookingy = character.y + 1
      animid = 102
    when 4
      lookingx = character.x - 1
      lookingy = character.y
      animid = 103
    when 6
      lookingx = character.x + 1
      lookingy = character.y
      animid = 104
    when 8
      lookingx = character.x
      lookingy = character.y - 1
      animid = 101
    end
    # If the terrain tag of the spot isn't 0, it goes ahead with the process
    if $game_map.terrain_tag(lookingx,lookingy) != 0
      # Plays animation on the character
      character.animation_id = animid
      # Plays a soundeffect of water.
      Audio.se_play("Audio/SE/021-Dive01")
    else
      # If it is = to 0 then show message.
      @fishing_window.catch_name("Need Water")
      @fishing_window.visible = true
      @window_wait_count = 20
      return
    end
    # Checks to see if you have more than 0 bait.
    if $game_party.item_number(BaitID) > 0
      # Chance to catch is set to a random number 0 to fishing skill
      catch_chance = rand(actor.fishing_skill + 1)
      # If you have a lure equipped (shield)...
      if $data_armors[actor.armor1_id] != nil
        if $data_armors[actor.armor1_id].guard_element_set.include?(LureElemID)
          # Increase chance by the value of the shield's evasion
          catch_chance += $data_armors[actor.armor1_id].eva
        end
      end
      # If you are the approriate level..
      if actor.fishing_skill >= $game_map.terrain_tag(lookingx, lookingy)
        # If the chance results in true..
        if catch_chance >= $game_map.terrain_tag(lookingx,lookingy)
          # Lose 1 bait
          $game_party.lose_item(BaitID, 1)
          # Check to see what Terrain Tag is equal to.
          # The number of the tag is level you require to use.
          case $game_map.terrain_tag(lookingx, lookingy)
          when 1
            # Setting for random chance to get RARE item
            num1 = rand(20)
            num2 = rand(20)
            if num1 != num2
              # If fail, give an item from Fish Table
              item = $data_items[RFT1[rand(RFT1.size)]]
            else
              # If succeed, give an item from Item Table
              item = $data_items[RIT1[rand(RIT1.size)]]
            end
          when 2
            num1 = rand(20)
            num2 = rand(20)
            if num1 != num2
              item = $data_items[RFT2[rand(RFT2.size)]]
            else
              item = $data_items[RIT2[rand(RIT2.size)]]
            end
          when 3
            num1 = rand(20)
            num2 = rand(20)
            if num1 != num2
              item = $data_items[RFT3[rand(RFT3.size)]]
            else
              item = $data_items[RIT3[rand(RIT3.size)]]
            end
          when 4
            num1 = rand(20)
            num2 = rand(20)
            if num1 != num2
              item = $data_items[RFT4[rand(RFT4.size)]]
            else
              item = $data_items[RIT4[rand(RIT4.size)]]
            end
          when 5
            num1 = rand(20)
            num2 = rand(20)
            if num1 != num2
              item = $data_items[RFT5[rand(RFT5.size)]]
            else
              item = $data_items[RIT5[rand(RIT5.size)]]
            end
          when 6
            num1 = rand(20)
            num2 = rand(20)
            if num1 != num2
              item = $data_items[RFT6[rand(RFT6.size)]]
            else
              item = $data_items[RIT6[rand(RIT6.size)]]
            end
          when 7
            num1 = rand(20)
            num2 = rand(20)
            if num1 != num2
              item = $data_items[RFT7[rand(RFT7.size)]]
            else
              item = $data_items[RIT7[rand(RIT7.size)]]
            end
          when 8
            num1 = rand(20)
            num2 = rand(20)
            if num1 != num2
              item = $data_items[RFT8[rand(RFT8.size)]]
            else
              item = $data_items[RIT8[rand(RIT8.size)]]
            end
          end
          # Adds item to inventory
          $game_party.gain_item(item.id, 1)
          if item.price > $game_party.best_fish
            $game_party.best_fish = item.price
            @fishing_window.catch_name(item.name, true)
          else
            @fishing_window.catch_name(item.name)
          end
          # Displays the name of the item you get
          @fishing_window.visible = true
          @window_wait_count = 50
          # If your skill is equal to or less than the terrain tag you get 1 exp
          if $game_map.terrain_tag(lookingx,lookingy) >= actor.fishing_skill
            actor.fishing_exp += 1
          end
          return
        else
          # Random chance of losing bait.
          num1 = rand(50)
          if num1 > 39
            $game_party.lose_item(BaitID, 1)
            @fishing_window.catch_name("Lost Bait")
            @fishing_window.visible = true
            @window_wait_count = 20
          end
          return
        end
      else
        # If level is too low show message
        @fishing_window.catch_name("Level too low.")
        @fishing_window.visible = true
        @window_wait_count = 20
        return
      end
    end
  else
    # If no bait show message
    @fishing_window.catch_name("No Bait")
    @fishing_window.visible = true
    @window_wait_count = 20
    return
  end
  # End Added
end

class Game_Actor < Game_Battler
  # Added
  attr_accessor :fishing_skill
  attr_accessor :fishing_exp
  # End Added
  def setup(actor_id)
    actor = $data_actors[actor_id]
    @actor_id = actor_id
    @name = actor.name
    @character_name = actor.character_name
    @character_hue = actor.character_hue
    @battler_name = actor.battler_name
    @battler_hue = actor.battler_hue
    @class_id = actor.class_id
    @weapon_id = actor.weapon_id
    @armor1_id = actor.armor1_id
    @armor2_id = actor.armor2_id
    @armor3_id = actor.armor3_id
    @armor4_id = actor.armor4_id
    @level = actor.initial_level
    # Added
    @fishing_skill = 1
    # End Added
    @exp_list = Array.new(101)
    make_exp_list
    @exp = @exp_list[@level]
    # Added
    @fishing_exp = @exp_list[@fishing_skill]
    # End Added
    @skills = []
    @hp = maxhp
    @sp = maxsp
    @states = []
    @states_turn = {}
    @maxhp_plus = 0
    @maxsp_plus = 0
    @str_plus = 0
    @dex_plus = 0
    @agi_plus = 0
    @int_plus = 0
    for i in 1..@level
      for j in $data_classes[@class_id].learnings
        if j.level == i
          learn_skill(j.skill_id)
        end
      end
    end
    update_auto_state(nil, $data_armors[@armor1_id])
    update_auto_state(nil, $data_armors[@armor2_id])
    update_auto_state(nil, $data_armors[@armor3_id])
    update_auto_state(nil, $data_armors[@armor4_id])
  end
  # Added
  def fishing_exp=(fishing_exp)
    @fishing_exp = [[fishing_exp, 9999999].min, 0].max
    # Limits fishing skill to level 8
    while @fishing_skill < 8 and @fishing_exp >= @exp_list[@fishing_skill+1] and @exp_list[@fishing_skill+1] > 0
      @fishing_skill += 1
    end
    while @fishing_exp < @exp_list[@fishing_skill] and @fishing_skill > 0
      @fishing_skill -= 1
    end
  end
  # End Added
end

# Added
class Window_Fishing < Window_Base
  def initialize
    super(0,0,640,64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.visible = false
    self.x = $game_player.screen_x
    self.y = $game_player.screen_y
    self.opacity = 0
  end
  def catch_name(name, record = false)
    @name = name
    @record = record
    refresh
  end
  def refresh
    if @name != nil
      self.contents.clear
    end
    self.x = $game_player.screen_x - self.width / 2
    self.y = $game_player.screen_y
    if @record == false
      self.contents.font.color = Color.new(0,0,0,255)
      self.contents.draw_text(6, 2, 600, 32, @name.to_s, 1)
      self.contents.draw_text(6, 0, 600, 32, @name.to_s, 1)
      self.contents.draw_text(4, 2, 600, 32, @name.to_s, 1)
      self.contents.draw_text(4, 0, 600, 32, @name.to_s, 1)
      self.contents.font.color = normal_color
      self.contents.draw_text(5, 1, 600, 32, @name.to_s, 1)
    else
      self.contents.font.color = Color.new(0,0,0,255)
      self.contents.draw_text(6, 2, 600, 32, @name.to_s + " New Record!", 1)
      self.contents.draw_text(6, 0, 600, 32, @name.to_s + " New Record!", 1)
      self.contents.draw_text(4, 2, 600, 32, @name.to_s + " New Record!", 1)
      self.contents.draw_text(4, 0, 600, 32, @name.to_s + " New Record!", 1)
      self.contents.font.color = normal_color
      self.contents.draw_text(5, 1, 600, 32, @name.to_s + " New Record!", 1)
    end
  end
  def update
    super
    self.x = $game_player.screen_x - self.width / 2
    self.y = $game_player.screen_y
  end
end
# End Added

class Window_Base
  # Added
  def draw_fish_level(actor, x, y, width = 174)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, width, 32, FishingLevelNames[actor.fishing_skill - 1].to_s)
  end
  # End Added
end

class Game_Party
  # Added
  attr_accessor :best_fish
  # End Added
  def initialize
    @actors = []
    @gold = 0
    @steps = 0
    # Added
    @best_fish = 0
    # End Added
    @items = {}
    @weapons = {}
    @armors = {}
  end
end

class Window_Status < Window_Base
  def refresh
    self.contents.clear
    draw_actor_graphic(@actor, 40, 112)
    draw_actor_name(@actor, 4, 0)
    draw_actor_class(@actor, 4 + 144, 0)
    draw_actor_level(@actor, 96, 32)
    draw_actor_state(@actor, 96, 64)
    draw_actor_hp(@actor, 96, 112, 172)
    draw_actor_sp(@actor, 96, 144, 172)
    draw_actor_parameter(@actor, 96, 192, 0)
    draw_actor_parameter(@actor, 96, 224, 1)
    draw_actor_parameter(@actor, 96, 256, 2)
    draw_actor_parameter(@actor, 96, 304, 3)
    draw_actor_parameter(@actor, 96, 336, 4)
    draw_actor_parameter(@actor, 96, 368, 5)
    draw_actor_parameter(@actor, 96, 400, 6)
    self.contents.font.color = system_color
    self.contents.draw_text(320, 48, 80, 32, "EXP")
    self.contents.draw_text(320, 80, 80, 32, "NEXT")
    self.contents.font.color = normal_color
    self.contents.draw_text(320 + 80, 48, 84, 32, @actor.exp_s, 2)
    self.contents.draw_text(320 + 80, 80, 84, 32, @actor.next_rest_exp_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(320, 160, 96, 32, "Equipment")
    draw_item_name($data_weapons[@actor.weapon_id], 320 + 16, 128)
    draw_item_name($data_armors[@actor.armor1_id], 320 + 16, 160)
    draw_item_name($data_armors[@actor.armor2_id], 320 + 16, 192)
    draw_item_name($data_armors[@actor.armor3_id], 320 + 16, 224)
    draw_item_name($data_armors[@actor.armor4_id], 320 + 16, 256)
    draw_fish_level(@actor, 320, 288)
    self.contents.draw_text(320, 320, 96, 32, "Best Catch")
    self.contents.draw_text(336, 352, 64, 32, ($game_party.best_fish / 2).to_s + "lbs!")
  end
end


Animation:
http://i2.photobucket.com/albums/y41/Auror...msGFX/Water.png

Demo:
http://prexus.rmxponline.com/prexus/script...hingSystem1.rar
Rpgx
Ahhh fishing.... one of yhe classics. I love these type of thibngs. Keep it up!!

Fishing, reminds me of the good times.....

Peace!
Bearrick
got a new demo for it?
jedicommando
Yea, the demo link does not work.
Holder
Prexus, hasn't been active here since the end of 2005.
The code and animation is fine so there should be no need to use a demo.

Where cool.gif is just simply replace that with B ) but no space.
Bearrick
well i really dont know how to setup the script and all, its confusing the demo helped me last time, but my comp fried so i lost it
reaven
i cant copy the script :S if i paste it into the script editor it stayes blank and i only see spaces
plz help
jens009
QUOTE (reaven @ Dec 28 2008, 03:46 PM) *
i cant copy the script :S if i paste it into the script editor it stayes blank and i only see spaces
plz help

Press reply on the first post.
Copy the script from there. =]

[Show/Hide] Message to reporter

Necroposting in RGSS forum is allowed. =]
reaven
It worked thank you so much!
now i can use al those scripts i couldt copy = D =D thx
BlackMask
It's not working can some 1 make a demo I'm new to this and love fishing like in zelda Twilight princes but yeah it's not working

carnie_natas
immediately not compatible with my scripts,

script ' ' line 186: Syntax Error

any fixes on that?
screaminggingin
What's with all the ????'s ?
I'm currently deleting them all... Maybe it's just my computer...
And also I found this
if $data_weapons[$game_party.actors[i].weapon_id] != nil
it said
"Unidentified weapon_i.d for Nil_Class"
I know nothing about scripts
carnie_natas
since asking for help on this script i immediately disposed of it for lack of help from the creator with bugs,and created a far more complex and strategized luck based fishing system with switches and events,took me a good 4 days to compile,but it includes different rods,bait,locations,fish sizes,and times of day and night to create the random rolls for different fish,all tested and accurate.....just take some time and learn about switches and eventing,you will achieve far more in my opinion,and you are your own troubleshooter!
andry5ury4
how to call this script
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.