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.

Serious problem with script

I just purchased the full version today, but I've already encountered a serious problem. The scripts I am using are now very laggy. Whenever they are refreshed, there are short pauses in the game. This didn't happen before. Does anyone know why this happens and how to fix this?
 
HUD Script, I customized.

Code:
class Scene_Map
  
  alias raz_hud_main main
  alias raz_hud_update update
  
  def main
    @size = $game_party.actors.size
    raz_hud_main
    @hud_window.dispose
    @hud_dummy[0].dispose
    @hud_dummy[1].dispose
    @hud_dummy[2].dispose
    @hud_dummy[3].dispose
  end
  
  def update
  if @size != $game_party.actors.size
     @hud_window.refresh
      show_window
    end
  if @hud == true
      else
    main_window
  end
  
    @hud_window.update
    raz_hud_update
  end
  
  def show_window
    @size = $game_party.actors.size
    if $game_party.actors[0] == nil
      @hud_dummy[0].visible = false
      else
      @hud_dummy[0].visible = true
    end
    
    if $game_party.actors[1] == nil
      @hud_dummy[1].visible = false
      else
      @hud_dummy[1].visible = true
    end

    if $game_party.actors[2] == nil
      @hud_dummy[2].visible = false
      else
      @hud_dummy[2].visible = true
    end

    if $game_party.actors[3] == nil
      @hud_dummy[3].visible = false
      else
      @hud_dummy[3].visible = true
    end
  end
  
  def main_window
    @opacity = 200
    @hud_dummy = []
    @hud_dummy[0] = Window_Base.new(1, 444,461, 11)
    @hud_dummy[1] = Window_Base.new(1, 456,461, 11)
    @hud_dummy[2] = Window_Base.new(1, 468,461, 11)
    @hud_dummy[3] = Window_Base.new(0, 0,0, 0)
    @hud_dummy[0].opacity = @opacity
    @hud_dummy[1].opacity = @opacity
    @hud_dummy[2].opacity = @opacity
    @hud_dummy[3].opacity = @opacity
    @hud_window = Window_HUD.new
    if $game_party.actors[0] == nil
      @hud_dummy[0].visible = false
      else
      @hud_dummy[0].visible = true
    end
    
    if $game_party.actors[1] == nil
      @hud_dummy[1].visible = false
      else
      @hud_dummy[1].visible = true
    end

    if $game_party.actors[2] == nil
      @hud_dummy[2].visible = false
      else
      @hud_dummy[2].visible = true
    end

    if $game_party.actors[3] == nil
      @hud_dummy[3].visible = false
      else
      @hud_dummy[3].visible = true
    end
    @hud = true
  end
  
  def turn_hud_off
    for i in 0...$game_party.actors.size
    @hud_window.visible, @hud_dummy[i].visible = false, false
    end
    return
  end
  
  def turn_hud_on
    for i in 0...$game_party.actors.size
    @hud_window.visible, @hud_dummy[i].visible = true, true
    end
    return
  end
  
