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.

I need to fix the lag in this script

I have this script made by sandgolem that makes you see icons above events.

But if you call an event parallel process it's starts slowing the player slowly slowly till he walk very slow. Is there a way to solve this i need this script for showing in my game that these events have quests.

Code:
#==========================================================================
# ** SG Event Icons
#==========================================================================
# sandgolem 
# Version 2
# 21.01.07
#==========================================================================

SG_EventIcon_DefaultOpacity = 60
SG_EventIcon_MaxOpacity = 180
SG_EventIcon_FadeInSpeed = 3

SG_EventIcon_MapMemory = true
  # Switch this to false to disable the map's icons from being remembered.
  
SG_EventIcon_Types = {
  1 => 'Exclamationmark',
  2 => 'Questionmark' }
  # These are shortcuts you can use instead of always putting in a file name.

#==========================================================================
#
# To check for updates or find more scripts, visit:
# http://www.gamebaker.com/rmxp/scripts/
#
# Need help? Support topic:
#   http://forums.gamebaker.com/showthread.php?t=701
#
#==========================================================================

if Object.const_defined?('SDK')
  SDK.log('SG Event Icons', 'sandgolem', 2, '21.01.07')
  if SDK.state('SG Event Icons') != true
    @sg_eventicons_disabled = true
  end
end

if !@sg_eventicons_disabled
#--------------------------------------------------------------------------

class Game_Temp
  attr_accessor :sg_eventicon_sprites
  
  def sg_eventicon_dispose
    return if !@sg_eventicon_sprites
    @sg_eventicon_sprites.each { |i| i.dispose if i != nil }
    @sg_eventicon_sprites = []
  end
end

class Game_Map
  attr_accessor :sg_eventicons
  
  def sg_geteventicons
    return @sg_eventicons if !SG_EventIcon_MapMemory
    return @sg_eventicons[@map_id]
  end

  def sg_geteventicons=(new)
    if !SG_EventIcon_MapMemory
      @sg_eventicons = (new)
    else
      @sg_eventicons[@map_id] = (new)
    end
  end
  
  def sg_cleareventicons
    for i in 0...@sg_eventicons[@map_id].size
      return if @sg_eventicons[@map_id][i] != nil
    end
    @sg_eventicons[@map_id] = nil
  end
  
  alias sandgolem_eventicons_mapsetup setup
  def setup(map_id)
    if !@sg_eventicons or @map_id != map_id
      if !SG_EventIcon_MapMemory
        @sg_eventicons = []
      else
        @sg_eventicons = {} if !@sg_eventicons
        sg_cleareventicons if @sg_eventicons[@map_id]
        @sg_eventicons[map_id] = [] if !@sg_eventicons[map_id]
      end
      $game_temp.sg_eventicon_dispose
      $game_temp.sg_eventicon_sprites = []
    end
    sandgolem_eventicons_mapsetup(map_id)
  end
  
  def sg_eventicon_opacity(opac = SG_EventIcon_DefaultOpacity)
    return if !$game_temp.sg_eventicon_sprites
    $game_temp.sg_eventicon_sprites.each { |i| i.opacity = opac if i != nil }
  end
  
  def sg_eventicon_show
    # Called by the start of Scene_Map, redraws old icons
    if !$game_map.sg_geteventicons
      $game_map.sg_geteventicons = []
      $game_temp.sg_eventicon_sprites = []
    end
    return if $game_map.sg_geteventicons == []
    for i in 0...$game_map.sg_geteventicons.size
      z = $game_map.sg_geteventicons[i]
      next if z == nil
      sg_eventicon(z[0],z[1],z[2],z[3])
    end
    sg_eventicon_opacity
  end
  
  def sg_eventicon(event,type,xoff,yoff)
    $game_temp.sg_eventicon_sprites = [] if !$game_temp.sg_eventicon_sprites
    icon = SG_EventIcon.new
    $game_temp.sg_eventicon_sprites += [icon]
    icon.event = @events[event]
    icon.xoff = xoff
    icon.yoff = yoff
    icon.x = @events[event].screen_x + xoff
    icon.y = @events[event].screen_y + yoff    
    icon.bitmap = RPG::Cache.icon(type)
    icon.z = 541
    icon.opacity = SG_EventIcon_DefaultOpacity
  end
