Jump to content
Coolie

Help request for Effects Box script

Recommended Posts

Hi, all! I am using a script by Neon Black that allows the user to input notes on items, skills, gear, etc. to give more detailed information about the particular items. However, it seems the script is not functioning the way the author intended.

 

What is happening is that all of the item's note contents are being displayed, rather than just what is between the specified tag that the script should be reading. What this is doing is causing an extreme amount of lag when it is loading every single note box from every single item, even ones that do not have notes in the tag from the script. As the player gains more items, gear and skills, the lag gets increasingly worse, until even scrolling through windows is nearly impossible. Can anyone help me fix this script by making it...

 

- Only load the information inside the tags

- Only load the information the item in question has the tag to begin with?

- Only load the information of the item being viewed (you press a button to bring up the effects box window)

 

##----------------------------------------------------------------------------##
## Effects Box Script v1.0
## Created by Neon Black
##
## For both commercial and non-commercial use as long as credit is given to
## Neon Black and any additional authors.  Licensed under Creative Commons
## CC BY 3.0 - http://creativecommons.org/licenses/by/3.0/.
##----------------------------------------------------------------------------##
                                                                              ##
##----------------------------------------------------------------------------##
##    Revision Info:
## v1.0 - 3.3.2013
##  Wrote and debugged main script
##----------------------------------------------------------------------------##
                                                                              ##
$imported ||= {}                                                              ##
$imported["EFFECTS_BOX"] = 1.0                                                ##
                                                                              ##
##----------------------------------------------------------------------------##
##    Instructions:
## Place this script in the script editor below "Materials" and above "Main".
## This script requires Neon Black's Features and Effects name module.  You can
## obtain it from http://cphouseset.wordpress.com/modules/.  If you do not
## import it, you will get errors.
##
## This script is plug and play.  It allows a pop-up boxes to display on equips,
## items, and skills.  You can choose to have these pop-ups be constant, toggle
## with a button press, or only appear while a key is held down.  These display
## 3 bits of information.  First an added note, second all the stats equipping
## the item will provide, and finally all the effects or features of the item.
## A note can be added using <effect note> and </effect note> and placing your
## note in between those tags, like so:
##
##    <effect note>
##    This will display line 1
##    This will display line 2
##    </effect note>
##
##----------------------------------------------------------------------------##
                                                                              ##
module CP             # Do not touch                                          ##
module EFFECTS_WINDOW #  these lines.                                         ##
##----------------------------------------------------------------------------##
##    Config:
## The config options are below.  You can set these depending on the flavour of
## your game.  Each option is explained in a bit more detail above it.
##
##------
# This is the padding around the edges of the box.  Increasing this number will
# increase the size of the box without increasing the size of it's contents.
EDGES = 6

# This is the font size of the pop up's text.  Adjusting this affects the entire
# box's size.
FONT_SIZE = 20

# Choose to use font shadow or outlines.
SHADOW = false
OUTLINE = false

# If this value is set to false, stats will not be shown on equips.
SHOW_STATS = false

# The key to press to toggle or show the box.
BOX_KEY = :Z

# The show type for the pop-up box.  Any value other than these three will
# prevent the box from being show.
#  0 = Hold button to display the box.
#  1 = Press button to toggle the box.
#  2 = The box is constantly show.
SHOW_TYPE = 0

# If type 2 was selected above, this is the default state of the box.  Set it to
# true to show the box or false to hide the box until the key is pressed.
@show = false
##----------------------------------------------------------------------------##
                                                                              ##
                                                                              ##
##----------------------------------------------------------------------------##
## The following lines are the actual core code of the script.  While you are
## certainly invited to look, modifying it may result in undesirable results.
## Modify at your own risk!
###----------------------------------------------------------------------------


  def self.toggle_effects
    @show = !@show if Input.trigger?(BOX_KEY)
    return @show
  end

end
end