end

  
class Window_HUD < Window_Base
  def initialize
    super(0, 0, 800, 600)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    unless $game_party.actors[0] == nil
    @old_hp1 = $game_party.actors[0].hp
    @old_sp1 = $game_party.actors[0].sp
    @old_exp1 = $game_party.actors[0].now_exp
    end
    unless $game_party.actors[1] == nil
    @old_hp2 = $game_party.actors[1].hp
    @old_sp2 = $game_party.actors[1].sp
    @old_exp2 = $game_party.actors[1].now_exp
    end
    unless $game_party.actors[2] == nil
    @old_hp3 = $game_party.actors[2].hp
    @old_sp3 = $game_party.actors[2].sp
    @old_exp3 = $game_party.actors[2].now_exp
    end
    unless $game_party.actors[3] == nil
    @old_hp4 = $game_party.actors[3].hp
    @old_sp4 = $game_party.actors[3].sp
    @old_exp4 = $game_party.actors[3].now_exp
    end

    refresh
  end
  
  def refresh
    self.contents.clear
    for i in 0...$game_party.actors.size
    actor = $game_party.actors[i]
    x = 25 + i * 12
    self.contents.font.size = 21
    draw_actor_graphic(actor, y + 16, 476)
    self.contents.font.color = normal_color
    self.contents.draw_text(x - 25, 360, 100, 32, actor.name)
    draw_slant_bar(x + 403, 38, actor.hp, actor.maxhp, width = 100, height = 10, bar_color = Color.new(24, 248, 74, 255), end_color = Color.new(224, 254, 214, 255))
    draw_slant_bar(x + 403, 138, actor.sp, actor.maxsp, width = 100, height = 10, bar_color = Color.new(228, 211, 118, 255), end_color = Color.new(250, 247, 226, 255))
    unless actor.level == 99
    draw_slant_bar(x + 403, 238, actor.now_exp, actor.next_exp, width = 100, height = 10, bar_color = Color.new(0, 150, 0, 255), end_color = Color.new(60, 255, 60, 255))
  else
    draw_slant_bar(x + 8, 436, 1, 1, width = 100, height = 10, bar_color = Color.new(0, 150, 0, 255), end_color = Color.new(60, 255, 60, 255))
    end
    self.contents.font.size = 12
    draw_actor_state(actor, x + 280, 303, 32)
    self.contents.font.color = normal_color
    self.contents.font.bold = true
    self.contents.font.color = actor.hp == 0 ? knockout_color : actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
    self.contents.draw_text(x + 460, 282, 100, 32, "#{actor.hp}" + "/" + "#{actor.maxhp}", 1)
    self.contents.font.color = actor.sp == 0 ? crisis_color : actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
    self.contents.draw_text(x + 200, 100, 400, 320, "#{actor.sp}" + "/" + "#{actor.maxsp}", 1)
    self.contents.font.color = system_color
    self.contents.font.size = 20
    self.contents.font.bold = false
    self.contents.draw_text(y + 75, 403, 500, 32, $data_system.words.hp)
    self.contents.draw_text(y + 170, 403, 500, 32, $data_system.words.sp)
    self.contents.draw_text(y + 280, 403, 500, 32, "Pain")
  end
end

def update
  super
    unless $game_party.actors[0] == nil
  if @old_hp1 != $game_party.actors[0].hp or @old_sp1 != $game_party.actors[0].sp or @old_exp1 != $game_party.actors[0].now_exp
      refresh
      @old_hp1 = $game_party.actors[0].hp
      @old_sp1 = $game_party.actors[0].sp
      @old_exp1 = $game_party.actors[0].now_exp
    end
  end
  unless $game_party.actors[1] == nil
      if @old_hp2 != $game_party.actors[1].hp or @old_sp2 != $game_party.actors[1].sp or @old_exp2 != $game_party.actors[1].now_exp
      refresh
      @old_hp2 = $game_party.actors[1].hp
      @old_sp2 = $game_party.actors[1].sp
      @old_exp2 = $game_party.actors[1].now_exp
    end
  end
  unless $game_party.actors[2] == nil
  if @old_hp3 != $game_party.actors[2].hp or @old_sp3 != $game_party.actors[2].sp or @old_exp3 != $game_party.actors[2].now_exp
      refresh
      @old_hp3 = $game_party.actors[2].hp
      @old_sp3 = $game_party.actors[2].sp
      @old_exp3 = $game_party.actors[2].now_exp
    end
  end
  unless $game_party.actors[3] == nil
  if @old_hp4 != $game_party.actors[3].hp or @old_sp4 != $game_party.actors[3].sp or @old_exp4 != $game_party.actors[3].now_exp
      refresh
      @old_hp4 = $game_party.actors[3].hp
      @old_sp4 = $game_party.actors[3].sp
      @old_exp4 = $game_party.actors[3].now_exp
    end
    end

  end
end
    
class Window_Base < Window
  def draw_slant_bar(y, x, min, max, width = 152, height = 6,
      bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
    for i in 0..height
      self.contents.fill_rect(x + i, y + height - i, width + 1, 1, Color.new(50, 50, 50, 200))
    end
    for i in 1..(height - 1)
      r = 100 * (height - i) / height + 0 * i / height
      g = 100 * (height - i) / height + 0 * i / height
      b = 100 * (height - i) / height + 0 * i / height
      a = 255 * (height - i) / height + 255 * i / height
      self.contents.fill_rect(x + i, y + height - i, width, 1, Color.new(r, b, g, a))
    end
    for i in 1..( (min / max.to_f) * width - 1)
      for j in 1..(height - 1)
        r = bar_color.red * (width - i) / width + end_color.red * i / width
        g = bar_color.green * (width - i) / width + end_color.green * i / width
        b = bar_color.blue * (width - i) / width + end_color.blue * i / width
        a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
        self.contents.fill_rect(x + i + j, y + height - j, 1, 1, Color.new(r, g, b, a))
      end
    end
  end
  
end

class Game_Actor
  def now_exp
    return @exp - @exp_list[@level]
  end
  def next_exp
    return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
  end
end
 
That script shouldn't be the problem; it's made for this version of RMXP (v1.02)
Maybe another script..?

How many scripts do you have in there?. Maybe you should remove them one by one and post the script that probably gives the lag over here.

~Budsie
 
So.. if you remove it the lag is gone?.
For me the script looks like THIS.

No lag though.
The lag is probably because of your computer, 'cause this is a pretty heavy script; it's always on the screen.

Look at this:
Enterbrain":38nx80qy said:
Minimum System Requirements

* Microsoft® Windows® 98/98SE/Me/XP/2000
* PC with 800MHz Intel® Pentium® III equivalent or higher processor
* At least 128 MB of system RAM
* 1024x768 or better video resolution in High Color mode
* DirectSound-compatible sound card
* At least 100 MB of available hard disk space


Recommended System Requirements

* Microsoft® Windows® XP
* PC with 1.5GHz Intel® Pentium® 4 equivalent or higher processor
* At least 256 MB of system RAM
* 1024x768 or better video resolution in True Color mode
* DirectSound-compatible sound card
* At least 500 MB of available hard disk space

~Budsie
 
I dont really want to go on about how good my computer is, but lets just say my computer is between 40-50 times better than the recommended system requirements.
Try putting on a fog moving at 99 pixels per second, then changing a character's HP.

Here is the project that is lagging with this script
http://www.megaupload.com/?d=8WCG4SPF

It might actually be happening because there is an animation and the script is being refreshed at the same time. Windows really sucks for optimizing pictures, especially animated pictures. A simple animated pop-up can take Counter-Strike: Source from 100 FPS to 70, and that's just sad.



On a side note, could anyone help me use this script (yes the one that is lagging) and show me how to make the text display vertically ontop of one another instead of beside each other?

Right now it goes like this,

HP--HP--HP
MP--MP--MP

and I need it to go like this,

HP--MP
HP--MP
HP--MP

Anyone whos had a lot of experience with positioning things in scripts could help me out it would be very appreciated
(the script below is a bit more modified than the one in the demo)

Code:
class Scene_Map
  
  alias raz_hud_main main
  alias raz_hud_update update
  
  def main
    @size = $game_party.actors.size
    raz_hud_main
    @hud_window.dispose
    @hud_dummy[0].dispose
    @hud_dummy[1].dispose
    @hud_dummy[2].dispose
    @hud_dummy[3].dispose
  end
  
  def update
  if @size != $game_party.actors.size
     @hud_window.refresh
      show_window
    end
  if @hud == true
      else
    main_window
  end
  
    @hud_window.update
    raz_hud_update
  end
  
  def show_window
    @size = $game_party.actors.size
    if $game_party.actors[0] == nil
      @hud_dummy[0].visible = false
      else
      @hud_dummy[0].visible = true
    end
    
    if $game_party.actors[1] == nil
      @hud_dummy[1].visible = false
      else
      @hud_dummy[1].visible = true
    end

    if $game_party.actors[2] == nil
      @hud_dummy[2].visible = false
      else
      @hud_dummy[2].visible = true
    end

    if $game_party.actors[3] == nil
      @hud_dummy[3].visible = false
      else
      @hud_dummy[3].visible = true
    end
  end
  
  def main_window
    @opacity = 200
    @hud_dummy = []
    @hud_dummy[0] = Window_Base.new(1, 444,461, 11)
    @hud_dummy[1] = Window_Base.new(1, 456,461, 11)
    @hud_dummy[2] = Window_Base.new(1, 468,461, 11)
    @hud_dummy[3] = Window_Base.new(0, 0,0, 0)
    @hud_dummy[0].opacity = @opacity
    @hud_dummy[1].opacity = @opacity
    @hud_dummy[2].opacity = @opacity
    @hud_dummy[3].opacity = @opacity
    @hud_window = Window_HUD.new
    if $game_party.actors[0] == nil
      @hud_dummy[0].visible = false
      else
      @hud_dummy[0].visible = true
    end
    
    if $game_party.actors[1] == nil
      @hud_dummy[1].visible = false
      else
      @hud_dummy[1].visible = true
    end

    if $game_party.actors[2] == nil
      @hud_dummy[2].visible = false
      else
      @hud_dummy[2].visible = true
    end

    if $game_party.actors[3] == nil
      @hud_dummy[3].visible = false
      else
      @hud_dummy[3].visible = true
    end
    @hud = true
  end
  
  def turn_hud_off
    for i in 0...$game_party.actors.size
    @hud_window.visible, @hud_dummy[i].visible = false, false
    end
    return
  end
  
  def turn_hud_on
    for i in 0...$game_party.actors.size
    @hud_window.visible, @hud_dummy[i].visible = true, true
    end
    return
  end
  
end

  
class Window_HUD < Window_Base
  def initialize
    super(-10, 0, 800, 600)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    unless $game_party.actors[0] == nil
    @old_hp1 = $game_party.actors[0].hp
    @old_sp1 = $game_party.actors[0].sp
    @old_exp1 = $game_party.actors[0].now_exp
    end
    unless $game_party.actors[1] == nil
    @old_hp2 = $game_party.actors[1].hp
    @old_sp2 = $game_party.actors[1].sp
    @old_exp2 = $game_party.actors[1].now_exp
    end
    unless $game_party.actors[2] == nil
    @old_hp3 = $game_party.actors[2].hp
    @old_sp3 = $game_party.actors[2].sp
    @old_exp3 = $game_party.actors[2].now_exp
    end
    unless $game_party.actors[3] == nil
    @old_hp4 = $game_party.actors[3].hp
    @old_sp4 = $game_party.actors[3].sp
    @old_exp4 = $game_party.actors[3].now_exp
    end

    refresh
  end
  
  def refresh
    self.contents.clear
    for i in 0...$game_party.actors.size
    actor = $game_party.actors[i]
    x = 25 + i * 12
    self.contents.font.size = 21
    draw_actor_graphic(actor, y + 16, 476)
    self.contents.font.color = normal_color
    self.contents.draw_text(x - 25, 360, 100, 32, actor.name)
    draw_slant_bar(x + 403, 38, actor.hp, actor.maxhp, width = 100, height = 10, bar_color = Color.new(24, 248, 74, 255), end_color = Color.new(224, 254, 214, 255))
    draw_slant_bar(x + 403, 138, actor.sp, actor.maxsp, width = 100, height = 10, bar_color = Color.new(228, 211, 118, 255), end_color = Color.new(250, 247, 226, 255))
    unless actor.level == 99
    draw_slant_bar(x + 403, 238, actor.now_exp, actor.next_exp, width = 100, height = 10, bar_color = Color.new(0, 150, 0, 255), end_color = Color.new(60, 255, 60, 255))
  else
    draw_slant_bar(x + 8, 436, 1, 1, width = 100, height = 10, bar_color = Color.new(0, 150, 0, 255), end_color = Color.new(60, 255, 60, 255))
  end
    actor = $game_party.actors[i]
    x = 25 + i * 60
    self.contents.font.size = 12
    draw_actor_state(actor, x + 45, 360)
    self.contents.font.color = normal_color
    self.contents.font.bold = true
    self.contents.font.color = actor.hp == 0 ? knockout_color : actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
    self.contents.draw_text(x + 16, 382, 100, 32, "#{actor.hp}" + "/" + "#{actor.maxhp}", 1)
    self.contents.font.color = actor.sp == 0 ? crisis_color : actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
    self.contents.draw_text(x + 16, 402, 100, 32, "#{actor.sp}" + "/" + "#{actor.maxsp}", 1)
    self.contents.font.color = system_color
    self.contents.font.size = 20
    self.contents.font.bold = false
    self.contents.draw_text(y, 384, 500, 32, $data_system.words.hp)
    self.contents.draw_text(y, 404, 500, 32, $data_system.words.sp)
    self.contents.draw_text(y, 424, 500, 32, "Exp")
  end
end

def update
  super
    unless $game_party.actors[0] == nil
  if @old_hp1 != $game_party.actors[0].hp or @old_sp1 != $game_party.actors[0].sp or @old_exp1 != $game_party.actors[0].now_exp
      refresh
      @old_hp1 = $game_party.actors[0].hp
      @old_sp1 = $game_party.actors[0].sp
      @old_exp1 = $game_party.actors[0].now_exp
    end
  end
  unless $game_party.actors[1] == nil
      if @old_hp2 != $game_party.actors[1].hp or @old_sp2 != $game_party.actors[1].sp or @old_exp2 != $game_party.actors[1].now_exp
      refresh
      @old_hp2 = $game_party.actors[1].hp
      @old_sp2 = $game_party.actors[1].sp
      @old_exp2 = $game_party.actors[1].now_exp
    end
  end
  unless $game_party.actors[2] == nil
  if @old_hp3 != $game_party.actors[2].hp or @old_sp3 != $game_party.actors[2].sp or @old_exp3 != $game_party.actors[2].now_exp
      refresh
      @old_hp3 = $game_party.actors[2].hp
      @old_sp3 = $game_party.actors[2].sp
      @old_exp3 = $game_party.actors[2].now_exp
    end
  end
  unless $game_party.actors[3] == nil
  if @old_hp4 != $game_party.actors[3].hp or @old_sp4 != $game_party.actors[3].sp or @old_exp4 != $game_party.actors[3].now_exp
      refresh
      @old_hp4 = $game_party.actors[3].hp
      @old_sp4 = $game_party.actors[3].sp
      @old_exp4 = $game_party.actors[3].now_exp
    end
    end

  end
end
    
class Window_Base < Window
  def draw_slant_bar(y, x, min, max, width = 152, height = 6,
      bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
    for i in 0..height
      self.contents.fill_rect(x + i, y + height - i, width + 1, 1, Color.new(50, 50, 50, 200))
    end
    for i in 1..(height - 1)
      r = 100 * (height - i) / height + 0 * i / height
      g = 100 * (height - i) / height + 0 * i / height
      b = 100 * (height - i) / height + 0 * i / height
      a = 255 * (height - i) / height + 255 * i / height
      self.contents.fill_rect(x + i, y + height - i, width, 1, Color.new(r, b, g, a))
    end
    for i in 1..( (min / max.to_f) * width - 1)
      for j in 1..(height - 1)
        r = bar_color.red * (width - i) / width + end_color.red * i / width
        g = bar_color.green * (width - i) / width + end_color.green * i / width
        b = bar_color.blue * (width - i) / width + end_color.blue * i / width
        a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
        self.contents.fill_rect(x + i + j, y + height - j, 1, 1, Color.new(r, g, b, a))
      end
    end
  end
  
end

class Game_Actor
  def now_exp
    return @exp - @exp_list[@level]
  end
  def next_exp
    return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
  end
end
 

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