Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if true # << Make true to use this script, false to disable.
- #===============================================================================
- #
- # ☆ $D13x - Simple Antilag
- # -- Author : Dekita
- # -- Version : 1.0
- # -- Level : Easy / Normal
- # -- Requires : N/A
- # -- Engine : RPG Maker VX Ace.
- #
- #===============================================================================
- # ☆ Import
- #-------------------------------------------------------------------------------
- $D13x={}if$D13x==nil
- $D13x[:Antilag]=true
- #===============================================================================
- # ☆ Updates
- #-------------------------------------------------------------------------------
- # D /M /Y
- # 29/o3/2o13 - Started, Finished,
- #
- #===============================================================================
- # ☆ Introduction
- #-------------------------------------------------------------------------------
- # This simple script slightly reduces lag caused by events.
- # It also stops animations from causing lag spikes when being played.
- #
- #===============================================================================
- # ★☆★☆★☆★☆★☆★☆★☆★ TERMS AND CONDITIONS: ☆★☆★☆★☆★☆★☆★☆★☆★☆
- #===============================================================================
- # 1. You MUST give credit to "Dekita" !!
- # 2. You are NOT allowed to repost this script.(or modified versions)
- # 3. You are NOT allowed to convert this script.
- # 4. You are NOT allowed to use this script for Commercial games.
- # 5. ENJOY!
- #
- # "FINE PRINT"
- # By using this script you hereby agree to the above terms and conditions,
- # if any violation of the above terms occurs "legal action" may be taken.
- # Not understanding the above terms and conditions does NOT mean that
- # they do not apply to you.
- # If you wish to discuss the terms and conditions in further detail you can
- # contact me at http://dekitarpg.wordpress.com/
- #
- #===============================================================================
- # ☆ Instructions
- #-------------------------------------------------------------------------------
- # Place Below " ▼ Materials " and Above " ▼ Main " in your script editor.
- #
- #===============================================================================
- # ☆ Script Calls
- #-------------------------------------------------------------------------------
- # $game_system.anti_lag = Boolean
- # ^- Event anti Lag
- #
- # $game_system.anti_lag_ani = Boolean
- # ^- Animation anti Lag
- #
- #===============================================================================
- # ☆ Notetags ( default )
- #-------------------------------------------------------------------------------
- # N/A
- #
- #===============================================================================
- # ☆ HELP
- #-------------------------------------------------------------------------------
- # N/A
- #
- #===============================================================================
- module Anti_Lag
- #===============================================================================
- #-----------------------------------------------------------------------------
- # Out Of Screen Update Range
- #-----------------------------------------------------------------------------
- Event_Update_Range = 3
- #-----------------------------------------------------------------------------
- # Event Antilag
- #-----------------------------------------------------------------------------
- Event_Anti_Lag_On = true
- #-----------------------------------------------------------------------------
- # Animation Antilag
- #-----------------------------------------------------------------------------
- Anima_Anti_lag_On = true
- #####################
- # CUSTOMISATION END #
- end #####################
- #☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★#
- # #
- # http://dekitarpg.wordpress.com/ #
- # #
- #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆#
- #===============================================================================#
- # ARE YOU MODIFYING BEYOND THIS POINT? \.\. #
- # YES?\.\. #
- # OMG, REALLY? \| #
- # WELL SLAP MY FACE AND CALL ME A DRAGONITE.\..\.. #
- # I REALLY DIDN'T THINK YOU HAD IT IN YOU.\..\.. #
- #===============================================================================#
- module SceneManager
- #===============================================================================
- #-----------------------------------------------------------------------------
- # Alias List
- #-----------------------------------------------------------------------------
- class << self
- alias :call_antilag :call
- alias :goto_antilag :goto
- end
- #-----------------------------------------------------------------------------
- # Call Scene
- #-----------------------------------------------------------------------------
- def self.call(scene_class)
- call_antilag(scene_class)
- dispose_ani_crap
- end
- #-----------------------------------------------------------------------------
- # Goto Scene
- #-----------------------------------------------------------------------------
- def self.goto(scene_class)
- goto_antilag(scene_class)
- dispose_ani_crap
- end
- #-----------------------------------------------------------------------------
- # Dispose Ani Crap
- #-----------------------------------------------------------------------------
- def self.dispose_ani_crap
- return if $game_temp.ani_crap == nil
- $game_temp.ani_crap.each do |ani|
- ani.dispose
- end
- $game_temp.ani_crap = nil
- end
- end
- #===============================================================================
- class Game_Temp
- #===============================================================================
- #-----------------------------------------------------------------------------
- # Alias List
- #-----------------------------------------------------------------------------
- alias :init_abs_antilag :initialize
- #-----------------------------------------------------------------------------
- # Pi Variables
- #-----------------------------------------------------------------------------
- attr_accessor :ani_crap
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize
- @ani_crap = []
- init_abs_antilag
- end
- end
- #===============================================================================
- class Game_System
- #===============================================================================
- #-----------------------------------------------------------------------------
- # Pi Variables
- #-----------------------------------------------------------------------------
- attr_accessor :anti_lag
- attr_accessor :anti_lag_ani
- #-----------------------------------------------------------------------------
- # Alias List
- #-----------------------------------------------------------------------------
- alias :initantilag :initialize
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize
- @anti_lag = Anti_Lag::Event_Anti_Lag_On
- @anti_lag_ani = Anti_Lag::Anima_Anti_lag_On
- initantilag
- end
- end
- #===============================================================================
- class Game_Map
- #===============================================================================
- #-----------------------------------------------------------------------------
- # Alias List
- #-----------------------------------------------------------------------------
- alias :setup_de_antilag :setup
- #-----------------------------------------------------------------------------
- # Setup
- #-----------------------------------------------------------------------------
- def setup(map_id)
- SceneManager.dispose_ani_crap
- setup_de_antilag(map_id)
- end
- end
- #===============================================================================
- class Game_Event < Game_Character
- #===============================================================================
- #-----------------------------------------------------------------------------
- # Pi Variables
- #-----------------------------------------------------------------------------
- attr_reader :can_update
- #-----------------------------------------------------------------------------
- # Alias List
- #-----------------------------------------------------------------------------
- alias :anti_lag_init_GE :initialize
- alias :updt_anti_lag :update
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize(map_id, event)
- @can_anti_lag = $game_system.anti_lag
- @can_update = true
- if $game_map.loop_horizontal? or $game_map.loop_vertical?
- @can_anti_lag = false
- end
- anti_lag_init_GE(map_id, event)
- end
- #-----------------------------------------------------------------------------
- # Update
- #-----------------------------------------------------------------------------
- def update
- update_anti_lag
- return unless @can_update
- updt_anti_lag
- end
- #-----------------------------------------------------------------------------
- # Update Anti Lag
- #-----------------------------------------------------------------------------
- def update_anti_lag
- if @can_anti_lag != $game_system.anti_lag
- @can_anti_lag = $game_system.anti_lag
- if $game_map.loop_horizontal? or $game_map.loop_vertical?
- @can_anti_lag = false
- end
- end
- event_is_on_screen?
- end
- #-----------------------------------------------------------------------------
- # Event Is On Screen ?
- #-----------------------------------------------------------------------------
- def event_is_on_screen?
- return unless @can_anti_lag
- w = Graphics.width / 32
- h = Graphics.height / 32
- @can_update = false
- os = Anti_Lag::Event_Update_Range
- px = ($game_map.display_x).truncate
- py = ($game_map.display_y).truncate
- dx = @x - px
- dy = @y - py
- if dx.between?(0-os,w+os) && dy.between?(0-os,h+os)
- @can_update = true
- end
- end
- end
- #===============================================================================
- class Sprite_Base < Sprite
- #===============================================================================
- #-----------------------------------------------------------------------------
- # Alias List
- #-----------------------------------------------------------------------------
- alias :dispose_antilagani :dispose_animation
- #-----------------------------------------------------------------------------
- # Dispose Animation
- #-----------------------------------------------------------------------------
- def dispose_animation
- if $game_system.anti_lag_ani
- make_ani_into_crap
- return
- end
- dispose_antilagani
- end
- #-----------------------------------------------------------------------------
- # Make Animation Garbage
- #-----------------------------------------------------------------------------
- def make_ani_into_crap
- $game_temp.ani_crap = [] if $game_temp.ani_crap == nil
- if @ani_bitmap1
- @@_reference_count[@ani_bitmap1] -= 1
- if @@_reference_count[@ani_bitmap1] == 0
- $game_temp.ani_crap << @ani_bitmap1
- end
- end
- if @ani_bitmap2
- @@_reference_count[@ani_bitmap2] -= 1
- if @@_reference_count[@ani_bitmap2] == 0
- $game_temp.ani_crap << @ani_bitmap2
- end
- end
- if @ani_sprites
- @ani_sprites.each {|sprite| sprite.dispose }
- @ani_sprites = nil
- @animation = nil
- end
- @ani_bitmap1 = nil
- @ani_bitmap2 = nil
- end
- end
- #===============================================================================
- class Sprite_Character < Sprite_Base
- #===============================================================================
- #-----------------------------------------------------------------------------
- # Alias List
- #-----------------------------------------------------------------------------
- alias :anti_lag_update :update
- #-----------------------------------------------------------------------------
- # Update
- #-----------------------------------------------------------------------------
- def update
- if $game_system.anti_lag and @character.is_a?(Game_Event)
- check_can_update_sprite
- return unless self.visible
- end
- anti_lag_update
- end
- #-----------------------------------------------------------------------------
- # Update
- #-----------------------------------------------------------------------------
- def check_can_update_sprite
- if self.visible and !@character.can_update
- reset_sprite_animation
- end
- self.visible = @character.can_update
- end
- #-----------------------------------------------------------------------------
- # Reset Sprite Animation
- #-----------------------------------------------------------------------------
- def reset_sprite_animation
- dispose_animation
- end
- end
- #===============================================================================
- class Scene_Base
- #===============================================================================
- #-----------------------------------------------------------------------------
- # Alias List
- #-----------------------------------------------------------------------------
- alias :term_antilag :terminate
- #-----------------------------------------------------------------------------
- # Terminate
- #-----------------------------------------------------------------------------
- def terminate
- term_antilag
- SceneManager.dispose_ani_crap
- end
- end
- #==============================================================================#
- # http://dekitarpg.wordpress.com/ #
- #==============================================================================#
- end # if true # << Make true to use this script, false to disable.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement