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.

Simple Bestiary

Status
Not open for further replies.
Introduction[/FONT]
Hello Everyone, I just made this script because I WAS BORED, it's a simple Bestiary Script.Hope you like.

Script[/FONT]
http://img144.imageshack.us/img144/8670/screencn9.th.png[/IMG]
Code:
#==============================================================================
# ** Scene_bestiary
#------------------------------------------------------------------------------
#  Version: 1.2 Fixed Some Bugs, Code Cleaning, Improved general methods.
#  Author:  Chaosg1
#------------------------------------------------------------------------------
#  Show all the monster in the databse That you have seen.
#==============================================================================
class Scene_Bestiary 
  Opacity = 160
  Chose_Text = "Please chose a Monster from the list below."
  Not_Seen   =  "You haven't seen/battled this Monster."
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    @enemies = []
    @wait = 0
    #Checks all enemies
    for i in 0...$data_enemies.size
      if $game_system.seen[i] == true
        @enemies[i] = i.to_s + ' - ' + $data_enemies[i].name
      elsif $game_system.seen[i] == nil 
        @enemies[i] = i.to_s + ' - ???????'
      end
    end
     @enemies.delete_at(0)
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    @spriteset = Spriteset_Map.new
    draw_windows
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    dispose_windows
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    #Updates the Spriteset
    @spriteset.update
    return @wait -= 1 if @wait != 0
    @enemy_window.active = true if @status_window != nil and @status_window.disposed?
    #Checks Wich Windows is active
    if @enemy_window.active
      @index = @enemy_window.index
      @enemy_window.update
      #Sets Help Text
      @help_window.set_text(Chose_Text, 1)
      #Check The player input
      if Input.trigger?(Input::C)
        validate
      elsif Input.trigger?(Input::B)
        $scene = Scene_Map.new
      end
    else
      if Input.trigger?(Input::B)
        @battler_window.dispose
        @points_window.dispose
        @status_window.dispose
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Validates
  #--------------------------------------------------------------------------
  def validate
    if $game_system.seen[@index+1] == nil
      @enemy_window.active = false
      $game_system.se_play($data_system.buzzer_se)
      @help_window.set_text(Not_Seen,1)
      return @wait = 40
    end
    $game_system.se_play($data_system.decision_se)
    @enemy_window.active = false
    @battler_window = Window_Base.new(160,64,200,200)
    @battler_window.opacity = Opacity
    @battler_window.contents = Bitmap.new(200-32,200-32)
    actor = $data_enemies[@index + 1]
    bitmap = RPG::Cache.battler(actor.battler_name, actor.battler_hue)
    cw = 200 - 32 
    ch = 200 - 32
    x = 0
    x = (100-16 - bitmap.width/2) if not bitmap.width > 200-32  
    @battler_window.contents.fit_blt(x, 0, cw, ch, bitmap, 255)
    #Draw Status
    @status_window = Window_Base.new(360,64,280,200)
    @status_window.opacity = Opacity
    @status_window.contents = Bitmap.new(280-32,200-32)
    @status_window.contents.draw_text(0,0,200,32,"Monster Name:",0)
    @status_window.contents.draw_text(150+4,0,100,32,$data_enemies[@index + 1].name,0)
    @status_window.contents.draw_text(0,36,150,32,"Monster Hp:",0)
    @status_window.contents.draw_text(150+4,36,100,32,$data_enemies[@index + 1].maxhp.to_s,0)
    @status_window.contents.draw_text(0,72,150,32,"Monster Sp:",0)
    @status_window.contents.draw_text(150+4,72,100,32,$data_enemies[@index + 1].maxsp.to_s,0)
    @status_window.contents.draw_text(0,108,150,32,"Monster Exp:",0)
    @status_window.contents.draw_text(150+4,108,100,32,$data_enemies[@index + 1].exp.to_s,0)
    @status_window.contents.draw_text(0,140,150,32,"Monster " + $data_system.words.gold + ":",0)
    @status_window.contents.draw_text(150+4,140,100,32,$data_enemies[@index + 1].exp.to_s,0)
    @points_window = Window_Base.new(160,264,480,216 )
    @points_window.opacity = Opacity
    @points_window.contents = Bitmap.new(480-32,212-32 )
    @points_window.contents.draw_text(0,-10,200,32,"Status:",0)
    #Easy Coordinate modification LOL
    y = 0
    y2 = 32
    @points_window.contents.draw_text(50,y2 + y,120,32,"Monster " + $data_system.words.str + ":",0)
    @points_window.contents.draw_text(50+120+4,y2 + y,100,32,$data_enemies[@index + 1].str.to_s,0)
    @points_window.contents.draw_text(50,2*y2 + y,120,32,"Monster " + $data_system.words.pdef + ":",0)
    @points_window.contents.draw_text(50+120+4,2*y2 + y,100,32,$data_enemies[@index + 1].pdef.to_s,0)
    @points_window.contents.draw_text(50,3*y2 + y,120,32,"Monster " + $data_system.words.mdef + ":",0)
    @points_window.contents.draw_text(50+120+4,3*y2+ y,100,32,$data_enemies[@index + 1].mdef.to_s,0)
    @points_window.contents.draw_text(50,4*y2+ y,120,32,"Monster " + $data_system.words.int + ":",0)
    @points_window.contents.draw_text(50+120+4,4*y2+ y,100,32,$data_enemies[@index + 1].int.to_s,0)
    @points_window.contents.draw_text(234,y2+ y,120,32,"Monster " + $data_system.words.int + ":",0)
    @points_window.contents.draw_text(354 ,y2+ y,100,32,$data_enemies[@index + 1].int.to_s,0)
    @points_window.contents.draw_text(234,2*y2 +y,120,32,"Monster " + $data_system.words.dex + ":",0)
    @points_window.contents.draw_text(354,2*y2+ y,100,32,$data_enemies[@index + 1].dex.to_s,0)
    @points_window.contents.draw_text(234,3*y2+ y,120,32,"Monster " + $data_system.words.atk + ":",0)
    @points_window.contents.draw_text(354,3*y2+ y,100,32,$data_enemies[@index + 1].atk.to_s,0)
    @points_window.contents.draw_text(234,4*y2+ y,120,32,"Monster EVA:" ,0)
    @points_window.contents.draw_text(354,4*y2+ y,100,32,$data_enemies[@index + 1].eva.to_s,0)
  end
  #--------------------------------------------------------------------------
  # * Main Draw
  #--------------------------------------------------------------------------
  def draw_windows
    #Make Enemy Window
    @enemy_window = Window_Command.new(160,@enemies)
    @enemy_window.x = 0
    @enemy_window.y = 64
    @enemy_window.height = 480-64
    @enemy_window.opacity = Opacity
    #Make Help_Window
    @help_window = Window_Help.new
    @help_window.opacity = Opacity
  end
  #--------------------------------------------------------------------------
  # * Main Dispose
  #--------------------------------------------------------------------------
  def dispose_windows
    #Make Enemy Window
    @enemy_window.dispose
    @help_window.dispose
  end
