scripting suggestians / shortcuts

Started by nathmatt, May 30, 2010, 05:45:41 pm

Previous topic - Next topic

nathmatt

May 30, 2010, 05:45:41 pm Last Edit: May 30, 2010, 09:23:09 pm by nathmatt
i made a class of script calls with things like chapter save inn messages random npc messages just thought i also combined this with a AMS i made to go with it just some scripting ideas

edit: what I meant was to give ppl a suggestion to create a class for everything they use a lot i may mess around with it some and post it up with a small tutorial on how to add to it

edit:  OK here is what i have

calls
Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Script Calls / AMS by Nathmatt
# Version: 1.00
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
#                                    PART 1
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#   
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# # 
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# # 
# #  You are free:
# # 
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# # 
# #  Under the following conditions:
# # 
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# # 
# #  Noncommercial. You may not use this work for commercial purposes.
# # 
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# # 
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# # 
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# # 
# #  - Nothing in this license impairs or restricts the author's moral rights.
# # 
# #----------------------------------------------------------------------------
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
class Calls
 
  # The Game_Variables id used to store all you locations
  variable_id = 13
  #-----------------------------------------------------------------------------
  # These are used for the AMS
  #-----------------------------------------------------------------------------
  # NPC random chat
  #-----------------------------------------------------------------------------
  # the gender can be any condition you want
  def random_message(gender)
    id = rand(9)
    if gender == 'female'
      case id
      when 0 then return 'Can i help you with somthing?'
      when 1 then return 'Do you need somthing?'
      when 2 then return 'Hey sweetie.'
      when 3 then return 'Hi.'
      when 4 then return 'Hello.'
      when 5 then return 'Have you met my daughter?'
      when 6 then return 'Sorry i am married.'
      when 7 then return 'If only i was younger.'
      when 8 then return 'Better not let my husband see you.'
      when 9 then return '...'
      end
    elsif gender == 'male'
      case id
      when 0 then return 'What do you want?'
      when 1 then return 'Nice day isnt it?'
      when 2 then return 'What?'
      when 3 then return 'Get out of my face.'
      when 4 then return 'Hi.'
      when 5 then return 'Hello'
      when 6 then return 'Can i help you with somthing?'
      when 7 then return 'Did you need somthing.'
      when 8 then return 'Back off.'
      when 9 then return '...'
      end
    end
  end
  #-----------------------------------------------------------------------------
  # Basic
  #-----------------------------------------------------------------------------
  def Basic_Messages(name,i)
    case i
    when 0 then return "\\Name[#{name}]Sorry you do not have enough."
    when 1 then return "\\Name[#{name}]Come again."
    end
  end
  #-----------------------------------------------------------------------------
  # Inn
  #-----------------------------------------------------------------------------
  def Inn(name,gold)
    $game_temp.choice_start += 1
    return "\\Name[Inn Keeper]Would you Like to stay at the \\c[2]#{name}\\c[0]" +
    "\n for \\c[6]#{gold}\\c[0] \\gold."
  end
  #-----------------------------------------------------------------------------
  # Shop
  #-----------------------------------------------------------------------------
  def Shop(name)
    return "\\Name[Shop Keeper]Would you Like to check out my wares."
  end
  #-----------------------------------------------------------------------------
  # Icon
  #-----------------------------------------------------------------------------
  def Icon(type,id)
    case type
    when 'i'
      data = $data_items[id]
    when 'w'
      data = $data_weapons[id]
    when 'a'
      data = $data_armors[id]
    when 's'
      data = $data_skills[id]
    end
    return RPG::Cache.icon(type.icon_name)
  end
  #-----------------------------------------------------------------------------
  # initialize
  #-----------------------------------------------------------------------------
  def initialize
    @map_infos = load_data('Data/MapInfos.rxdata')
    @map_infos.keys.each {|key| @map_infos[key] = @map_infos[key].name}
  end
  #-----------------------------------------------------------------------------
  # Map Name
  #-----------------------------------------------------------------------------
  def Map_Name
    @map_infos[$game_map.map_id]
  end
  #-----------------------------------------------------------------------------
  # These are used the script calls
  #-----------------------------------------------------------------------------
  # Play Time
  #-----------------------------------------------------------------------------
  def Play_Time
    @total_sec = Graphics.frame_count / Graphics.frame_rate
    hour = @total_sec / 60 / 60
    min = @total_sec / 60 % 60
    sec = @total_sec % 60
    time = sprintf("%02d:%02d:%02d", hour, min, sec)
    return time.to_s
  end
  #-----------------------------------------------------------------------------
  # Save Location
  #-----------------------------------------------------------------------------
  def Save_Location(id)
    $game_variables[variable_id][id] = [$game_map.map_id,$game_player.x,
    $game_player.y,$game_player.direction]
    return
  end
  #-----------------------------------------------------------------------------
  # Load Location
  #-----------------------------------------------------------------------------
  def Load_Location(id)
    loc = $game_variables[variable_id][id]
    $game_temp.player_new_map_id = loc[0]
    $game_temp.player_new_x = loc[1]
    $game_temp.player_new_y = loc[2]
    $game_temp.player_new_direction = loc[3]
    return
  end
  #-----------------------------------------------------------------------------
  # Chapter Save
  #-----------------------------------------------------------------------------
  def Save(index)
    filename = "Auto_Save/Chapter#{index}.rxdata"
    file = File.open(filename, "wb")
    characters = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      characters.push([actor.character_name, actor.character_hue])
    end
    # Write character data for drawing save file
    Marshal.dump(characters, file)
    # Wrire frame count for measuring play time
    Marshal.dump(Graphics.frame_count, file)
    # Save magic number
    # (A random value will be written each time saving with editor)
    $game_system.magic_number = $data_system.magic_number
    # Write each type of game object
    Marshal.dump($game_system, file)
    Marshal.dump($game_switches, file)
    Marshal.dump($game_variables, file)
    Marshal.dump($game_self_switches, file)
    Marshal.dump($game_screen, file)
    Marshal.dump($game_actors, file)
    Marshal.dump($game_party, file)
    Marshal.dump($game_troop, file)
    Marshal.dump($game_map, file)
    Marshal.dump($game_player, file)
    file.close
  end
  #-----------------------------------------------------------------------------
  # Call Self Switch
  #-----------------------------------------------------------------------------
  def Call_Self_Switch(id,condition,let = 'A')
    $game_self_switches[[$game_map.map_id, id, let]] = conditon
    return
  end
 