module SceneManager
  class << self
    alias :cp_rshp_run :run unless method_defined?(:cp_rshp_run)
  end

  def self.run
    cp_module_check_features
    cp_rshp_run
  end

  def self.cp_module_check_features
    return if $imported["CP_FEATURES_EFFECTS"]
    a1 = "One or more scripts require Neon Black's Features and Effects module."
    a2 = "This can be obtained at http://cphouseset.wordpress.com/modules/"
    a3 = "Please add this module and try again."
    a4 = "Please contact the creator of the game to resolve this issue."
    if $TEST || $BTEST
      msgbox "#{a1}/n#{a2}/n#{a3}"
      Thread.new{system("start http://cphouseset.wordpress.com/modules/#features")}
    else
      msgbox "#{a1}/n#{a4}"
    end
  end
end

class Window_Selectable < Window_Base
  def item
    return nil
  end

  alias :cp_itembox_update :update
  def update(*args)
    cp_itembox_update(*args)
    show_fet_window
  end

  def show_fet_window
    key = key_show_features_box
    show_feature_box if key && active && open?
    remove_feature_box unless key && active && open?
  end

  def key_show_features_box
    case CP::EFFECTS_WINDOW::SHOW_TYPE
    when 0
      return Input.press?(CP::EFFECTS_WINDOW::BOX_KEY)
    when 1
      return CP::EFFECTS_WINDOW.toggle_effects
    when 2
      return true
    else
      return false
    end
  end

  def show_feature_box  ## Creates the box if "A" key is held
    if item != @last_box_item
      if feature_box_item?
        @feature_box.dispose unless @feature_box.nil?
        rect = item_rect(@index)
        x = rect.x + self.x + padding + 24 - ox
        y = rect.y + line_height + self.y + padding - oy - 2
        @feature_box = Window_FeaturesShow.new(item, x, y, self)
        @last_box_item = item
      else
        remove_feature_box
      end
    end
  end

  def feature_box_item?
    item.is_a?(RPG::EquipItem) || item.is_a?(RPG::UsableItem)
  end

  def remove_feature_box  ## Dispose the box.
    @feature_box.dispose unless @feature_box.nil?
    @feature_box = nil
    @last_box_item = nil
  end
end

class Window_FeaturesShow < Window_Base
  def initialize(item, x, y, parent)
    @parent = parent
    @bx = x; @by = y
    @item = item
    super(0, 0, 500, 500)
    self.z = @parent.z + 500
    self.windowskin = Cache.system(($game_system.windowskin))
    self.opacity = 255
    self.back_opacity = 255
    self.tone = Tone.new
    make_width
    make_height
    make_position
    draw_all_items
  end

  def make_width
    contents.font.size = line_height
    contents.font.outline = CP::EFFECTS_WINDOW::OUTLINE
    contents.font.shadow = CP::EFFECTS_WINDOW::SHADOW
    i = 120
    unless notes.empty?
      i = [i, notes.collect{|n| contents.text_size(n).width}.max + 2].max
    end
    self.width = i + standard_padding * 2
  end

  def make_height
    sw = self.width - standard_padding * 2
    i = standard_padding * 2
    i += notes.size * line_height
    i += seps * line_height / 2
    self.height = i
    self.visible = false if i == standard_padding * 2
    create_contents
    contents.font.size = line_height
    contents.font.outline = false
    contents.font.shadow = false
    change_color(normal_color)
  end

  def make_position
    self.x = @bx + self.width > Graphics.width ? Graphics.width - self.width :
             @bx
    self.y = @by + self.height <= Graphics.height ? @by :
             @by - self.height - @parent.line_height + 4 > 0 ? @by -
             self.height - @parent.line_height + 4 : Graphics.height -
             self.height
  end

  def standard_padding
    CP::EFFECTS_WINDOW::EDGES
  end

  def line_height
    24
  end

  def seps
    i = -1
    i += 1 unless notes.empty?
    return [i, 0].max
  end

  def stats
    return [] unless CP::EFFECTS_WINDOW::SHOW_STATS && @item.is_a?(RPG::EquipItem)
    r = []
    8.times do |i|
      next if @item.params[i] == 0
      r.push("#{Vocab.param(i)}   #{@item.params[i]}")
    end
    return r
  end

  def notes
    @item.effect_desc
  end

  def effects
    if @item.is_a?(RPG::EquipItem)
      @item.features
    elsif @item.is_a?(RPG::UsableItem)
      @item.effects
    end
  end

  def draw_all_items
    contents.clear
    y = 0
    notes.each do |l|
      draw_text(1, y, contents.width, line_height, l)
      y += line_height
    end
  end