end
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles data surrounding the system. Backround music, etc.
#  is managed here as well. Refer to "$game_system" for the instance of 
#  this class.
#==============================================================================
class Game_System
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :seen
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias cg1_bestiary_initialize initialize
  def initialize
    cg1_bestiary_initialize
    @seen = {}
  end
end
#==============================================================================
# ** Game_Enemy
#------------------------------------------------------------------------------
#  This class handles enemies. It's used within the Game_Troop class
#  ($game_troop).
#==============================================================================
class Game_Enemy < Game_Battler
  alias cg1_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     troop_id     : troop ID
  #     member_index : troop member index
  #--------------------------------------------------------------------------
  def initialize(troop_id, member_index)
    cg1_initialize(troop_id, member_index)
    $game_system.seen[@enemy_id] = true 
  end
end
class Bitmap
  #-------------------------------------------------------------------------
  # * Name:      Fit BLT
  #   Info:      Zooms to Width and Height, if needed
  #   Author:    Trickster
  #   Call Info: Five or Six Arguments, Integer X and Y Define Position
  #              Integer Width and Height Defines Dimensions
  #              Bitmap bitmap bitmap to transfer
  #              Integer opacity, opacity
  #-------------------------------------------------------------------------
  def fit_blt(x, y, width, height, bitmap, opacity = 255)
    w = bitmap.width
    h = bitmap.height
    conversion = w / h.to_f
    if w > width or h > height
      if conversion <= 1
        zoom_x, zoom_y = width * conversion, height
      else
        zoom_x, zoom_y = width, height * conversion ** -1
      end
      dest_rect = Rect.new(x, y, zoom_x, zoom_y)
      self.stretch_blt(dest_rect, bitmap, bitmap.rect, opacity)
    else
      self.full_blt(x, y, bitmap, opacity)
    end
  end
  #-------------------------------------------------------------------------
  #   Name:      Full Block Transfer
  #   Info:      Draws a Bitmap
  #   Author:    Trickster
  #   Call Info: Three or Four Arguments
  #              Integer X and Y define position
  #              Bitmap bitmap is the bitmap to draw
  #              Integer Opacity is the transparency (defaults to 255)
  #   Comment:   Lazy method for people who don't want to type bitmap.rect
  #-------------------------------------------------------------------------
  def full_blt(x,y,bitmap, opacity = 255)
    self.blt(x,y,bitmap,bitmap.rect, opacity)
  end