end

$calls = Calls.new


AMS
Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Script Calls / AMS by Nathmatt
# Version: 1.00
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
#                                    PART 2
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#   
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# # 
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# # 
# #  You are free:
# # 
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# # 
# #  Under the following conditions:
# # 
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# # 
# #  Noncommercial. You may not use this work for commercial purposes.
# # 
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# # 
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# # 
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# # 
# #  - Nothing in this license impairs or restricts the author's moral rights.
# # 
# #----------------------------------------------------------------------------
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#==============================================================================
# Window_Message
#==============================================================================
class Window_Message < Window_Selectable

  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    x = y = 0
    @cursor_width = 0
    # Indent if choice
    if $game_temp.choice_start == 0
      x = 8
    end
    # If waiting for a message to be displayed
    if $game_temp.message_text != nil
      text = $game_temp.message_text
      # Control text processing
      begin
        last_text = text.clone
        text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
        # calls shop messages with \shop[id]
        text.gsub!(/\\[Ss]hop\[(\S+)\]/) { $calls.Shop($1) }
        # calls Inn messages with \inn[inn name,price]
        text.gsub!(/\\[Ii]nn\[([\S, ]+)\]/) {
        data = $1.split(',')
        $calls.Inn(data[0],data[1]) }
        # calls basic messages with \basic[npc's name,id]
        text.gsub!(/\\[Bb]asic\[([\S, ]+)\]/) {
        data = $1.split(',')
        $calls.Basic_Messages(data[0],data[1].to_i) }
      end until text == last_text
      # calls actors name with \n[id]
      text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
        $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
      end
      # calls random messages with \r[gender]
      text.gsub!(/\\[Rr]\[(\S+)\]/) do
        $calls.random_message($1)
      end
      # calls map name with \m
      text.gsub!(/\\[Mm]/) do
        $calls.Map_Name
      end
      text.gsub!(/\\[Gg]old/) do
        $data_system.words.gold
      end
      # returns \\
      text.gsub!(/\\\\/)                {"\000"}
      # changes text color with \c[id]
      text.gsub!(/\\[Cc]\[([0-9]+)\]/)  {"\001[#{$1}]"}
      # calls gold window with \g
      text.gsub!(/\\[Gg]/)              {"\002"}
      # calls name window with \name[name]
      text.gsub!(/\\[Nn]ame\[(.+?)\]/)  {"\003[#{$1}]"}
      # calls face Graphic with \name[name]
      text.gsub!(/\\[Ff]\[(\S+)\]/)     {"\004[#{$1}]" }
      # calls icon with \i[type,id] type is i for item a for armor w for weapon
      # & s for skills
      text.gsub!(/\\[Ii]\[([\S, ]+)\]/) {"\005[#{$1}]" }
      # Get 1 text character in c (loop until unable to get text)
      while ((c = text.slice!(/./m)) != nil)
        # If \\
        if c == "\000"
          # Return to original text
          c = "\\"
        end
        # If \C[n]
        if c == "\001"
          # Change text color
          text.sub!(/\[([0-9]+)\]/, "")
          color = $1.to_i
          if color >= 0 and color <= 7
            self.contents.font.color = text_color(color)
          end
          # go to next text
          next
        end
        # If \G
        if c == "\002"
          # Make gold window
          if @gold_window == nil
            @gold_window = Window_Gold.new
            @gold_window.x = 560 - @gold_window.width
            if $game_temp.in_battle
              @gold_window.y = 192
            else
              @gold_window.y = self.y >= 128 ? 32 : 384
            end
            @gold_window.opacity = self.opacity
            @gold_window.back_opacity = self.back_opacity
          end
          # go to next text
          next
        end
        if c == "\003"
          # Make name window
          text.sub!(/\[(.+?)\]/, "")
          @name_window = Name_Window.new($1,self.x,self.y)
          nwidth = contents.text_size($1).width
          @name_back = Window_Base.new(self.x,self.y-32,nwidth+8,32)
          @name_back.opacity = self.opacity
          @name_back.back_opacity = self.back_opacity
          next
        end
        if c == "\004"
          # Make face window
           text.sub!(/\[(\S+)\]/, "")
          if @face_window == nil
            @face_window = Face_Window.new($1,self.x-10,self.y-10)
            left = true
          end
          next
        end
        if c == "\005"
          # Make Icons
          text.sub!(/\[([\S, ]+)\]/, "")
          data =  $1.split(',')
          data = $calls.Icon(data[0].to_s,data[1].to_i)
          self.contents.blt(x + (left != nil ? 96 : 0), y, data[0],
          Rect.new(0, 0, 24, 24), opacity)
          x += 24
          w = self.contents.text_size(data[1]).width
          self.contents.draw_text(4 + x + (left != nil ? 96 : 0),
          32 * y, w, 32, data[1])
          x += w
          next
        end
        # If new line text
        if c == "\n"
          # Update cursor width if choice
          if y >= $game_temp.choice_start
            @cursor_width = [@cursor_width, x].max
          end
          # Add 1 to y
          y += 1
          x = 0
          # Indent if choice
          if y >= $game_temp.choice_start
            x = 8
          end
          # go to next text
          next
        end
        # Draw text
        self.contents.draw_text(4 + x + (left != nil ? 96 : 0),
        32 * y, 40, 32, c)
        # Add x to drawn text width
        x += self.contents.text_size(c).width
      end
    end
    # If choice
    if $game_temp.choice_max > 0
      @item_max = $game_temp.choice_max
      self.active = true
      self.index = 0
    end
    # If number input
    if $game_temp.num_input_variable_id > 0
      digits_max = $game_temp.num_input_digits_max
      number = $game_variables[$game_temp.num_input_variable_id]
      @input_number_window = Window_InputNumber.new(digits_max)
      @input_number_window.number = number
      @input_number_window.x = self.x + 8
      @input_number_window.y = self.y + $game_temp.num_input_start * 32
    end
  end

  alias cms_terminate_message terminate_message
  def terminate_message
    cms_terminate_message
    if @name_window != nil
      @name_window.dispose
      @name_window = nil
    end
    if @name_back != nil
      @name_back.dispose
      @name_back = nil
    end
    if @face_window != nil
      @face_window.dispose
      @face_window = nil
    end
  end
 
  alias cms_update update
  def update
    if @contents_showing && Graphics.frame_rate == 80
      if $game_temp.choice_max > 0
        $game_system.se_play($data_system.decision_se)
        $game_temp.choice_proc.call(self.index)
      end
      terminate_message
    end
    cms_update
  end
 
