(VX) Compatibility Patch OR enabling/disabling script with switch (visual issues)

Hello everyone!


I know there are not many people - let alone coders! - who still use VX but I hope you can help me nonetheless. My main project is on VX so it's pretty important to me.


As the semi-convoluted title says, I'm trying to find a solution for a compatibility issue between 3 scripts - SwapXT, Wall Tile Extension and (Anaryus) Anti-Lag. I'm already using a patch which makes SwapXT work with Wall Tile Extension, which is doing just fine. However, once Anti-Lag is added to the mix, the display of some tiles gets a bit bonkers. These are the issues I stumbled across:

1. Bridges technically work, meaning that you can still walk beneath them and walk on them. But once you walk on a bridge, the bridge is still displayed above the player. That doesn't happen without Anti-Lag.
2. Similarily, the northern edge of a cliff is displayed above the player. This is good if the player actually walks beneath them. But the edges are still displayed above the player when the player (or an event) is supposed to be standing on the edge. Again, that doesn't happen without Anti-Lag.
3. Without Anti-Lag, events that are placed behind a ceiling or wall should be semi-transparent once the player is 1 tile away. With Anti-Lag, the event is not semi-transparent, but not visible at all. This instance is not as bad as the first 2 though, so if this issue would be hard to fix, feel free to skip it.

I already tried putting the Anti-Lag script before SwapXT and Wall Tile Extension but that's also a bad idea because putting the script behind either of those makes the passability settings go totally nuts and you can walk on pretty much everything.

Of course you could just say: "Well, so don't use Anti-Lag and everything's fine!". Unfortunately, since I'm trying to save maps by combining some house interiors on one big map, the lag without Anaryus script is unbearable... That's why I'm humbly asking for a compatibility patch.


Alternatively, it could also help to use an in-game switch to enable/disable the visual changes made by the Anti-Lag script, since the cliff/bridge issue would only be problematic in exterior maps and the most lag I get is in interior maps. So if that's easier to code (or actually possible in the first place), I would totally be fine with it.


You can find a demo to demonstrate the visual issues in the attachment. In case you can't look at the script editor, the zip file also contains the scripts in question as .txt.


I hope this is doable! I really need your help. 😢
Moved to: RGSSx Script Support
I'm sorry! Thank you for correcting my mistake. 🙏
Don't mind me, I'm gonna bump this-
(Anaryus) Anti-Lag.
That script is horrible. It breaks all passability on the map. at least in your demo.
I found two others so far.
If your not making a commercial game then Gamebaker has one (retrieved from internet archive), otherwise there is a small snippett that is supposed to be a antilag script.

Spoiler: Gamebaker
Ruby:
#==========================================================================
# ** GameBaker Anti-Event Lag
#==========================================================================
# by sandgolem
#   Concept based on Near Fantastica's original RMXP script
#
# Still a beta version, still the looping bug
#
# Version 3 [VX]
# February 22nd, 2008
#==========================================================================
=begin
Script Description
Reduces game lag from events. By default every single event (even the ones doing nothing)
 has to run through over 41 lines of code per frame. At 60 fps, that's 2460+ a second.
 Adds up pretty fast.

This script chops that down mightily. Only events within a screen distance of your
choice & active events/common events are updated. This script was developed for a
commercial game which we are allowing everyone to use for non-commercial games.

Instructions:
This Rpg Maker VX script does not require any changes, but options are available:

AntiLagDisable = 0
Change that number if you would like to use a switch to disable the anti lag script.

AntiLagAlwaysMove = '&'
Including the & sign (changable in this line) in an event's name will cause it to
always move regardless of where it is. This is good for events you have on a schedule
such as a baker who moves between his bakery and the grocery store bringing in fresh
loaves of bread.

The other numbers at the top of the script control how much distance away from the
screen is refreshed. You may want to change these if you are using larger charactersets.
Compatibility Notes
This script assumes events will be treated as normal. Other scripts may interfere.

Rewrites:
Game_Event force_move_route (created, supering it in Game_Character)
Game_Event update
Aliases:
Game_CommonEvent refresh
Game_Event initialize
Game_Event setup
Game_Map refresh
Game_Map setup_events
Game_Map update_events
Spriteset_Map update_characters
=end

module GameBaker
  AntiLagDisable = 0
  AntiLagModifierX = 408
  AntiLagModifierWidth = 272
  AntiLagModifierY = 272
  AntiLagModifierHeight = 408
  AntiLagAlwaysMove = '&'
end

#==========================================================================
#
# To check for updates or find more scripts, visit:
#       http://www.gamebaker.com/rmvx/scripts/
# Our RMXP scripts: http://www.gamebaker.com/rmxp/scripts/
#
# This script is not exclusive to our site!
# Feel free to pass around as long as you leave the links here.
# A license is required for commercial use, see instructions below.
#
# Instructions: http://www.gamebaker.com/rmvx/scripts/e/anti-event-lag.php
# Discussion/Help: http://forums.gamebaker.com/showthread.php?t=1242
#
#==========================================================================