end
Instructions[/FONT]
Just place this above main, get in a battle, and to call Use $scene = Scene_Bestiary.new
Notes:[/FONT]
Credit me and Trickster Because I used some methods of him.
 
I don't want to see duplicate posts asking for screens/demos/scripts. If the author does not give any screens please do not make posts complaining about it as they are indeed spam, and does not contribute anything to the script. How hard is it to create a new project add the script and then test it out for yourself.

Indepth Code Analysis



Comments
  • Okay I see that you used my fit_blt and full_blt methods, but you should add them to the top of the script and include in the directions to delete them if they have MACL. the reason for this is that I could edit of the the methods, and if you have the older version of it in your script that could cause some problems.
Coding
  • I see few indentation problems, but the bulk of it is properly indented, good job
  • Most of the code is commented as well.
  • Code:
     @seen = {}
    Code:
        for i in 0...$data_enemies.size
          if $game_system.seen[i] == nil
            $game_system.seen[i] = false
            @enemies[i] = i.to_s + ' - ???????'
          elsif $game_system.seen[i] == true
            @enemies[i] = i.to_s + ' - ' + $data_enemies[i].name
          elsif $game_system.seen[i] == false
            @enemies[i] = i.to_s + ' - ???????'
          end
        end
    If you just create a Hash the default value if the key doesn't exist is nil. There is no need to check if its false if you wanted it to return false then replace the {} in the first section of code with Hash.new(false) but one of those sections of code can be cut out (either the false or the nil section)
  • Code:
      def initialize(menu_index = 0)
        @menu_index = menu_index
    This can be safely removed since you aren't using it anywhere in this script
  • Code:
          loop do 
            wait -= 1
            Graphics.update
            if wait == 0
              @enemy_window.active = true
              break
            end
          end
    I don't agree that you should use this method for waiting, instead just create an instance variable @wait_count, set it to 0 in the initialize method and add this code in your update method after the objects that need to be updated
    Code:
        # If waiting
        if @wait_count > 0
          # Decrease wait count
          @wait_count -= 1
          return
        end
    Easier and more effective.
  • Well I don't agree with the creation and disposing of windows in the middle of while a scene is running, just create all of your windows in the main method and dispose them at the end of the main method. and then use <window>.visible. There are special cases of this though (In Scene_Battle). But this is just a suggestion you may want to consider.
  • Okay don't use Window_Base to create your windows, just create a class that inherits from Window_Base, so that your Scene_ Class isn't bogged down with code to create the window.
  • Okay you should use loop to draw the parameters and use Window_Base#draw_actor_parameter or an edited version of it (redefine this method in the Window_ class of your script)
  • Code:
    $game_system.seen[@enemy_id] = true if $game_system.seen[@enemy_id] == false or $game_system.seen[@enemy_id] == nil
    just change this line to
    Code:
    $game_system.seen[@enemy_id] = true