end
#==============================================================================
# Name_Window
#==============================================================================
class Name_Window < Sprite
 
  def initialize(name,x,y)
    super()
    w = (name.length * 32)
    self.bitmap = Bitmap.new(w, 32)
    self.x = x
    self.y = y - 32
    self.z = 500
    @name = name
    refresh
  end
 
  def refresh
    w = bitmap.text_size(@name).width
    self.bitmap.draw_text(4,0,w,32,@name.to_s)
  end
end
#==============================================================================
# Face_Window
#==============================================================================
class Face_Window < Sprite
 
  def initialize(file,x,y,flip = nil)
    super()
    self.bitmap = RPG::Cache.picture(file + '.png')
    self.x = x +20
    self.y = y +20
    self.z = 9999
    if flip
      self.mirror = true
      self.x += (460-self.bitmap.width)
    end
  end
 
  def size
    return self.bitmap.width
  end
 
end


now y i did not post this under scripts because i figure you wont use this as is im got to help you add to it for ur own game for it purposes

so first off if you notice the inn in the script calls
 def Inn(name,gold)
    $game_temp.choice_start += 1
    return "\\Name[Inn Keeper]Would you Like to stay at the \\c[2]#{name}\\c[0]" +
    "\n for \\c[6]#{gold}\\c[0] \\gold."
 end

