Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NPC Information
#1
NPC Information
by SephirothSpawn
Oct 1 2005

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given.


Updated Attributes, Script Calling & Window Setup. (10.3.05)


What it does:

Basically, this will add information about NPCs you meet throughout your game.

Instructions:

Make a call script in an event like this:
Code:
a = "name";b = location
c = sex;d = age
e = height;f = weight
g = job;h = hobby
i = alignment;j = reputation
k = bio
npc = NPC.new(a, b, c, d, e, f, g, h, i, j, k)
$npc_info.add_npc(npc)
or To fill a specific Index
$npc_info.input_npc(npc, index)

New Features
You can also now fill in blank nps. However, if you do this, all current npcs will be deleted, so do this at the start of the game (recommended).
Code:
$npc_info.fill_npcs(size)

It will fill a list of Blank NPC's.

To substitute in those NPC's, use:
Code:
$npc_info.input_npc(npc, index)

Updated: I updated how the NPC class Initializes, so it makes NPC calling a little easier. Just Fill in the info. For further Instructions, See Script.

Heres the code. Just add it somewhere above Main.

Code:
#================================
# NPC Information
#  Created By SephirothSpawn
#   Last Updated: 10.03.05
#------------------------ Instructions ------------------------
#Make an Event with a Call Script
#Use this template:
#  -------------------------------------------------------
#    a = "name";b = location
#    c = sex;d = age
#    e = height;f = weight
#    g = job;h = hobby
#    i = alignment;j = reputation
#    k = bio
#    npc = NPC.new(a, b, c, d, e, f, g, h, i, j, k)
#    $npc_info.add_npc(npc)
#    or To fill a specific Index
#    $npc_info.input_npc(npc, index)
#  -------------------------------------------------------
#  
#  A = "Name"
#    Set this to a String.
#      IE: a = "SephirothSpawn"
#  
#  B = Location
#      Make a string that identify's the NPC's usuall location
#        IE: b = "Behind Your!!!"
#      To use the Current Map, just use:
#        b = $game_map.name
#    
#  C = Age
#    Default is set to recieve Years.
#      IE: c = 5 -> "5 Years"
#    To Make it custom, use a string.
#      IE: c = "Eighteen Years"
#      
#  D = Sex
#    0 = Male;1 = Female;2 = Unknown
#      IE: d = 0 -> Male
#    Custom: d = "Yes Please"
#    
#  E = Height
#    Set in Mini-Array [', "].
#      IE: e = [5, 10] -> 5' 10"
#    Set to Number
#      e = 5   -> 5 Feet
#    Set to string
#      e = "5 Feet, 3 Inches"
#    
#  F = Weight
#    Default is Set to recieve Pounds (Lbs.)
#      IE: f = 135 -> "135 Pounds"
#    To Make it custom, use a string.
#      IE: f = "45 Kilograms"
#
#  G = Job / Class
#    Set Job with String:
#      g = "Delievery Boy"
#    Or set it with Database Classes
#      g = $data_classes[ID#].name
#
#  H = Hobby
#    Set with String:
#      h = "Hiding & Seeking"
#
#  I = Alignment
#    Set with Numeric (-: Evil, 0: Neutral, +: Good) (-100 --- 100)
#      i = -50  -> "Whatever String Valued at -50"    IE: Dr.Evil
#      i = 43 -> "Whatever String Valued at 43"   IE: Holy Man
#    Set with String
#      i = "Pretty Evil"
#
#  J = Repulation
#    Set with Numeric (-: Not known, 0: Normal, +: Worldly Known) (-100 --- 100)
#      j = -70 -> "Whatever String Valued at -70"    IE: Who?
#      j = 100 -> "Whatever String Valued at 50"    IE: Near Fantastica
#
#  K = Bio
#    Make a String that descripes the NPC.
#      IE: k = "Lalalalalalala" -> "Lalalalalalala"
#    Make a Array to describe NPC (3 Max)
#      IE. l1 = "This is Line one"
#           l2 = "This is Line two"
#           l3 = "This is Line three"
#           k = [l1, l2, l3]
#================================
  
