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.

Super Simple Anti-Lag Script (Very Fast!)

Status
Not open for further replies.

Anonymous

Guest

No idea. But scripts shouldn't lag, it's entirely possible to write almost anything without lag.
 
I found the problem: I watched Alastyr_six his cutscene to see how it works. It laggs also.... I think it's a problem with the program itself....
 
Yes, if you have a lot of events on one screen, you're going to get lots of lag. I'm working on making simple events for my next game. If I figure out how to make them work, I'll post the fix here. :)
 

darkyy

Member

ok this scrip really helped out i must say :)
500-500 sized map with everything filled with 3 layers and everything was filled with diffrent stuff from 14% down to 8% it really does help :)
Rajiu's edit is included in this test

EDIT ok now i have tested with 200 moving event people at highest moving frequenzy and higest speed and the utilization of the cpu then was 41 with anti lag it is reduced to 22 (this is with around 30 moving on screen
Rajiu's edit is included in this test

I must say it is really a good script :)
 
(I apologize in advance for the necropost :please:)

I'd like to use this because I have a big (750 x 400) map (worldmap) and instead of having to redo it and make it smaller maps, I am pretty sure that an anti-lag script would fix this.

However, I had one question if there is an event that is set to Parallel Process or Auto Run and it is off the screen will it still run? Or does it have to be within a certain range?

Thanks, and I apologize again but I didn't see any answers to this in the thread. :)
 
Im kindda curious.. what is the ideal FPS? the best possible FPS of a 80 x 80 map?

-This is because I cant seem to achieve an 50 or above FPS contrary to the topic title that claims FPS at 100 percent.. or my PC really sucks...

i.e: in my game I have a 50 x 80 map with 10 events with no parallel
events and the FPS falls around 25 - 40 FPS.

whats the average FPS that should be followed?
 
mensahero;188719 said:
Im kindda curious.. what is the ideal FPS? the best possible FPS of a 80 x 80 map?

-This is because I cant seem to achieve an 50 or above FPS contrary to the topic title that claims FPS at 100 percent.. or my PC really sucks...

i.e: in my game I have a 50 x 80 map with 10 events with no parallel
events and the FPS falls around 25 - 40 FPS.

whats the average FPS that should be followed?
She didn't mean 100 FPS she meant 100 %
Someone told me normal FPS is 40-30ish, also someone else said that above 20 didn't mater cause the human eyes can only see 20 frames per second.
 
Correction: The human eye can see at 60 frames per second. Anything above that is excess speed.

Great script, by the way. I'm sure it'll really come in handy for just about... anybody.
 
Wow this really helps in those ice caves with the icy ground. And with big maps using Mr. Mo's ABS, too! Actually, it works well everywhere! Nice! :D
 
There's one problem that I've come across with this.

Its a great anti lag system, but if you have a big map and are scrolling to a far away point, distant events (that is, distant from wherever your hero is) won't show.

For some reason (not sure why), my old anti lag script didn't have a problem with this...
 
can i achieve the anti lag with this edit
even without the anti lag scripts?

and when lambchop says, "At the bottom of the Game_Map class, add the following method called in_range (def in_range). (Make sure to add this before the last end tag in the class)"

did lambchop mean like this?
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# This class handles the map. It includes scrolling and passable determining
# functions. Refer to "$game_map" for the instance of this class.
#==============================================================================