If your using msg calls you have to add \\ instead of \ for it to read it also using #{variable} will allow you to add that variable to your msg as long as you use the double quotations ("") and if you are using the choice selector in your msg the for every line after the first 1 you need to add 1 to $game_temp.choice_start OK that is a bit about how to use a msg call now how i added it to the msg script
text.gsub!(/\\[Ii]nn\[([\S, ]+)\]/) { 
        data = $1.split(',')
        $calls.Inn(data[0],data[1]) }

the text.gsub!(/\\[Ii]nn\[([\S, ]+)\]/) is used to find either \Inn or \inn then in the brackets we have \S, that tells it i want to get anything but spaces in the bracket the comma tells it i want an array size of 2 the $1.split(',') i used store the $1 array into data then i called my script call from my Calls class $calls.Inn(data[0],data[1])  i store the inns name in data[0] and the price in data[1] by using \inn[name,price] now to add your own just define something in the Calls class then have it call it that way but change the [Ii]nn if its an array if not use can use this to call 1 with one variable or none
text.gsub!(/\\[Mm]/) do
        $calls.Map_Name
      end

as you can see we used text.gsub!(/\\[Mm]/) do $calls.Map_Name this tells it when \M or \M call $calls.Map_Name which i store the maps name in in my Calls class
text.gsub!(/\\[Rr]\[(\S+)\]/) do $calls.random_message($1) stores one variable and calls $calls.random_message($1) same as above

if you need any help addind any thing else or want something added to whats already here post


Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script