class Game_CommonEvent
  alias gamebaker_antilag_commonrefresh refresh
  def refresh
    gamebaker_antilag_commonrefresh
    gamebaker_antilag_add if @interpreter
    gamebaker_antilag_remove if !@interpreter
  end
 
  def gamebaker_antilag_remove
    return if !$game_map.gb_antilagcommons.include?(@common_event_id)
    $game_map.gb_antilagcommons -= [@common_event_id]
  end
 
  def gamebaker_antilag_add
    return if $game_map.gb_antilagcommons.include?(@common_event_id)
    $game_map.gb_antilagcommons += [@common_event_id]
  end
end

class Game_Event
  def force_move_route(move_route)
    super(move_route)
    if $game_map.gb_antilagnonmove.include?(@id)
      $game_map.gb_antilagnonmove -= [@id]
      $game_map.gb_antilagmoveevents += [@id]
    end
  end 
 
  alias gamebaker_antilag_init initialize
  def initialize(map_id, event)
    gamebaker_antilag_init(map_id, event)
    if event.name.include?(GameBaker::AntiLagAlwaysMove)
      $game_map.gb_antilagmove += [@id]
    end
  end
 
  alias gamebaker_antilag_evsetup setup
  def setup(new_page)
    gamebaker_antilag_evsetup(new_page)
    if @trigger == 3 or @trigger == 4
      start if @trigger == 3
      if !$game_map.gb_antilagprocess.include?(@id)
        $game_map.gb_antilagprocess += [@id]
      end
    elsif $game_map.gb_antilagprocess.include?(@id)
      $game_map.gb_antilagprocess -= [@id]
    end
    if @character_name == "" && @tile_id == 0
      if !$game_map.gb_antilagnosprite.include?(@id)
        $game_map.gb_antilagnosprite += [@id]
      end
    elsif $game_map.gb_antilagnosprite.include?(@id)
      $game_map.gb_antilagnosprite -= [@id]
    end
    if @move_type == 0 && !@step_anime &&
      !$game_map.gb_antilagnonmove.include?(@id)
      $game_map.gb_antilagnonmove += [@id]
    elsif $game_map.gb_antilagnonmove.include?(@id)
      $game_map.gb_antilagnonmove -= [@id]
    end
  end
 
  def gamebaker_antilag_interupdate
    if @interpreter != nil
      unless @interpreter.running?
        @interpreter.setup(@list, @event.id)
      end
      @interpreter.update
    end
  end
 
  def update
    super
  end
end

class Game_Map
  attr_accessor :gb_antilagcommons, :gb_antilagnonmove, :gb_antilagnosprite,
    :gb_antilagmoveevents, :gb_antilagmove, :gb_antilagprocess,
    :gb_antilagspriteevents, :gb_antilag_spriteupdate
 
  def gamebaker_antilag?(sg)
    return false if sg.real_x < @gb_antilagscreen_x or
                    sg.real_x > @gb_antilagscreen_width or
                    sg.real_y < @gb_antilagscreen_y or
                    sg.real_y > @gb_antilagscreen_height
    return true
  end
 
  alias gamebaker_antilag_setupev setup_events
  def setup_events
    gamebaker_antilag_getscreen
    @gb_antilagnonmove = []
    @gb_antilagmove = []
    @gb_antilagnosprite = []
    @gb_antilagprocess = []
    @gb_antilagcommons = [] if !@gb_antilagcommons
    gamebaker_antilag_setupev
    gamebaker_antilag_refresh_events
  end
 
  def gamebaker_antilag_getscreen
    @gb_antilagscreen_x = @display_x - GameBaker::AntiLagModifierX
    @gb_antilagscreen_y = @display_y - GameBaker::AntiLagModifierY
    @gb_antilagscreen_width =
      @display_x + (Graphics.width * 8) + GameBaker::AntiLagModifierWidth
    @gb_antilagscreen_height =
      @display_y + (Graphics.height * 8) + GameBaker::AntiLagModifierHeight
  end
 
  def gamebaker_antilag_refresh_events
    @gb_antilagalwaysmove = []
    @gb_antilagmoveevents = []
    @gb_antilagspriteevents = []
    for i in @events.values
      next if @gb_antilagnosprite.include?(i)
      @gb_antilagspriteevents += [i]
    end
    @gb_antilagspriteevents += [$game_player]
    for vehicle in $game_map.vehicles
      next if vehicle.map_id != @map_id
      @gb_antilagspriteevents += [vehicle]
    end
    for i in 0...@gb_antilagmove.size
      @gb_antilagalwaysmove += [@events[@gb_antilagmove[i]].id]
    end
    for i in @events.values
      next if @gb_antilagnonmove.include?(i.id)
      next if @gb_antilagmove.include?(i.id)
      @gb_antilagmoveevents += [i.id]
    end
    @gb_antilag_spriteupdate = true
  end
 
  alias gamebaker_antilag_ue update_events
  def update_events
    return gamebaker_antilag_ue if $game_switches[GameBaker::AntiLagDisable]
    gamebaker_antilag_getscreen
    for i in 0...@gb_antilagprocess.size
      @events[@gb_antilagprocess[i]].gamebaker_antilag_interupdate
    end
    for i in 0...@gb_antilagalwaysmove.size
      @events[@gb_antilagalwaysmove[i]].update
    end
    for i in 0...@gb_antilagmoveevents.size
      j = @gb_antilagmoveevents[i]
      @events[j].update if gamebaker_antilag?(@events[j])
    end
    for i in 0...@gb_antilagcommons.size
      @common_events[@gb_antilagcommons[i]].update
    end
  end
 
  alias gamebaker_antilag_maprefresh refresh
  def refresh
    gamebaker_antilag_maprefresh
    gamebaker_antilag_refresh_events
  end