Overall, good job I can see that you are improving, but consider polishing this up a bit more to remove the unneeded stuff
 
wow, this is the first beastiary I've seen that is RTAB compactible and I like the layout. Great work!

though... there are some problems with it i found ^^
1) when you go to the beastiary, after you exit it all "light effects" of the light effects script will start moving with you ^^
2) the game often crashes when you have viewed the beastiary and then go to the next map.

can this be fixed?
 
@zealex: It doesn't crash for, anyway does it gives you an error?
Also Could I see the Light Effects script??
Edit: Thanx By the comments!
 
The game just simply 'Crashes'
It just closes and gives this Send error report thingy which usually comes after you have closed something by ctrl+alt+del.
Game.exe has encountered an error blablabla...
the crashing might be cause of some other script im using too i guess... i would really like
someone to fix up my scripts... some of them aren't compactible with each other.

Light effects:
how can i make this [Content hidden] thing?
I'll post the script in it.
Code:
#==============================================================================
# ** Light Effects
#==============================================================================
# Near Fantastica
# Version 4
# 29.11.05 
#==============================================================================
# The Light Effects Script adds light effects to events that are setup correctly
# this light can be used to simulate fires, street lights, windows and lamps.
# The light effects also have antilag build into them.
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log("Light Effects", "Near Fantastica", 4, "29.11.05")

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------