#================================
#Class NPC
#================================

class NPC
  attr_accessor :name, :location, :sex, :age, :height, :weight
  attr_accessor :job, :hobby, :alignment, :reputation, :bio
  def initialize(name = "?????", location = "?????",
                    sex = "Unknown", age = "???",
                    height = "???", weight = "???",
                    job = "???", hobby = "???",
                    alignment = "???", reputation = "???",
                    bio = "???")
    @name, @location, @sex, @age, @height, @weight = name, location, sex, age, height, weight
    @job, @hobby, @alignment, @reputation, @bio = job, hobby, alignment, reputation, bio
  end
end

#================================
#Class NPC Information
#================================

class NPC_Information
  attr_accessor :npcs, :list
  #--------------------------------------------------------------
  # Attribute Setup
  #--------------------------------------------------------------
  def initialize
    @npcs = [];@list = []
  end
  #--------------------------------------------------------------
  # Add NPC
  #--------------------------------------------------------------
  def add_npc(npc)
    name = npc.name
    if !@npcs.include?(name) or npc.name == "?????"
      @npcs.push(name)
      @list.push(npc)
    end
  end
  #--------------------------------------------------------------
  # Fill NPCs
  #--------------------------------------------------------------
  def fill_npcs(size)
    @npcs.fill("???", size)
    @list.fill(NPC.new, size)
  end
  #--------------------------------------------------------------
  # Input NPC
  #--------------------------------------------------------------
  def input_npc(npc, input)
    name = npc.name
    @npcs[input] = name
    @list[input] = npc
  end
end
  
#================================
#Class Scene NPC Information
#================================

class Scene_NPC_Information
  #--------------------------------------------------------------
  # Sets Up Scene
  #--------------------------------------------------------------
  def main
    #--- Variable Setup ---
    @current_npc = 0
    #--- Window Setup ---
    @profile = Window_Profile.new
      @profile.x, @profile.y, @profile.opacity = 32, 32, 200
    #--- Sprite Setup ---
    @background = Sprite.new
      @background.bitmap = RPG::Cache.picture("Background")
    @border = Sprite.new
      @border.bitmap = RPG::Cache.picture("Border")
      @border.z = 9950
    #--- Scene Processing ---
    @objects = [@background, @profile, @border]
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @objects.each {|x| x.dispose}
  end
  #--------------------------------------------------------------
  # Updates Scene
  #--------------------------------------------------------------
  def update
    @profile.refresh(@current_npc)
    $scene = Scene_Map.new if Input.trigger?(Input::B)
    if Input.trigger?(Input::RIGHT)
      if @current_npc == $npc_info.list.size - 1
        @current_npc = 0
      else
        @current_npc += 1
      end
    end
    if Input.trigger?(Input::LEFT)
      if @current_npc == 0
        @current_npc = $npc_info.list.size - 1
      else
        @current_npc -= 1
      end
    end
  end
end
  
#================================
#Class Window Profile
#================================

