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.

Special Support - A great place to learn to Script

Everyone wants to learn to script, but no one really knows where to start. In my honest opinion, the best place to learn is just by reading the default scripts. I learned to script with the japanese RMXP, so I didn't have English comments at my disposal, so everyone of the new generation has that upperhand. Anyways, what I think the best thing to do to learn to script is read the default scripts, and understand each line.

So what I am offering here is support for anyone trying to learn to script. If there is a line of code you don't understand, ask me here. If there is something you want to know, like where in the script editor does something happen, ask here.
  • Ask about a certain line of code : What it means, does, etc.
  • Ask where the coding is for a certain function
PLEASE DO NOT ASK SOMETHING OTHER THAN EXISTING CODE, OR WHERE IN THE DEFAULT SCRIPTS TO FIND A CERTAIN BLOCK OF CODE. Your post will be deleted.

This is a Trial and Error topic. Hopefully, it can lead to more a use full FAQ for beginners.
 
Code:
class Window_a1 < Window_Base
  def initialize
    super(0, 0, 440, 120)
    self.contents = Bitmap.new(width - 32, height - 32)
  end
  
  def write(text = '')
    self.contents.draw_text(0, 0, 440, 32, text)
  end
end

class Testing
  def initialize
    @window_a1 = Window_a1.new
    @window_a1.write('hello')
  end
end

There's a bit of a fix. A few things from me:

1) The reason hello won't work, because hello looks for a local variable. You will find an undefined error, because hello was never defined. You must use 'hello', and send a string to your write method.

2) RMXP windows (and VX I believe) work in intervals of 4, 8, 16 and 32 when it comes to window size. It its nothing major, but I strongly suggest you keep your windows in intervals of 32, or at least 16. It just appears cleaner from a professional standpoint. That's sizes, and positions.

3) If everytime you create a object using your Window_a1 object class, and are constantly, or even a majority of the time writing the same text, I suggest in your initialize method in your Window_a1 object class, that you add:
write('your_text') so you don't have to call this outside the class.

4) There is no need for your Testing class. Unless you are making a scene, don't do this.

5) def something=(something) is what is called a writer method. It usually writes an instance variable for your class, usually, the same name as your method name, as in:
Code:
class Something
  def something=(something)
    @something = something
  end
end

However, there is a shortcut for a method this simple. When it is just as simple as setting a instance variable like above, we can just use attr_writer :something, as here:
Code:
class Something
  attr_writer :something
end

The only place where you would need to do this, is when you would need to do further processing where the instance variable matters. Like below:
Code:
class Window_Simple < Window_Base
  def initialize
    super(0, 0, 640, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.text = 'This is our first text'
  end
  def text=(text)
    @text = text
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0, width - 32, 32, @text)
  end
end

As you can see, our refresh method write our @text on the window. So when we set our text method, we wouldn't have to do:
Code:
my_window.text = 'Text'
my_window.refresh

We can complete omit the 2nd line, and chances are 99% of the time, that is what we will be doing when we change the @text instance. It's just another shortcut for us lazy scripters.  :thumb:
 
Thanks for your explanation  :smile:


SephirothSpawn":tvqaatvm said:
Code:
class Window_a1 < Window_Base
  def initialize
    super(0, 0, 440, 120)
    self.contents = Bitmap.new(width - 32, height - 32)
  end
  
  def write(text = '')
    self.contents.draw_text(0, 0, 440, 32, text)
  end
end

class Testing
  def initialize
    @window_a1 = Window_a1.new
    @window_a1.write('hello')
  end
end

There's a bit of a fix. A few things from me:

1) The reason hello won't work, because hello looks for a local variable. You will find an undefined error, because hello was never defined. You must use 'hello', and send a string to your write method.

2) RMXP windows (and VX I believe) work in intervals of 4, 8, 16 and 32 when it comes to window size. It its nothing major, but I strongly suggest you keep your windows in intervals of 32, or at least 16. It just appears cleaner from a professional standpoint. That's sizes, and positions.

3) If everytime you create a object using your Window_a1 object class, and are constantly, or even a majority of the time writing the same text, I suggest in your initialize method in your Window_a1 object class, that you add:
write('your_text') so you don't have to call this outside the class.

4) There is no need for your Testing class. Unless you are making a scene, don't do this.

The code.. It was just a test. I wanted to know if I type
Code:
@window_a1 = Window_a1.new
I can do the methods of "Window_a1" class by typing "@window_a1.methodname" in the different class.

Thanks for the tips anyway, especially number 2.  :thumb:
 
This is a really useful thread, I was just wondering and I hope this isn't a bad question, I am just wondering don't script for me just please walk me through how to do this, how to add a custom stat. What I mean by custom stat is a parameter like strength and dexterity, "vitality" that adds to your HP and "energy" that adds to SP. I know this would require rescripting many things but with a good scripters help I may be able to do it. I need to know how to change displaying the stats (to add new stat display to places like in Scene_Status), how to add this stat in the first place and major support on how to change a Blizzard's Stat Distribution System Script:

Code:
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Stat Distribution System by Blizzard
# Version: 1.33b
# Type: Actor Attribute Modifier
# Date: 25.3.2007
# Date v1.1b: 6.4.2007
# Date v1.2b: 22.8.2007
# Date v1.3b: 12.9.2007
# Date v1.33b: 5.11.2007
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#   
#  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.
# #  
# #----------------------------------------------------------------------------
# 
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# 
# Compatibility:
# 
#   99% compatible with SDK v1.x. 80% compatible with SDK 2.x. WILL corrupt
#   your old savegames. Might cause problems with custom leveling up systems.
#   99% compatibility with everything else.
# 
# 
# Features:
# 
#   - distribute points between different stats
#   - extra scene for point distribution with confirmation window at the end
#   - calls the "caller scene" automatically when finished
#   - add points by easily pressing RIGHT/LEFT
#   - hold Q to add 10 points at once
#   - hold W to add 100 points at once
#   - a Stat Distribution System that actually works like it should...
# 
# new in v1.1b:
#   - added option to call the Points Scene after a fight with level ups
#   - customizable icon position and opacity
# 
# new in v1.2b:
#   - improved coding and made code shorter
#   - rewritten conditions using classic syntax to avoid RGSS conditioning bug
# 
# new in v1.3b:
#   - improved coding
#   - fixed bug with AUTOMATIC_CALL after battle
#   - new AUTOMATIC_MAP_CALL works on the map as well (that means it's fully
#     compatible with Blizz-ABS)
# 
# new in v1.33b:
#   - improved coding
#   - improved compatibility
#   - fixed a little glitch
# 
# 
# Configuration:
# 
#   Set up the configuration below.
# 
#   STARTING_POINTS    - how many points should the actor have initially at
#                        level 1
#   POINTS_PER_LEVEL   - how many points should the actor gain per level
#   DISPLAY_ICON       - displays an icon on the map if ANY character in the
#                        party has any points to distribute
#   ICON_DATA          - some custom options for your icon: [X, Y, OPACITY]
#                        the default values are [612, 452, 192]
#   OWN_ICON           - use an own icon for display (the icon has to be in the
#                        Icons folder and must be named "point_notify")
#   EVASION            - the name that should be displayed for "Evasion"
#   STR_LIMIT          - max possible STR
#   DEX_LIMIT          - max possible DEX
#   AGI_LIMIT          - max possible AGI
#   INT_LIMIT          - max possible INT
#   WINDOW_MODE        - set to true to have the windows at the left, set to
#                        false to have them to at the right
#   AUTOMATIC_CALL     - set to true to have the scene called automatically
#                        after battles if at least one character got leveled up
#   AUTOMATIC_MAP_CALL - set to true to have the scene called automatically on
#                        the map if at least one character got leveled up
#                        (this works for Blizz-ABS as well), also note that
#                        this will cause the scene to called over and over as
#                        long as not all points were distributed
# 
# 
#   You can always add stat points yourself by using following syntax:
# 
#     $game_party.actors[X].add_stat_points(Z)
#     $game_actors[Y].add_stat_points(Z)
# 
#   Or you can remove them (how much sense it does is up to you...):
# 
#     $game_party.actors[X].remove_stat_points(Z)
#     $game_actors[Y].remove_stat_points(Z)
# 
#   X - position of actor in the party (STARTS FROM ZERO!)
#   Y - ID of actor in the database
#   Z - value
# 
#   You can call the Scene by using a "Call script" event command. Type into
#   the editor window this text:
# 
#     $scene = Scene_Points.new
# 
# 
# Side Note:
# 
#   Decreasing the level of an actor won't remove his gained stat points. You
#   MUST do it manually.
# 
# 
# If you find any bugs, please report them here:
# http://forum.chaos-project.com
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

module BlizzCFG

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# START Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  STARTING_POINTS = 0
  POINTS_PER_LEVEL = 5
  DISPLAY_ICON = false
  ICON_DATA = [612, 452, 192]
  OWN_ICON = false
  EVASION = 'Evasion'
  STR_LIMIT = 999
  DEX_LIMIT = 999
  AGI_LIMIT = 999
  INT_LIMIT = 999
  WINDOW_MODE = true
  AUTOMATIC_CALL = false
  AUTOMATIC_MAP_CALL = true
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# END Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  ATTR_LIMITS = [STR_LIMIT, DEX_LIMIT, AGI_LIMIT, INT_LIMIT]
  # ensures compatibility
  $stat_system = 1.33
  
end

#==============================================================================
# Array
#==============================================================================

class Array
  
  def sum
    result = 0
    self.each {|i| result += i if i.is_a?(Numeric)}
    return result
  end
  
end
  
#==============================================================================
# Game_Actor
#==============================================================================

class Game_Actor < Game_Battler
  
  attr_reader :points
  
  alias setup_sds_later setup
  def setup(actor_id)
    @points = BlizzCFG::STARTING_POINTS
    setup_sds_later(actor_id)
  end
  
  alias exp_sds_later exp=
  def exp=(exp)
    old_level = @level
    exp_sds_later(exp)
    add_stat_points((@level - old_level) * BlizzCFG::POINTS_PER_LEVEL)
  end
  
  def add_stat_points(val)
    @points += val if val > 0
  end
  
  def remove_stat_points(val)
    @points = [@points-val, 0].max
  end
  
end

#==============================================================================
# Window_Base
#==============================================================================

class Window_Base < Window
  
  def draw_actor_battler(actor, x, y)
    bitmap = RPG::Cache.battler(actor.battler_name, actor.battler_hue)
    cw, ch = bitmap.width, bitmap.height
    src_rect = Rect.new(0, 0, cw, ch)
    self.contents.blt(x - cw/2, y - ch/2, bitmap, src_rect)
  end
  
  alias draw_actor_parameter_sds_later draw_actor_parameter
  def draw_actor_parameter(actor, x, y, type)
    if type == 7
      self.contents.font.color = system_color
      self.contents.draw_text(x, y, 120, 32, BlizzCFG::EVASION)
      self.contents.font.color = normal_color
      self.contents.draw_text(x + 120, y, 36, 32, actor.eva.to_s, 2)
    else
      draw_actor_parameter_sds_later(actor, x, y, type)
    end
  end
  
end

#==============================================================================
# Window_Distribution_Status
#==============================================================================

class Window_Distribution_Status < Window_Base
  
  attr_accessor :actor
  
  def initialize(actor)
    super(BlizzCFG::WINDOW_MODE ? 160 : 0, 0, 480, 480)
    @actor = actor
    self.contents = Bitmap.new(width - 32, height - 32)
    if $fontface != nil
      self.contents.font.name = $fontface
      self.contents.font.size = $fontsize
    elsif $defaultfonttype != nil
      self.contents.font.name = $defaultfonttype
      self.contents.font.size = $defaultfontsize
    end
    refresh
  end
  
  def refresh
    self.contents.clear
    unless @actor == nil
      draw_actor_battler(@actor, 280, 120)
      draw_actor_name(@actor, 4, 0)
      draw_actor_class(@actor, 4, 32)
      draw_actor_level(@actor, 4, 64)
      draw_actor_state(@actor, 4, 96)
      self.contents.font.color = system_color
      self.contents.draw_text(4, 128, 80, 32, 'EXP')
      self.contents.draw_text(4, 160, 80, 32, 'next')
      self.contents.font.color = normal_color
      self.contents.draw_text(4, 128, 156, 32, @actor.exp_s, 2)
      self.contents.draw_text(4, 160, 156, 32, @actor.next_rest_exp_s, 2)
      draw_actor_hp(@actor, 4, 224, 172)
      draw_actor_sp(@actor, 4, 256, 172)
      draw_actor_parameter(@actor, 4, 320, 0)
      draw_actor_parameter(@actor, 4, 352, 1)
      draw_actor_parameter(@actor, 4, 384, 2)
      draw_actor_parameter(@actor, 4, 416, 7)
      self.contents.font.color = system_color
      self.contents.draw_text(240, 240, 96, 32, 'Main Equipment')
      draw_item_name($data_weapons[@actor.weapon_id], 240, 288)
      draw_item_name($data_armors[@actor.armor1_id], 240, 320)
      draw_item_name($data_armors[@actor.armor2_id], 240, 352)
      draw_item_name($data_armors[@actor.armor3_id], 240, 384)
      draw_item_name($data_armors[@actor.armor4_id], 240, 416)
    end
  end
  
end
  
#==============================================================================
# Window_Distribution
#==============================================================================

class Window_Distribution < Window_Selectable
  
  attr_accessor :actor
  attr_reader   :points
  
  def initialize(actor)
    super(BlizzCFG::WINDOW_MODE ? 0 : 480, 160, 160, 320)
    self.contents = Bitmap.new(width - 32, height - 32)
    if $fontface != nil
      self.contents.font.name = $fontface
      self.contents.font.size = $fontsize
    elsif $defaultfonttype != nil
      self.contents.font.name = $defaultfonttype
      self.contents.font.size = $defaultfontsize
    end
    self.active, self.index, = false, 0
    @item_max, @actor, @att, @points = 4, actor, [0, 0, 0, 0], 0
    refresh
  end
  
  def set_new_attributes
    @actor.str += @att[0]
    @actor.dex += @att[1]
    @actor.agi += @att[2]
    @actor.int += @att[3]
    @actor.remove_stat_points(@points)
  end
  
  def actor=(actor)
    @actor = actor
    @att[0] = @att[1] = @att[2] = @att[3] = @points = 0
  end
  
  def refresh
    self.contents.clear
    unless @actor == nil
      self.contents.font.color = system_color
      self.contents.draw_text(52, 0, 72, 32, 'AP left', 2)
      self.contents.draw_text(4, 32, 120, 32, $data_system.words.str)
      self.contents.draw_text(4, 96, 120, 32, $data_system.words.dex)
      self.contents.draw_text(4, 160, 120, 32, $data_system.words.agi)
      self.contents.draw_text(4, 224, 120, 32, $data_system.words.int)
      self.contents.font.color = normal_color
      self.contents.draw_text(4, 0, 48, 32, "#{actor.points-@points}", 2)
      self.contents.draw_text(36, 64, 56, 32, "#{@actor.str+@att[0]}", 2)
      self.contents.draw_text(36, 128, 56, 32, "#{@actor.dex+@att[1]}", 2)
      self.contents.draw_text(36, 192, 56, 32, "#{@actor.agi+@att[2]}", 2)
      self.contents.draw_text(36, 256, 56, 32, "#{@actor.int+@att[3]}", 2)
      self.contents.font.size += 8
      self.contents.font.bold = true
      (0...4).each {|i|
          self.contents.draw_text(0, (i + 1) * 64 - 8, 32, 42, '«', 2)
          self.contents.draw_text(96, (i + 1) * 64 - 8, 32, 42, '»')}
      self.contents.font.bold = false
      self.contents.font.size -= 8
    end
  end
  
  def add_points(num)
    attr = [@actor.str, @actor.dex, @actor.agi, @actor.int]
    if @points < @actor.points &&
        attr[index]+@att[index] < BlizzCFG::ATTR_LIMITS[index]
      @points = [@points + num, @actor.points].min
      @att[index] = [@att[index]+num, @points+@att[index]-@att.sum].min
      return true
    end
    return false
  end
  
  def remove_points(num)
    if @points > 0 && @att[index] > 0
      @points = [@points - num, 0].max
      @att[index] = [@att[index] - num, 0].max
      return true
    end
    return false
  end
  
  def update
    super
    return unless self.active
    if Input.press?(Input::R)
      if Input.repeat?(Input::RIGHT)
        if add_points(100)
          $game_system.se_play($data_system.cursor_se)
          refresh
        else
          $game_system.se_play($data_system.buzzer_se)
        end
      elsif Input.repeat?(Input::LEFT)
        if remove_points(100)
          $game_system.se_play($data_system.cursor_se)
          refresh
        else
          $game_system.se_play($data_system.buzzer_se)
        end
      end
    elsif Input.press?(Input::L)
      if Input.repeat?(Input::RIGHT)
        if add_points(10)
          $game_system.se_play($data_system.cursor_se)
          refresh
        else
          $game_system.se_play($data_system.buzzer_se)
        end
      elsif Input.repeat?(Input::LEFT)
        if remove_points(10)
          $game_system.se_play($data_system.cursor_se)
          refresh
        else
          $game_system.se_play($data_system.buzzer_se)
        end
      end
    elsif Input.repeat?(Input::RIGHT)
      if add_points(1)
        $game_system.se_play($data_system.cursor_se)
        refresh
      else
        $game_system.se_play($data_system.buzzer_se)
      end
    elsif Input.repeat?(Input::LEFT)
      if remove_points(1)
        $game_system.se_play($data_system.cursor_se)
        refresh
      else
        $game_system.se_play($data_system.buzzer_se)
      end
    end
  end
  
  def update_cursor_rect
    if @index < 0 || !self.active
      self.cursor_rect.empty
    else
      self.cursor_rect.set(32, (@index+1)*64, 64, 32)
    end
  end
  
end
  
#==============================================================================
# Window_Sure
#==============================================================================

class Window_Sure < Window_Command
  
  attr_accessor :actor
  
  def initialize(width, commands)
    commands.push('')
    super
    @item_max, self.index = commands.size - 1, 0
    self.x, self.y, self.z = 320-self.width/2, 240-self.height/2, 10000
    refresh
  end
  
  def refresh
    super
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, self.contents.width - 8, 32, 'Are you sure?', 1)
  end
  
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(4, 32 * (index+1), self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index], 1)
  end
  
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
    else
      self.cursor_rect.set(32, (@index+1)*32, self.contents.width - 64, 32)
    end
  end
  
end
  
#==============================================================================
# Scene_Points
#==============================================================================

class Scene_Points
  
  def initialize
    @actor, @scene = $game_party.actors[0], $scene.class
  end
  
  def main
    commands = ['Distribute', 'Next', 'Previous', 'Finish']
    @command_window = Window_Command.new(160, commands)
    @command_window.x = (BlizzCFG::WINDOW_MODE ? 0 : 480)
    @status_window = Window_Distribution_Status.new(@actor)
    @distro_window = Window_Distribution.new(@actor)
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      break if $scene != self
    end
    Graphics.freeze
    [@command_window, @status_window, @distro_window].each {|win| win.dispose}
  end
  
  def make_sure_window
    commands = ['Cancel', 'Accept changes', 'Discard changes']
    @sure_window = Window_Sure.new(256, commands)
  end
  
  def update
    if @command_window.active
      @command_window.update
      update_main_command
    elsif @sure_window != nil
      @sure_window.update
      update_sure
    elsif @distro_window.active
      @distro_window.update
      if Input.trigger?(Input::B)
        $game_system.se_play($data_system.cancel_se)
        @command_window.active, @distro_window.active = true, false
      end
    end
  end
  
  def update_main_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      if @distro_window.points != 0
        @command_window.index, @command_window.active = 3, false
        make_sure_window
      else
        $scene = @scene.new
      end
    elsif Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      case @command_window.index
      when 0 then @command_window.active, @distro_window.active = false, true
      when 1
        if @distro_window.points != 0
          @command_window.active = false
          make_sure_window
        else
          i = (@actor.index+1) % $game_party.actors.size
          @actor = @status_window.actor = @distro_window.actor = $game_party.actors[i]
          [@status_window, @distro_window].each {|win| win.refresh}
          @distro_window.index = 0
        end
      when 2
        if @distro_window.points != 0
          @command_window.active = false
          make_sure_window
        else
          i = (@actor.index+$game_party.actors.size-1) % $game_party.actors.size
          @actor = @status_window.actor = @distro_window.actor = $game_party.actors[i]
          [@status_window, @distro_window].each {|win| win.refresh}
          @distro_window.index = 0
        end
      when 3
        if @distro_window.points != 0
          @command_window.active = false
          make_sure_window
        else
          $scene = @scene.new
        end
      end
    end
  end
  
  def update_sure
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @sure_window.dispose
      @sure_window, @command_window.active = nil, true
    elsif Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      case @command_window.index
      when 1
        if @sure_window.index > 0
          @distro_window.set_new_attributes if @sure_window.index == 1
          i = (@actor.index+1) % $game_party.actors.size
          @actor = @status_window.actor = @distro_window.actor = $game_party.actors[i]
          [@status_window, @distro_window].each {|win| win.refresh}
        end
        @sure_window.dispose
        @sure_window, @command_window.active = nil, true
      when 2
        if @sure_window.index > 0
          @distro_window.set_new_attributes if @sure_window.index == 1
          i = (@actor.index+$game_party.actors.size-1) % $game_party.actors.size
          @actor = @status_window.actor = @distro_window.actor = $game_party.actors[i]
          [@status_window, @distro_window].each {|win| win.refresh}
        end
        @sure_window.dispose
        @sure_window, @command_window.active = nil, true
      when 3
        if @sure_window.index > 0
          @distro_window.set_new_attributes if @sure_window.index == 1
          $scene = @scene.new
        end
        @sure_window.dispose
        @sure_window, @command_window.active = nil, true
      end
    end
  end
  
end

#==============================================================================
# Scene_Battle
#==============================================================================

class Scene_Battle
  
  alias main_sds_later main
  def main
    main_sds_later
    if BlizzCFG::AUTOMATIC_CALL &&
        $game_party.actors.any? {|actor| actor.points > 0}
      $scene = Scene_Points.new
    end
  end
  
end

#==============================================================================
# Scene_Map
#==============================================================================

class Scene_Map
  
  alias main_sds_later main
  def main
    main_sds_later
    @notify.dispose if @notify != nil
  end
  
  alias upd_sds_later update
  def update
    check_icon if BlizzCFG::DISPLAY_ICON
    upd_sds_later
    if BlizzCFG::AUTOMATIC_MAP_CALL &&
        $game_party.actors.any? {|actor| actor.points > 0}
      $scene = Scene_Points.new
    end
  end
  
  def check_icon
    if $game_party.actors.any? {|actor| actor.points > 0}
      if @notify == nil
        @notify = RPG::Sprite.new
        if BlizzCFG::OWN_ICON
          @notify.bitmap = RPG::Cache.icon('point_notify')
        else
          @notify.bitmap = Bitmap.new(24, 24)
          @notify.bitmap.fill_rect(0, 0, 24, 24, Color.new(255, 255, 255))
          @notify.bitmap.fill_rect(22, 1, 2, 23, Color.new(0, 0, 0))
          @notify.bitmap.fill_rect(1, 22, 23, 2, Color.new(0, 0, 0))
          @notify.bitmap.set_pixel(23, 0, Color.new(0, 0, 0))
          @notify.bitmap.set_pixel(0, 23, Color.new(0, 0, 0))
          @notify.bitmap.fill_rect(2, 2, 20, 20, Color.new(0, 0, 224))
          @notify.bitmap.fill_rect(4, 10, 16, 4, Color.new(255, 255, 255))
          @notify.bitmap.fill_rect(10, 4, 4, 16, Color.new(255, 255, 255))
          @notify.opacity = BlizzCFG::ICON_DATA[2]
        end
        @notify.x, @notify.y = BlizzCFG::ICON_DATA[0, 2]
        @notify.z = 5000
        @notify.blink_on
      end
      @notify.update
    elsif @notify != nil
      @notify.dispose
      @notify = nil
    end
  end
  
end

Any scripters that can help me please jump right in, but explain with thorough steps so a beginner scripter can grab the concepts. I will give special credits in the games that use this if you are able to help (not manditory but if you want special credit you can have it).

Also I won't give up I will keep trying my best until I set it up I won't quit when I get stuck.
 
There is no way to test if one event runs into another by default, but I made this script so we could check:

Code:
#==============================================================================
# ** Event Collision Detection
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 2.01
# 2007-07-23
# SDK : Version 2.0+, Part I
#------------------------------------------------------------------------------
# * Version History :
#
#   Version 1 ---------------------------------------------------- (2006-10-16)
#   Version 2 ---------------------------------------------------- (2007-01-24)
#    - Update : Re-scripted Much of the System & Update to SDK 2.0
#    Version 2.01 ------------------------------------------------ (2007-07-23)
#     - Update : Minor Updates
#------------------------------------------------------------------------------
# * Description :
#
#   This script was designed to detect when events colide with each other.
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place The Script Below the SDK and Above Main.
#   To Test for event collisions, refer to Syntax.
#------------------------------------------------------------------------------
# * Syntax :
#
#   Testing Event For Collision
#    - $game_map.event_collisions(event_id [, uniq = true])
#
#    event_id        = Id For Event or 0 for the Player
#    uniq (Optional) = Returns Unique array (No repeated ids)
#
#   Testing Event For Collision (And Clear)
#    - $game_map.event_collisions!(event_id [, uniq = true])
#
#    event_id        = Id For Event or 0 for the Player
#    uniq (Optional) = Returns Unique array (No repeated ids)
#
#   Clear Collisions
#    - $game_map.clear_event_collisions(event_id = -1)
#
#    event_id        = ID for event or -1 for all events
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Event Collision Detection', 'SephirothSpawn', 2.01, '2007-07-23')
SDK.check_requirements(2.0)

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Event Collision Detection')

#==============================================================================
# ** Game_Map
#==============================================================================

class Game_Map
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :event_collisions
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_evtcolo_gmmap_setup, :setup
  #--------------------------------------------------------------------------
  # * Setup
  #--------------------------------------------------------------------------
  def setup(map_id)
    # Original Map Setup
    seph_evtcolo_gmmap_setup(map_id)
    # Sets Up Event Collision Detection
    @event_collisions = {}
  end
  #--------------------------------------------------------------------------
  # * Save Event Collision
  #--------------------------------------------------------------------------
  def save_collision(id1, id2)
    # Saves Array For Event
    if (not @event_collisions.has_key?(id1)) || @event_collisions[id1].nil?
      @event_collisions[id1] = []
    end
    # Saves ID
    @event_collisions[id1] << id2
  end
  #--------------------------------------------------------------------------
  # * Checks Event Collisions for Event
  #--------------------------------------------------------------------------
  def event_collisions(event_id, uniq = true)
    # If Event Has Encounter Another Event
    if @event_collisions.has_key?(event_id)
      # Return Collisions
      return uniq ? @event_collisions[event_id].uniq.sort : 
                    @event_collisions[event_id].sort
    end
    # Return No Collisions
    return []
  end
  #--------------------------------------------------------------------------
  # * Checks Event Collisions for Event
  #--------------------------------------------------------------------------
  def event_collisions!(event_id, uniq = true)
    # Gets Event Collisions
    c = event_collisions(event_id, uniq)
    # Clear Event Collisions
    @event_collisions[event_id].clear if @event_collisions.has_key?(event_id)
    # Return Collisions
    return c
  end
  #--------------------------------------------------------------------------
  # * Clear Event Collisions
  #--------------------------------------------------------------------------
  def clear_event_collisions(id = -1)
    @event_collisions = {} if id == -1
    @event_collisions[id].clear if id != -1 && @event_collisions.has_key?(id)
  end
end

#==============================================================================
# ** Game_Character
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  if self.method_defined?(:check_event_trigger_touch)
    unless self.method_defined?(:seph_evtcol_gmchr_cett)
      alias_method :seph_evtcol_gmchr_cett, :check_event_trigger_touch
    end
  end
  #--------------------------------------------------------------------------
  # * Touch Event Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    # Pass Through All Events
    for event in $game_map.events.values
      # Skip If Event is Self
      next if event == self
      # If Position is Same
      if event.x == x && event.y == y
        # Save Collision
        id = self.is_a?(Game_Player) ? 0 : self.id
        $game_map.save_collision(id, event.id)
        break
      end
    end
    # Original Method call (if exist)
#    if self.method_defined?(:seph_evtcol_gmchr_cett)
#      seph_evtcol_gmchr_cett(x, y)
#    end
  end
end

#==============================================================================
# ** Game_Event
#==============================================================================

class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_evtcolo_gmevt_cett, :check_event_trigger_touch
  #--------------------------------------------------------------------------
  # * Touch Event Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    super(x, y)
    # Original Touch Event Test
    seph_evtcolo_gmevt_cett(x, y)
  end
end

#==============================================================================
# ** Game_Player
#==============================================================================

class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_evtcolo_gmplyr_cett, :check_event_trigger_touch
  #--------------------------------------------------------------------------
  # * Touch Event Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    super(x, y)
    # Original Touch Event Test
    seph_evtcolo_gmplyr_cett(x, y)
  end
end
  
#------------------------------------------------------------------------------
# * End SDK Enable Test
#------------------------------------------------------------------------------
end
 
Okay, I've got a couple questions myself... three in fact, wait no, four, so bear with me.

Okay, I know Ruby/RGSS is capable of file read and write, and file creation, but is there a way to make it successfully write-to or create a file within an encrypted project? I only ask because I have an unfinished Serial Activation script, and I need it to be able to create/write to the file Activation.rxdata inside the encryption, so nobody can edit the .rxdata file.

When it comes to Party and Troop, how do I detect if "Aluxes" is in party position 0..3, or who "Aluxes" is targetting in battle, or if "[Position 0] actor has [this state]", or if "[Position 3] actor is using [Command] on [Target]?" Sorry, eventing is too vauge as it only determines if "Aluxes" has [state], it never tells you if [position 0] has [state] or is [performing action].

Say I want to index and categorize my items/skills/other in the menu with Element Tagging, so they group together what is tagged with what, or are 'hidden' from the menu when they have a certain tag, how do I write a method like that?

I know the basics of calling the Input.press?(Input::C) command, but is there other ways to detect if the player is repeatedly pressing and/or holding the button, or if its a one-time press?

Sorry about all these questions, but they're all very basic things I've been wanting to know about.
 
Okay, I know Ruby/RGSS is capable of file read and write, and file creation, but is there a way to make it successfully write-to or create a file within an encrypted project? I only ask because I have an unfinished Serial Activation script, and I need it to be able to create/write to the file Activation.rxdata inside the encryption, so nobody can edit the .rxdata file.
No. Encrypted data access is made directly by the classes whitin the RGSS library. There's no available methods that allow you to do that. :(

When it comes to Party and Troop, how do I detect if "Aluxes" is in party position 0..3, or who "Aluxes" is targetting in battle, or if "(Position 0) actor has (this state)", or if "(Position 3) actor is using (Command) on (Target)?" Sorry, eventing is too vauge as it only determines if "Aluxes" has (state), it never tells you if (position 0) has (state) or is (performing action).
Dude, that's a lot of questions. Let's make it one step after other...
To check if a character is on your party, we must check the $game_party.actors array. It's a list of the characters in your party. But it's filled with Game_Actor objects, so we first need to find the proper Game_Actor object of "Aluxes".
Code:
actor = $game_actors[1]
It'll set the Game_Actor of ID #1 into the "actor" variable. I presume "Aluxes" is your ID #1 character, so you should change 1 to the character id.
Then, we should verify if Aluxes is on your party. Now that we have the Game_Actor object, it's preety easy:
Code:
if $game_party.actors.include?(actor)
For the rest, let's check the Game_Actor script first, so open the Script Editor.
Look into it's functions. They're mostly about equipment, status and skill... Not really useful here.
We can see its superclass is "Game_Battler". So, let's check the Game_Battler. There's three parts, but let's go first into the number one.
Nothing very useful here... except, of course, for the "def current_action". What's that? It returns to you the current action this character is doing in battle. Looks like @current_action is a Game_BattleAction. Let's check it out.
Nothing useful at the functions, but wait a sec! There's a "target_index" attribute there. This will do to check who Aluxes is targetting:
Code:
actor = $game_actors[1]
target = actor.current_action.target_index
Great, but it only get us it's index... Well, we know the opponents are known as "troop". There is a Game_Troop script, so this may what we need.
There's a "def enemies" there. It returns all the enemies, just like "actors", from "$game_party.actors". Hmm... looks we can use Game_Troop with $game_troop, as it's being said on the script description!
Code:
actor = $game_actors[1]
target_id = actor.current_action.target_index
target = $game_troop.enemies[target_id]
Now we got the target. What next, check state?Well, let's go back to the Game_Battler.
Moving to the Game_Battler 2 reveals... Whoa, first strike. "def state?(state_id)" are exactly what I was looking for.
Code:
actor = $game_actors[1]
if actor.state?(2)
Now, checking position 0 actor? Easy:
Code:
actor = $game_party.actors[0]
Well, the rest is up to you. As you can see, it much likely you need to analyze the scripts and find what is useful for you. :P