class Game_Map
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :tileset_name # tileset file name
attr_accessor :autotile_names # autotile file name
attr_accessor :panorama_name # panorama file name
attr_accessor :panorama_hue # panorama hue
attr_accessor :fog_name # fog file name
attr_accessor :fog_hue # fog hue
attr_accessor :fog_opacity # fog opacity level
attr_accessor :fog_blend_type # fog blending method
attr_accessor :fog_zoom # fog zoom rate
attr_accessor :fog_sx # fog sx
attr_accessor :fog_sy # fog sy
attr_accessor :battleback_name # battleback file name
attr_accessor :display_x # display x-coordinate * 128
attr_accessor :display_y # display y-coordinate * 128
attr_accessor :need_refresh # refresh request flag
attr_reader :passages # passage table
attr_reader :priorities # prioroty table
attr_reader :terrain_tags # terrain tag table
attr_reader :events # events
attr_reader :fog_ox # fog x-coordinate starting point
attr_reader :fog_oy # fog y-coordinate starting point
attr_reader :fog_tone # fog color tone
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@map_id = 0
@display_x = 0
@display_y = 0
end

#--------------------------------------------------------------------------
# * Setup
# map_id : map ID
#--------------------------------------------------------------------------
def setup(map_id)
# Put map ID in @map_id memory
@map_id = map_id
# Load map from file and set @map
@map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))
# set tile set information in opening instance variables
tileset = $data_tilesets[@map.tileset_id]
@tileset_name = tileset.tileset_name
@autotile_names = tileset.autotile_names
@panorama_name = tileset.panorama_name
@panorama_hue = tileset.panorama_hue
@fog_name = tileset.fog_name
@fog_hue = tileset.fog_hue
@fog_opacity = tileset.fog_opacity
@fog_blend_type = tileset.fog_blend_type
@fog_zoom = tileset.fog_zoom
@fog_sx = tileset.fog_sx
@fog_sy = tileset.fog_sy
@battleback_name = tileset.battleback_name
@passages = tileset.passages
@priorities = tileset.priorities
@terrain_tags = tileset.terrain_tags
# Initialize displayed coordinates
@display_x = 0
@display_y = 0
# Clear refresh request flag
@need_refresh = false
# Set map event data
@events = {}
for i in @map.events.keys
@events = Game_Event.new(@map_id, @map.events)
end
# Set common event data
@common_events = {}
for i in 1...$data_common_events.size
@common_events = Game_CommonEvent.new(i)
end
# Initialize all fog information
@fog_ox = 0
@fog_oy = 0
@fog_tone = Tone.new(0, 0, 0, 0)
@fog_tone_target = Tone.new(0, 0, 0, 0)
@fog_tone_duration = 0
@fog_opacity_duration = 0
@fog_opacity_target = 0
# Initialize scroll information
@scroll_direction = 2
@scroll_rest = 0
@scroll_speed = 4
end
#--------------------------------------------------------------------------
# * Get Map ID
#--------------------------------------------------------------------------
def map_id
return @map_id
end
#--------------------------------------------------------------------------
# * Get Width
#--------------------------------------------------------------------------
def width
return @map.width
end
#--------------------------------------------------------------------------
# * Get Height
#--------------------------------------------------------------------------
def height
return @map.height
end
#--------------------------------------------------------------------------
# * Get Encounter List
#--------------------------------------------------------------------------
def encounter_list
return @map.encounter_list
end
#--------------------------------------------------------------------------
# * Get Encounter Steps
#--------------------------------------------------------------------------
def encounter_step
return @map.encounter_step
end
#--------------------------------------------------------------------------
# * Get Map Data
#--------------------------------------------------------------------------
def data
return @map.data
end
#--------------------------------------------------------------------------
# * Automatically Change Background Music and Backround Sound
#--------------------------------------------------------------------------
def autoplay
if @map.autoplay_bgm
$game_system.bgm_play(@map.bgm)
end
if @map.autoplay_bgs
$game_system.bgs_play(@map.bgs)
end
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
# If map ID is effective
if @map_id > 0
# Refresh all map events
for event in @events.values
event.refresh
end
# Refresh all common events
for common_event in @common_events.values
common_event.refresh
end
end
# Clear refresh request flag
@need_refresh = false
end
#--------------------------------------------------------------------------
# * Scroll Down
# distance : scroll distance
#--------------------------------------------------------------------------
def scroll_down(distance)
@display_y = [@display_y + distance, (self.height - 15) * 128].min
end
#--------------------------------------------------------------------------
# * Scroll Left
# distance : scroll distance
#--------------------------------------------------------------------------
def scroll_left(distance)
@display_x = [@display_x - distance, 0].max
end
#--------------------------------------------------------------------------
# * Scroll Right
# distance : scroll distance
#--------------------------------------------------------------------------
def scroll_right(distance)
@display_x = [@display_x + distance, (self.width - 20) * 128].min
end
#--------------------------------------------------------------------------
# * Scroll Up
# distance : scroll distance
#--------------------------------------------------------------------------
def scroll_up(distance)
@display_y = [@display_y - distance, 0].max
end
#--------------------------------------------------------------------------
# * Determine Valid Coordinates
# x : x-coordinate
# y : y-coordinate
#--------------------------------------------------------------------------
def valid?(x, y)
return (x >= 0 and x < width and y >= 0 and y < height)
end
#--------------------------------------------------------------------------
# * Determine if Passable
# x : x-coordinate
# y : y-coordinate
# d : direction (0,2,4,6,8,10)
# * 0,10 = determine if all directions are impassable
# self_event : Self (If event is determined passable)
#--------------------------------------------------------------------------
def passable?(x, y, d, self_event = nil)
# If coordinates given are outside of the map
unless valid?(x, y)
# impassable
return false
end
# Change direction (0,2,4,6,8,10) to obstacle bit (0,1,2,4,8,0)
bit = (1 << (d / 2 - 1)) & 0x0f
# Loop in all events
for event in events.values
# If tiles other than self are consistent with coordinates
if event.tile_id >= 0 and event != self_event and
event.x == x and event.y == y and not event.through
# If obstacle bit is set
if @passages[event.tile_id] & bit != 0
# impassable
return false
# If obstacle bit is set in all directions
elsif @passages[event.tile_id] & 0x0f == 0x0f
# impassable
return false
# If priorities other than that are 0
elsif @priorities[event.tile_id] == 0
# passable
return true
end
end
end
# Loop searches in order from top of layer
for i in [2, 1, 0]
# Get tile ID
tile_id = data[x, y, i]
# Tile ID acquistion failure
if tile_id == nil
# impassable
return false
# If obstacle bit is set
elsif @passages[tile_id] & bit != 0
# impassable
return false
# If obstacle bit is set in all directions
elsif @passages[tile_id] & 0x0f == 0x0f
# impassable
return false
# If priorities other than that are 0
elsif @priorities[tile_id] == 0
# passable
return true
end
end
# passable
return true
end
#--------------------------------------------------------------------------
# * Determine Thicket
# x : x-coordinate
# y : y-coordinate
#--------------------------------------------------------------------------
def bush?(x, y)
if @map_id != 0
for i in [2, 1, 0]
tile_id = data[x, y, i]
if tile_id == nil
return false
elsif @passages[tile_id] & 0x40 == 0x40
return true
end
end
end
return false
end
#--------------------------------------------------------------------------
# * Determine Counter
# x : x-coordinate
# y : y-coordinate
#--------------------------------------------------------------------------
def counter?(x, y)
if @map_id != 0
for i in [2, 1, 0]
tile_id = data[x, y, i]
if tile_id == nil
return false
elsif @passages[tile_id] & 0x80 == 0x80
return true
end
end
end
return false
end
#--------------------------------------------------------------------------
# * Get Terrain Tag
# x : x-coordinate
# y : y-coordinate
#--------------------------------------------------------------------------
def terrain_tag(x, y)
if @map_id != 0
for i in [2, 1, 0]
tile_id = data[x, y, i]
if tile_id == nil
return 0
elsif @terrain_tags[tile_id] > 0
return @terrain_tags[tile_id]
end
end
end
return 0
end
#--------------------------------------------------------------------------
# * Get Designated Position Event ID
# x : x-coordinate
# y : y-coordinate
#--------------------------------------------------------------------------
def check_event(x, y)
for event in $game_map.events.values
if event.x == x and event.y == y
return event.id
end
end
end
#--------------------------------------------------------------------------
# * Start Scroll
# direction : scroll direction
# distance : scroll distance
# speed : scroll speed
#--------------------------------------------------------------------------
def start_scroll(direction, distance, speed)
@scroll_direction = direction
@scroll_rest = distance * 128
@scroll_speed = speed
end
#--------------------------------------------------------------------------
# * Determine if Scrolling
#--------------------------------------------------------------------------
def scrolling?
return @scroll_rest > 0
end
#--------------------------------------------------------------------------
# * Start Changing Fog Color Tone
# tone : color tone
# duration : time
#--------------------------------------------------------------------------
def start_fog_tone_change(tone, duration)
@fog_tone_target = tone.clone
@fog_tone_duration = duration
if @fog_tone_duration == 0
@fog_tone = @fog_tone_target.clone
end
end
#--------------------------------------------------------------------------
# * Start Changing Fog Opacity Level
# opacity : opacity level
# duration : time
#--------------------------------------------------------------------------
def start_fog_opacity_change(opacity, duration)
@fog_opacity_target = opacity * 1.0
@fog_opacity_duration = duration
if @fog_opacity_duration == 0
@fog_opacity = @fog_opacity_target
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Refresh map if necessary
if $game_map.need_refresh
refresh
end
# If scrolling
if @scroll_rest > 0
# Change from scroll speed to distance in map coordinates
distance = 2 ** @scroll_speed
# Execute scrolling
case @scroll_direction
when 2 # Down
scroll_down(distance)
when 4 # Left
scroll_left(distance)
when 6 # Right
scroll_right(distance)
when 8 # Up
scroll_up(distance)
end
# Subtract distance scrolled
@scroll_rest -= distance
end
# Update map event
for event in @events.values
if in_range?(event) or event.trigger == 3 or event.trigger == 4
event.update
end
end
# Update common event
for common_event in @common_events.values
common_event.update
end
# Manage fog scrolling
@fog_ox -= @fog_sx / 8.0
@fog_oy -= @fog_sy / 8.0
# Manage change in fog color tone
if @fog_tone_duration >= 1
d = @fog_tone_duration
target = @fog_tone_target
@fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d
@fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d
@fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d
@fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d
@fog_tone_duration -= 1
end
# Manage change in fog opacity level
if @fog_opacity_duration >= 1
d = @fog_opacity_duration
@fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d
@fog_opacity_duration -= 1
end
end
end
#--------------------------------------------------------------------------
# ● Check if events are in range (ANTI-LAG)
#--------------------------------------------------------------------------
def in_range?(object)