class Window_Profile < Window_Base
  #--------------------------------------------------------------
  # Window Setup
  #--------------------------------------------------------------
  def initialize
    super(0, 0, 576, 416)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $defaultfonttype
    self.contents.font.size = 22
    self.contents.font.color = Color.new(0, 0, 0, 255)
  end
  #--------------------------------------------------------------
  # Window Refresh
  #--------------------------------------------------------------
  def refresh(num)
    self.contents.clear
    npc = $npc_info.list[num]
    #--- Sets Attributes ---
    # Name
    name = npc.name
    # Location
    location = npc.location
    # Age
    if npc.age.class == Fixnum
      age = "#{npc.age} Years Old"
    else
      age = npc.age
    end
    # Sex
    if npc.sex.class == Fixnum
      case npc.sex
        when 0;sex = "Male"
        when 1;sex = "Female"
        when 2;sex = "Unknown";end
    else
      sex = npc.sex
    end
    # Height
    if npc.height.class == Array
      height = "#{npc.height[0]} Foot, #{npc.height[1]} Inches"
    elsif npc.height.class == Fixnum
      height = "#{npc.height} Feet"
    else
      height = npc.height
    end
    # Weight
    if npc.weight.class == Fixnum
      weight = "#{npc.weight} Pounds"
    else
      weight = npc.weight
    end
    # Job
    job = npc.job
    # Hobby
    hobby = npc.hobby
    # Alignment
    if npc.alignment.class == Fixnum
      a = npc.alignment
      alignment = "Demon" if a <= -80
      alignment = "Merciless" if a <= -60 && a > -80
      alignment = "Corrupt" if a <= -40 && a > -60
      alignment = "Wicked" if a <= -20 && a > -40
      alignment = "Bad" if a < -0 && a > -20
      alignment = "Neutral" if a == 0
      alignment = "Good" if a > 0 && a <= 20
      alignment = "Honorable" if a > 20 && a <= 40
      alignment = "Noble" if a > 40 && a <= 60
      alignment = "Virtuous" if a > 60 && a <= 80
      alignment = "Angel" if a > 80
      alignment += "  (#{npc.alignment})"
    else
      alignment = npc.alignment
    end
    # Reputation
    if npc.reputation.class == Fixnum
      a = npc.reputation
      reputation = "Who?" if a <= -75
      reputation = "Mysterious" if a <= -50 && a > 75
      reputation = "Nameless" if a <= 25 && a > 50
      reputation = "Unknown" if a < 0 && a > 25
      reputation = "Neurtal" if a == 0
      reputation = "Known" if a > 0 && a < 25
      reputation = "Established" if a >= 25 && a < 50
      reputation = "Notorious" if a >= -50 && a < 75
      reputation = "Superstar" if a >= -75
    else
      reputation = npc.reputation
    end
    # Bio
    bio = npc.bio
    #--- Draws Picture And Text ---
    draw_pic(8, 32, npc)
    self.contents.font.size = 22
    self.contents.draw_text(8, 0, 150, 22, name, 1)
    self.contents.draw_text(176, 0, 370, 22, "Location: " + location)
    left = ["Sex:", "Height:", "Job:", "Alignment:"]
    right = ["Age:", "Weight:", "Hobby:", "Reputation:"]
    left_ = [sex, height, job, alignment]
    right_ = [age, weight, hobby, reputation]
    for i in 0...left.size
      self.contents.draw_text(176, 26 + 44 * i, 100, 22, left[i])
      self.contents.draw_text(200, 48 + 44 * i, 100, 22, right[i])
      self.contents.draw_text(326, 26 + 44 * i, 218, 22, left_[i])
      self.contents.draw_text(350, 48 + 44 * i, 294, 22, right_[i])
    end
    self.contents.draw_text(320, 210, 224, 22, "Profile:  " + (num + 1).to_s + " / " + $npc_info.list.size.to_s)
    if npc.bio.class == Array
      for i in 0...bio.size
        self.contents.draw_text(48, 288 + i * 22,448, 22, bio[i], 1)
      end
    else
      self.contents.draw_text(48, 310, 448, 22, bio, 1)
    end
  end
  #=================
  # ----- Draw NPC Picture -----
  #=================
  def draw_pic(x, y, npc)
    if npc.name == "?????"
      bitmap = RPG::Cache.picture("NPCS/Blah")
    else
      bitmap = RPG::Cache.picture("NPCS/" + npc.name)
    end
    cw = bitmap.width
    ch = bitmap.height
    src_rect = Rect.new(0, 0, cw, ch)
    self.contents.blt(x, y, bitmap, src_rect)
  end
end

#================================
#Class Scene_Title
#================================

class Scene_Title
  #=====================
  # ----- Alias' New Game Method -----
  #=====================
  alias new_game command_new_game
  #==========================
  #----- Adds NPC Information -----
  #==========================
  def command_new_game
    $npc_info = NPC_Information.new
    new_game
  end
end


Any Request?

I would like to add more attributes to the NPC's. Any Ideas you'd like to add?

Also, If anyone has and request or a design they would like me to make the scene, just ask and I can do it.


Future Add in

As request by some people, Im modifing this Into 2 other uses:

-Pokedex
-ABS Bestairy
}




Users browsing this thread: