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.
Introduction
If you are looking for an anti-lag script that will keep your FPS at 100% most of the time, this is the script for you.

This script eradicates redundancies and erroneous materials that were in previously created anti-lag scripts. Your game should be 40% faster than it was when you were using the other anti-lag scripts.

This script is not for beginners. To achieve good anti-lag, you're going to need to modify your base Game_Map and Spriteset_Map classes. This is not an SDK script and it requires fewer lines of code to implement.

This script is an optimization of Near's, sandgolem's, and Helmut's anti-lag scripts. I created this because each of these scripts has great stuff, but none of them really fixed the anti-lag problem completely.

Ready to get started? Let's make your game faster!

Update Game_Map
1. Open your game and script editor.

2. In Game_Map, in the update method (def update), replace the following line with the code snippet below.

Replace this:
for event in @events.values
event.update
end


With this:
Code:
    for event in @events.values
      if in_range?(event) or event.trigger == 3 or event.trigger == 4
        event.update
      end
    end

3. 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)
Code:
  #--------------------------------------------------------------------------
  # ● 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


Update Spriteset_Map

1. In Spriteset_Map, in the update method (def update), replace the following line with the code snippet below.

Replace this:
for sprite in @character_sprites
sprite.update
end


With this:
Code:
    for sprite in @character_sprites
      if in_range?(sprite.character)
        sprite.update
      end 
    end

3. 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)
Code:
  #--------------------------------------------------------------------------
  # ● 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

Credits
If any credit should be given, send it to Near, sandgolem, and Helmut. They got this ball rolling.
 
By What i have seen this is A very well done script, but you could aliased the methods, making it easier to other people to implement this.But keep Going!
 
True, but I found that by putting these directly in the base classes, that a game runs faster. Hey, maybe you could post an aliased version? (I'm not really familiar with how to do it) :)
 

Anonymous

Guest

This I must say is alot more simple and i like it welldone and goodwork ;)
 
Very good lampchop ^_^ Aliasing the script would make it more "universal" though, but still, this was very smart. Amazing. I'm one of the first to congragulate you and well done to Near, SG, and Helmut, and especially you for implementing the scripts ^_^
 
Lol, every script you did I've seen so far is like 'here ya go with the crap, make it better' :P (well, it's the same for me, thinking of I have only one released script and Trickster made the difficult part ^_^ )

For the script itself, you should add a switch that turns it on and off, or - even better - a game_variable that defines the range and disables everything from this script if set to 0. The purpose, you ask? Several people might want to have synchronized events, and if one event get updated and the other one doesn't, that's no good, actually... (I could do this by myself, but I'm too tired ATM ^_^ )

I'll try this if an updated or deactivateable version is out... :P
 
mh.. what exactly is different between this script and the old anti lag scripts? As far as I can see this script only checks if a character_sprite / event is on the screen or not..

like the other script's editors you also seem to have forgotten that some events need to be updated event if they're not on the screen anymore (e.g. autostart events, etc)
to prevent this you could add a possibility to tell the script somehow if an event shall be updated everytime (e.g. via a comment)

well thats it.. beside that the script works fine :)

-f0tz!
 
lambchop said:
True, but I found that by putting these directly in the base classes, that a game runs faster.
Thats not true, it doesn't matter. The old methods are replaced with the new method that is under the old class.

Also, this does the exact same thing as the other ones, which is;
- Stop Updating Events and Sprites

And other then what f0tz!baerchen too, its fine.
 
f0tz!baerchen said:
mh.. what exactly is different between this script and the old anti lag scripts? As far as I can see this script only checks if a character_sprite / event is on the screen or not..

like the other script's editors you also seem to have forgotten that some events need to be updated event if they're not on the screen anymore (e.g. autostart events, etc)
to prevent this you could add a possibility to tell the script somehow if an event shall be updated everytime (e.g. via a comment)

well thats it.. beside that the script works fine :)

-f0tz!

I updated the Game_Map event to recognize parallel and auto processes. I don't think that the Spriteset_Map needs these additional triggers. If I'm wrong let me know!

I also updated the script. It's even smaller now!
 
lambchop said:
If any credit should be given, send it to Near, sandgolem, and Helmut
No credit please :)

I only did a few minor optimizations to Near's SDK script. Nice to see another version for people that aren't using the SDK, and editing it into scripts themselves will help increase compatibility. For someone who asked why it isn't aliased, this part of the script needs to be rewritten. Aliasing only adds things before or after other scripts.

There are a few tiny issues with not including the triggers in Spriteset_Map, but I don't think anyone at all uses the problematic stuff. Definetely not things people would usually do :)
 
Heh, I just tried aliasing the script, and I realised that if you do alias it, then it checks if the event is on the screen, and the old update is still there. So it is pretty much the same thing as adding the lines to def update. Eh, oh well. Anyways, small and simple script, but powerful results. Good job ^^
 
Well, I think the lagging thing is something that should have been ceased in the first place... I mean, on 'normal' PCs that time, even 10 PP events on a map made it lag... they just failed programming an interpreter that's capable of handling the Delphi-RGSS-inbetweenation thingy XD
 
sirsk8aton said:
Yeah, I was thinking the same thing :P
I'm hoping that the next version of RMXP is going to have fixes for things like this. *crosses fingers that another one is coming and in English!*
 
well I think the main problem is the Sprite Class.. it doesnt matter if there are events or other sprites, if they're too many or too big it starts lagging..

so real Anti-Lag had to change the Sprite class itself (although this script still does a quite good job) ^^

-f0tz!
 
hmmm, i don't like the aliased defs too.
Because when u have too many aliased scripts, u don't have the overview of the methods, cause they're spread everywhere.
and when u have more than 1 same-called-defs, it might be possible that it occurs an error, because of the incompatibility.
...by the way...nice script and thanks :D
 
C'mon man, this is so simple to copy-paste that if you can't do it by yourself, you won't ever get anything inside your game you need the script for ^_^
 
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