end

class Game_Vehicle; attr_accessor :map_id; end

class Spriteset_Map
  def gamebaker_antilag_characters
    @gb_antilag_eventsprites = []
    for sprite in @character_sprites
      next if !$game_map.gb_antilagspriteevents.include?(sprite.character)
      @gb_antilag_eventsprites += [sprite]
    end
    $game_map.gb_antilag_spriteupdate = nil
  end
 
  alias gamebaker_antilag_uc update_characters
  def update_characters
    return gamebaker_antilag_uc if $game_switches[GameBaker::AntiLagDisable]
    gamebaker_antilag_characters if $game_map.gb_antilag_spriteupdate
    for sprite in @gb_antilag_eventsprites
      sprite.update if $game_map.gamebaker_antilag?(sprite.character)
    end
  end
end

#==========================================================================
# End of file! You can find more of our scripts at http://www.gamebaker.com
#==========================================================================

Or this snippet
Ruby:
################
#AntiLag
################
    module AntiLag
      SPC = Win32API.new("kernel32", "SetPriorityClass", "pi", "i")
      @@high_priority = false
      def self.high_priority ; @@high_priority; end
      def self.high_priority?; @@high_priority; end
      def self.high_priority=(valor)
        return if @@high_priority == valor
        @@high_priority = valor
        if @@high_priority
          SPC.call(-1, 0x80)
          return
        end
        SPC.call(-1, 0x20)
      end
    end
    AntiLag.high_priority = true
First of all - thank you so much for taking your time to take a look at this problem! I really appreciate it. 🙏

Sooo, I tried using the codes you posted and that's what I found out:

Unfortunately, the snippet isn't too helpful in my case since the lag I'm dealing with is caused by a massive amount of events on a huge map. As far as I can tell, stopping the events outside of the screen from updating might be the way to go. I tried the snippet out nonetheless and as I feared, it really didn't reduce lag.
Next up - Gamebaker. It looks very promising, especially because I can simply turn off the script to get rid of the visual issues on outside maps. However, Gamebaker seems to trigger a lot of other issues. I'm still trying to discover what causes these issues. Just to get some idea what issues I'm talking about:
- teleporting to another spot on the same map sometimes triggers a game crashing NoMethodError on line 252: undefined method `each'
- I also came across instances in which it didn't show the error when teleporting and just freezed on a black screen
- sometimes, events can move over unpassable tiles

Maybe there are more errors I didn't encounter yet and as I said, I'm still in the process of figuring out the exact causes. I only know for sure that when using Anaryus script, I don't come across these issues, which makes me wonder whether it's possible to add a disable switch to Anaryu's script, similar to Gamebaker.
Is it doable?
when using Anaryus script, I don't come across these issues,
Which makes me think you have more in you project that is correcting the issues with Anaryus's script.

In the demo you provided try walking around on top of everything. The player was able to move anywhere.
I did not get that with Gamebaker(sandgolem) script.

As for the transport to the same map,
adding one line fixes it.
After line 210 249 def update_characters - add this
Ruby:
    gamebaker_antilag_characters if @gb_antilag_eventsprites.nil?

events can move over unpassable tiles
Do you have through on for the event?
Oh, that's weird! When I'm playing the demo I posted, it's really just the visual errors that seem out of the ordinary. Passability seems A-OK for me. The player is only able to move on top of everything (except for water, for whatever reason) when putting the anti-lag script before every other script in the materials section. Now I'm a bit afraid that everything that seems to work in my project is actually f'ed up for other players. Oh my...

On the bright side, the added line works! At least the game doesn't crash anymore. In my project, teleportation still freezes on a black screens sometimes. I removed every custom script except Gamebaker and it still didn't get better. However, somehow I can't recreate this issue in the demo... I don't know why my game's so weird. But disabling Gamebaker while teleporting and enabling it directly after works like a charm, so doing that in every teleport event should be totally fine. (Edit: I think I figured out where the problem lies: The teleport events that freeze are also in charge of moveroutes for events that are placed out of the screen. Putting a & in the name of these events seems to settle it, but I'll continue testing nonetheless.)
I think I even managed to get rid of the events moving over unpassable tiles, so I don't think you have to worry about it anymore.

Thank you soooo much for all your help, I can't put in words how happy I am!

I will quickly change my teleport events and look whether I'll stumble across other bugs. But I'm really hopeful that everything will work out. I'll write if something stopped working after changing the anti-lag script. 😍

Again - thank you so much ♥

Original thread: https://forums.rpgmakerweb.com/threads/vx-compatibility-patch-or-enabling-disabling-script-with-switch-visual-issues.131635/