diff_x = ($game_map.display_x - object.real_x).abs # absolute value
diff_y = ($game_map.display_x - object.real_x).abs # absolute value

width = 128 * 24 # size * tiles
height = 128 * 19 # size * tiles

return !((diff_x > width) or (diff_y > height))

end


end when she say "At the bottom of the Spriteset_Map class, add the followind method called in_range (def in_range). (Make sure to add this before the last end tag)"

did she mean like this?
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# This class brings together map screen sprites, tilemaps, etc.
# It's used within the Scene_Map class.
#==============================================================================

class Spriteset_Map
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Make viewports
@viewport1 = Viewport.new(0, 0, 640, 480)
@viewport2 = Viewport.new(0, 0, 640, 480)
@viewport3 = Viewport.new(0, 0, 640, 480)
@viewport2.z = 200
@viewport3.z = 5000
# Make tilemap
@tilemap = Tilemap.new(@viewport1)
@tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
for i in 0..6
autotile_name = $game_map.autotile_names
@tilemap.autotiles = RPG::Cache.autotile(autotile_name)
end
@tilemap.map_data = $game_map.data
@tilemap.priorities = $game_map.priorities
# Make panorama plane
@panorama = Plane.new(@viewport1)
@panorama.z = -1000
# Make fog plane
@fog = Plane.new(@viewport1)
@fog.z = 3000
# Make character sprites
@character_sprites = []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events)
@character_sprites.push(sprite)
end
@character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
# Make weather
@weather = RPG::Weather.new(@viewport1)
# Make picture sprites
@picture_sprites = []
for i in 1..50
@picture_sprites.push(Sprite_Picture.new(@viewport2,
$game_screen.pictures))
end
# Make timer sprite
@timer_sprite = Sprite_Timer.new
# Frame update
update
end