end

class Scene_Map 
  alias sandgolem_eventicons_transfer transfer_player
  def transfer_player
    $game_map.sg_eventicon_opacity(0)
    sandgolem_eventicons_transfer
    $game_map.sg_eventicon_show
  end
  
  alias sandgolem_eventicons_mapmain main
  def main
    $game_map.sg_eventicon_show
    sandgolem_eventicons_mapmain
    $game_temp.sg_eventicon_dispose
  end
  
  alias sandgolem_eventicons_mapupdate update
  def update
    sandgolem_eventicons_mapupdate
    $game_temp.sg_eventicon_sprites.each { |i| i.update if i != nil }
  end
end

def sg_eventicon(event,type,xoff = -12,yoff = -74)
  type = SG_EventIcon_Types[type] if type.is_a?(Numeric)
  $game_map.sg_geteventicons += [[event,type,xoff,yoff]]
  $game_map.sg_eventicon(event,type,xoff,yoff)
end
  
def sg_uneventicon(event)
  z = $game_map.sg_geteventicons
  for i in 0...z.size
    if z[i] != nil && z[i][0] == event
      z[i] = nil
      $game_temp.sg_eventicon_sprites[i].dispose
      $game_temp.sg_eventicon_sprites[i] = nil
    end
  end
  z.delete(nil)
  $game_temp.sg_eventicon_sprites.delete(nil)
end

class SG_EventIcon < Sprite
  attr_accessor :eventid, :event, :xoff, :yoff, :type
  
  def update
    if self.opacity < SG_EventIcon_MaxOpacity
      self.opacity += SG_EventIcon_FadeInSpeed
    end
    self.x = @event.screen_x + @xoff
    self.y = @event.screen_y + @yoff
  end
end

#--------------------------------------------------------------------------
end

And this is the part were it explains what you need to do to show icons on events(This is not part of the script, i posted it for those who wish to try it.):

#==========================================
# Event icons guide
#==========================================
#sg_eventicon(4,1)
#
#Puts icon #1 above character 4 at the default position
#
#sg_eventicon(27,'003-Weapon03')
#
#Puts icon '003-Weapon03' above character 27
#
#sg_eventicon(11,1,-12,-50)
#
#Puts icon #1 above character 11 at a new x & y coordinate based on his own.
#You'll need to play around with the numbers a little.
#===================================================
 
Yeah, parallel processes can definitely cause a lot of event lag, especially coupled with scripts like this.

You probably have, but I guess I'll give it a try - have you tried an anti-lag script yet? Those can help, but with the degree of lag you seem to have, I don't know if it'll do it completely.
 
I don't think I put checking for stacking in that version, so your parallel process would likely be the problem.

It'd add a new icon every time it'd be run through, which'll add up quick since those are activated every 1/40th of a second. Eventually you might have the script drawing 50,000 icons on the screen. :eek:

The script says "This script is currently being updated. Don't use it at the moment unless you really want to. There are a few annoying bugs & kinks to work out." so don't use it if it's giving you any other problems. Too busy right now with work to even think about touching old scripts. :)
 
I need it for my game that's why i'm using it. I'm making some sort of stuff like world of warcraft and with the help of this script i can show icons like an exclamation mark or questionmark on events heads for quests so i will need it for sure.
 
Does it work without sdk? and i haven't understand well the comment on how to show icons. It says [icon_name] in text that all what it's written.

[Edit]
When i tried it without the lines of the sdk it gave me an error on this line:

bitmap.draw_icon_text(0, 0, 192, 24, @character.etd_display_text, 1)
 

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