Say I want to index and categorize my items/skills/other in the menu with Element Tagging, so they group together what is tagged with what, or are 'hidden' from the menu when they have a certain tag, how do I write a method like that?
Hm, that's quite more specific. You should look at the forum, there's plenty of scripts like that available for you.

I know the basics of calling the Input.press?(Input::C) command, but is there other ways to detect if the player is repeatedly pressing and/or holding the button, or if its a one-time press?
You should check the help file, there's tons of information there. Well, the help file says...
Input.press?(num) -> Returns if a button is being held
Input.trigger?(num) -> Returns if a button has been triggered (one-time press)
Input.repeat?(num) ->  Returns if a button is being held in a specific interval of repeat (defined by Control Panel configurations)
Input.dir4 -> Returns the pressed direction (only 4 directions)
Input.dir8 -> Returns the pressed direction (all the 8 directions)

The direction functions are clever. They return a number corresponding to the direction you're pressing. Checking the "num keypad", 4 is left, 8 is up, 6 is right and 2 is down. 1, 3, 7 and 9 are diagonals. When no direction is being pressed, it'll return 0.


SEE YA!!!!!
 
Ok...

Is there any way to edit DEFAULT keys input?

I must change default C = enter, space, B - escape, X  and others to differend keys...
pls help,  F1 don't helped, couse this change anly on my computer ;[
 
As far as I know, no (At least not with standard RGSS library).

OR. Use the Keyboard module (made by... Uh, SephSpawn I think) you can set any keys to be used in your game. With it, you can also make some sort of options so the player can set up the keys he want to use. ;)
A really useful Module. ^^

SEE YA!!!!!
 
Question 1

How do determine the max priority value of the tiles the player is standing on/under? I've been searching through the default scripts, but I can't really find much on priority.

Reason I'm asking is because, in an old script I'm revising, it needs to call a locator sprite when your character is hidden behind a priority 1+ tile.

Question 2

In Scene_Save, right around line 69, this is there... I think its also in Scene_Load and Game_System too, the 'magic_number'.

Code:
# Save magic number
# (A random value will be written each time saving with editor)
$game_system.magic_number = $data_system.magic_number

What the heck is magic_number exactly and what's the purpose of its function?
 
Okay. I am new to scripting with RGSS2, so I don't get some stuff.

Line 21:  attr_accessor :white_flash              # white flash flag
Line 22:  attr_accessor :blink                    # blink flag

I also cannot find where the menu is. Anyone know?
 
Cmitch1120":20pjxn1j said:
Okay. I am new to scripting with RGSS2, so I don't get some stuff.

Line 21:  attr_accessor :white_flash              # white flash flag
Line 22:   attr_accessor :blink                    # blink flag

Its a 'flag' that is set, that tells you that the player is flashing white or blinking

white_flash : when you don't select a 'Casting' animation for an actor, s/he just flashes white when performing an action. white_flash is used by default with normal attacks.

blink : I believe this is set when you're in the Input Command phase of battle, the actor who's command you're inputting is usually blinking, thats what this flag apparently does.

I also cannot find where the menu is. Anyone know?

The menu is made up of several components, actually....

Window_Gold
Window_Playtime
Window_Steps

Window_MenuStatus
Window_Item
Window_Skill
Window_EquipLeft
Window_EquipRight
Window_EquipItem
Window_SkillStatus
Window_Save

All those make up the "Windows" of the menu.

Scene_Menu #<--Controls everything having to do with the menu.

Edit: I just realised you're talking about VX, but this is all from XP. Although two different platforms, they are still very similar so VX probably isn't much different from what I just told you.
 
@Kain Nobel:
I'm afraid I'm not able to answer that right now. I'll need to check the scripts this weekend to tell you precisely, cuz' I'm now at school and I'm not able to install RMXP here. :(
Second answer, thought, is simple: the magic number is some sort of "random number" that defines your game version. It is generated by RPG Maker XP when you save your project, and it should update some save data whenever the magic number from the save file is different from the current magic number. So, if you saved in map 002, and changed some events and stuff, the scripts should reload it so the save file will be "updated" (not the actual correct term, but will do).

@Cmitch1120:
Indeed, Kain is correct. For the menu, you must be searching for Scene_Menu. On RMVX it's found right after Scene_Map script (as in RMXP), under the Scene category (I think it's the last of them, before the Main script). Preety the same as RMXP, except of course that it is now parent of Scene_Base, and as such it overloads its methods to make things more easy to be found.

SEE YA!!!!!
 

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