if SDK.state("Light Effects") == true
  class Spriteset_Map
   #---------------------------------------------------------------------------
   alias nf_les_spriteset_map_initalize initialize
   alias nf_les_spriteset_map_dispose dispose
   alias nf_les_spriteset_map_update update
   #---------------------------------------------------------------------------
   def initialize
     @light_effects = {}
     refresh_lights
     nf_les_spriteset_map_initalize
   end
   #---------------------------------------------------------------------------
   def dispose
     nf_les_spriteset_map_dispose
     dispose_lights
   end
   #---------------------------------------------------------------------------
   def update
     nf_les_spriteset_map_update
     refresh_lights
   end
   #---------------------------------------------------------------------------
   def dispose_lights
     for effect in @light_effects.values
       effect.light.dispose
     end
     @light_effects = {}
   end
   #---------------------------------------------------------------------------
   def refresh_lights
     for event in $game_map.events.values
       type = SDK.event_comment_input(event, 1, "Light Effects").to_s.upcase!
       if type.nil? and @light_effects.include?(event)
         @light_effects[event].light.dispose
         @light_effects.delete(event)
         next
       end
       if @light_effects.include?(event)
         update_lights(@light_effects[event])
         next
       end
       next if type.nil?
       setup_lights(event, type)
     end
   end
   #---------------------------------------------------------------------------
   def setup_lights(event, type)
     return if type.nil?
     case type
     when "GROUND"
       light_effects = Light_Effect.new(event,type)
       light_effects.light.zoom_x = 200 / 100.0
       light_effects.light.zoom_y = 200 / 100.0
       light_effects.light.opacity = 50
       light_effects.light.x = (light_effects.event.real_x - 200 - $game_map.display_x) / 4
       light_effects.light.y = (light_effects.event.real_y - 200 - $game_map.display_y) / 4
       @light_effects[event] = light_effects
     when "FIRE"
       light_effects = Light_Effect.new(event,type)
       light_effects.light.zoom_x = 300 / 100.0
       light_effects.light.zoom_y = 300 / 100.0
       light_effects.light.opacity = 100
       light_effects.light.x = (event.real_x - 300 - $game_map.display_x) / 4
       light_effects.light.y = (event.real_y - 300 - $game_map.display_y) / 4
       @light_effects[event] = light_effects
     when "LAMPPOST"
       light_effects = Lamp_Effect.new(event,"LAMPPOST")
       light_effects.light.opacity = 100
       light_effects.light.x = (-0.25 * $game_map.display_x) + (event.x * 32) - 25
       light_effects.light.y = (-0.25 * $game_map.display_y) + (event.y * 32) - 15       
       @light_effects[event] = light_effects
     when "LEFTLANTERN"
       light_effects = Light_Effect.new(event,type)
       light_effects.light.opacity = 150
       light_effects.light.x = (-0.25 * $game_map.display_x) + (light_effects.event.x * 32) - 20
       light_effects.light.y = (-0.25 * $game_map.display_y) + (light_effects.event.y * 32) - 5
       @light_effects[event] = light_effects
     when "RIGHTLANTERN"
       light_effects = Light_Effect.new(event,type)
       light_effects.light.opacity = 150
       light_effects.light.x = (-0.25 * $game_map.display_x) + (light_effects.event.x * 32) - 10
       light_effects.light.y = (-0.25 * $game_map.display_y) + (light_effects.event.y * 32) - 5
       @light_effects[event] = light_effects
     when "WINDOW"
       light_effects = Light_Effect.new(event,type)
       light_effects.light.opacity = 75
       light_effects.light.x = (-0.25 * $game_map.display_x) + (light_effects.event.x * 32) 
       light_effects.light.y = (-0.25 * $game_map.display_y) + (light_effects.event.y * 32)
       @light_effects[event] = light_effects
     end
   end
   #---------------------------------------------------------------------------
   def update_lights(effect)
     return if not in_range?(effect.event)
     case effect.type
     when "GROUND"
       effect.light.x = (effect.event.real_x - 200 - $game_map.display_x) / 4
       effect.light.y = (effect.event.real_y - 200 - $game_map.display_y) / 4
     when "FIRE"
       effect.light.x = (effect.event.real_x - 300 - $game_map.display_x) / 4
       effect.light.y = (effect.event.real_y - 300 - $game_map.display_y) / 4
     when "LAMPPOST"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 25
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 15
     when "LEFTLANTERN"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 20
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 5
     when "RIGHTLANTERN"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 10
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 5
     when "WINDOW"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 15
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 20
     end
   end
   #---------------------------------------------------------------------------
   def in_range?(object)
     screne_x = $game_map.display_x
     screne_x -= 350
     screne_y = $game_map.display_y
     screne_y -= 350
     screne_width = $game_map.display_x
     screne_width += 2950
     screne_height = $game_map.display_y
     screne_height += 2250
     return false if object.real_x <= screne_x
     return false if object.real_x >= screne_width
     return false if object.real_y <= screne_y
     return false if object.real_y >= screne_height
     return true
   end
  end
  
  #============================================================================
  # â–  Light Effects Class
  #============================================================================
  
  class Light_Effect
   #---------------------------------------------------------------------------
   attr_accessor :light
   attr_accessor :event
   attr_accessor :type
   #---------------------------------------------------------------------------
   def initialize(event, type)
     @light = Sprite.new
     @light.bitmap = RPG::Cache.picture("LE.PNG")
     @light.visible = true
     @light.z = 1000
     @event = event
     @type = type
   end
  end
 
  #============================================================================
  # â–  Lamp Effects Class
  #============================================================================
  
  class Lamp_Effect
   #---------------------------------------------------------------------------
   attr_accessor :light
   attr_accessor :event
   attr_accessor :type
   #---------------------------------------------------------------------------
   def initialize(event, type)
     @light = Sprite.new
     lamp = Bitmap.new(64,64)
     lamp = RPG::Cache.picture("LE.PNG")
     @light.bitmap = Bitmap.new(128,64)
     src_rect = Rect.new(0, 0, 64, 64) 
     @light.bitmap.blt(0, 0, lamp, src_rect) 
     @light.bitmap.blt(20, 0, lamp, src_rect) 
     @light.visible = true
     @light.z = 1000
     @event = event
     @type = type
   end
 end
 
#------------------------------------------------------------------------------
# * End SDK Enable Test
#------------------------------------------------------------------------------
end
 
Yup, it still happens,
crashing also.
And now i sometimes get an error when exiting the beastiary.
Undefined method 'dispose' for blablabla.

uh I think it is some of my other scripts that is causing this.
btw when i put it above all other scripts [just above the SDK] the monsters wont appear in the beastiary at all
 
^^It should be compatible it SDK, put it below the SDK...

The rest I dunno why it is Crashing, or Why the events move with you It has something to do with the antilag.. I will try to fix it anyway..
 
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