#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
# Dispose of tilemap
@tilemap.tileset.dispose
for i in 0..6
@tilemap.autotiles.dispose
end
@tilemap.dispose
# Dispose of panorama plane
@panorama.dispose
# Dispose of fog plane
@fog.dispose
# Dispose of character sprites
for sprite in @character_sprites
sprite.dispose
end
# Dispose of weather
@weather.dispose
# Dispose of picture sprites
for sprite in @picture_sprites
sprite.dispose
end
# Dispose of timer sprite
@timer_sprite.dispose
# Dispose of viewports
@viewport1.dispose
@viewport2.dispose
@viewport3.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# If panorama is different from current one
if @panorama_name != $game_map.panorama_name or
@panorama_hue != $game_map.panorama_hue
@panorama_name = $game_map.panorama_name
@panorama_hue = $game_map.panorama_hue
if @panorama.bitmap != nil
@panorama.bitmap.dispose
@panorama.bitmap = nil
end
if @panorama_name != ""
@panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
end
Graphics.frame_reset
end
# If fog is different than current fog
if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
@fog_name = $game_map.fog_name
@fog_hue = $game_map.fog_hue
if @fog.bitmap != nil
@fog.bitmap.dispose
@fog.bitmap = nil
end
if @fog_name != ""
@fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
end
Graphics.frame_reset
end
# Update tilemap
@tilemap.ox = $game_map.display_x / 4
@tilemap.oy = $game_map.display_y / 4
@tilemap.update
# Update panorama plane
@panorama.ox = $game_map.display_x / 8
@panorama.oy = $game_map.display_y / 8
# Update fog plane
@fog.zoom_x = $game_map.fog_zoom / 100.0
@fog.zoom_y = $game_map.fog_zoom / 100.0
@fog.opacity = $game_map.fog_opacity
@fog.blend_type = $game_map.fog_blend_type
@fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
@fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
@fog.tone = $game_map.fog_tone
# Update character sprites
for sprite in @character_sprites
if in_range?(sprite.character)
sprite.update
end
end
# Update weather graphic
@weather.type = $game_screen.weather_type
@weather.max = $game_screen.weather_max
@weather.ox = $game_map.display_x / 4
@weather.oy = $game_map.display_y / 4
@weather.update
# Update picture sprites
for sprite in @picture_sprites
sprite.update
end
# Update timer sprite
@timer_sprite.update
# Set screen color tone and shake position
@viewport1.tone = $game_screen.tone
@viewport1.ox = $game_screen.shake
# Set screen flash color
@viewport3.color = $game_screen.flash_color
# Update viewports
@viewport1.update
@viewport3.update
end
end
#--------------------------------------------------------------------------
# ● Check if events are in range (ANTI-LAG)
#--------------------------------------------------------------------------
def in_range?(object)

diff_x = ($game_player.real_x - object.real_x).abs # absolute value
diff_y = ($game_player.real_y - object.real_y).abs # absolute value

width = 128 * 24 # size * tiles
height = 128 * 19 # size * tiles

return !((diff_x > width) or (diff_y > height))

end


im sorry if i had to post the whole script here. i dont know if i was doing the right thing >.<
 
Status
Not open for further replies.

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