end

class RPG::BaseItem
  def effect_desc
    make_effect_desc if @effect_desc.nil?
    return @effect_desc
  end

  def make_effect_desc
    @effect_desc = []
    noted = false
    self.note.split(/[\r\n]+/i).each do |line|
      case line
      when /<effect note>/i
        noted = true
      when /<\/effect note>/i
        break
      else
        @effect_desc.push("#{line}")
      end
    end
  end
end


###--------------------------------------------------------------------------###
#  End of script.                                                              #
###--------------------------------------------------------------------------###

 

Share this post


Link to post
Share on other sites

I'm surprised you didn't put that into a spoiler.

1 hour ago, WCouillard said:

effects box

 

Use my addon

Spoiler

##----------------------------------------------------------------------------##
## Effects Box Script v1.2 - addon
## Created by Neon Black
## Modded by Roninator2
##
## For both commercial and non-commercial use as long as credit is given to
## Neon Black and any additional authors.  Licensed under Creative Commons
## CC BY 3.0 - http://creativecommons.org/licenses/by/3.0/.
##----------------------------------------------------------------------------##

=begin
##    *Addition by Roninator2
##    Whenever you desire to hide an items' effects; or weapons or armor
##		* Now supports Skills
##    use the following:
##    <no effect: X>  where X is the number for the effect
##    *The first effect is 1 the second 2, etc.
##    
##    So if you had 
##    Gain HP + 500   <- effect 1 not 0
##    Recover MP 10%  <- effect 2
##    
##    Using <no effect: 2> would show
##    
##    Gain HP + 500
##    
##    Useful for things like calling common events
##    
##    If an item has no effects and an empty note box, no effect box
##    will be shown.
##
##    If you have one effect and nothing in the note box, then effect box
##    will be shown even if you use <no effect: 1>
##    it will just be empty
##    In those circumstances put the normal <effect note> in the note box
##    with some info, then it won't look as bad.

* also fixed some bugs

=end
module R2
  module Effect_Box
    Regex = /<no[-_ ]effect:[-_ ]\s*(\d+)\s*>/imx
  end
end
  
class Window_Selectable < Window_Base
  def key_show_features_box
    case CP::EFFECTS_WINDOW::SHOW_TYPE
    when 0
      return Input.press?(CP::EFFECTS_WINDOW::BOX_KEY)
    when 1
      @show = !@show if Input.trigger?(CP::EFFECTS_WINDOW::BOX_KEY)
      return @show 
    when 2
      return true
    else
      return false
    end
  end
end

class Window_FeaturesShow < Window_Base

  def notes
    @item.effect_desc
  end

  def effects
    if @item.is_a?(RPG::EquipItem)
      @item.features
    elsif @item.is_a?(RPG::UsableItem)
      @item.effects
    end
  end

  def seps
    i = 0
    i += 1 unless effects.empty?
    i += 1 unless notes.empty?
    i += 1 unless stats.empty?
    return [i, 0].max
  end

  def draw_all_items
    contents.clear
    y = 0
    notes.each do |l|
      draw_text(1, y, contents.width, line_height, l)
      y += line_height
    end
    y += line_height / 2 unless y == 0
    unless stats.empty?
      w = stats.collect{|s| contents.text_size(s).width}.max + 2
      xt = contents.width / w
      xw = contents.width / xt
      xn = 0
      y -= line_height
      stats.each_with_index do |s, index|
        y += line_height if index % xt == 0
        case s
        when /(.*)   (-?)(\d+)/i
          draw_text(xw * (index % xt) + 1, y, xw, line_height, "#{$1.to_s}")
          draw_text(xw * (index % xt) + 1, y, xw, line_height,
                    "#{$2.to_s}#{$3.to_s}  ", 2)
        end
      end
      y += line_height
    end
    y += line_height / 2 unless y == 0
    # Start of my code
    effcount = 1
    effects.each_with_index do |e, effnum|
      item = $data_items[@item.id]
      results = item.note.scan(R2::Effect_Box::Regex)
      results.each do |res|
        effid = res[0].to_i - 1
        if effnum == effid
          effcount = 2
          self.height -= line_height
        end
      end
      item = $data_weapons[@item.id]
      results = item.note.scan(R2::Effect_Box::Regex)
      results.each do |res|
        effid = res[0].to_i - 1
        if effnum == effid
          effcount = 2
          self.height -= line_height
        end
      end
      item = $data_armors[@item.id]
      results = item.note.scan(R2::Effect_Box::Regex)
      results.each do |res|
        effid = res[0].to_i - 1
        if effnum == effid
          effcount = 2
          self.height -= line_height
        end
      end
      item = $data_skills[@item.id]
      results = item.note.scan(R2::Effect_Box::Regex)
      results.each do |res|
        effid = res[0].to_i - 1
        if effnum == effid
          effcount = 2
          self.height -= line_height
        end
      end
      if item.class == RPG::Skill
        @item = item
        data_id = @item.effects[effnum].data_id
        if data_id == 0; self.height -= line_height; next; end
      end
      if effcount == 1
          draw_text(1, y, contents.width, line_height, e.vocab)
          y += line_height
      else
        effcount = 1
      end
    end
  end
end

class RPG::UsableItem < RPG::BaseItem
  
  def effect_desc
    make_effect_desc if @effect_desc.nil?
    return @effect_desc
  end
  
  def make_effect_desc
    @effect_desc = [] 
    results = self.note.scan(/<effect[-_ ]*note>(.*?)<\/effect[-_ ]*note>/imx)
    results.each do |res|
      res[0].strip.split("\r\n").each do |line| 
      @effect_desc.push("#{line}") 
      end
    end
  end

end

class RPG::EquipItem < RPG::BaseItem
  
  def effect_desc
    make_effect_desc if @effect_desc.nil?
    return @effect_desc
  end
  
  def make_effect_desc
    @effect_desc = [] 
    results = self.note.scan(/<effect[-_ ]*note>(.*?)<\/effect[-_ ]*note>/imx)
    results.each do |res|
      res[0].strip.split("\r\n").each do |line| 
      @effect_desc.push("#{line}") 
      end
    end
  end

end

class RPG::Skill < RPG::UsableItem
  
  def effect_desc
    make_effect_desc if @effect_desc.nil?
    return @effect_desc
  end
  
  def make_effect_desc
    @effect_desc = [] 
    results = self.note.scan(/<effect[-_ ]*note>(.*?)<\/effect[-_ ]*note>/imx)
    results.each do |res|
      res[0].strip.split("\r\n").each do |line| 
      @effect_desc.push("#{line}") 
      end
    end
  end

end

###--------------------------------------------------------------------------###
#  End of script.                                                              #
###--------------------------------------------------------------------------###

 

 

Share this post


Link to post
Share on other sites
11 hours ago, roninator2 said:

Use my addon

 

So far, it is returning an error on line 113 citing an undefined method for "each_with_index"

 

Quote

113:in `draw_all_items': undefined method `each_with_index' for nil:NilClass (NoMethodError)

 

EDIT: I believe I fixed that problem, I'll let you know if any issues pop up. Thank you for your help!

Edited by WCouillard
Update

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×