Shaz Large Collision script

So I'm using Shaz's large collision script and it has been a lifesaver. I'm doing events that require dynamically determined collision, and it's cut out 100+ events from some of my maps, which took them from unplayable to totally manageable.

Overall the script is great, but there's a bit of problem and I'm wondering if it would be easy to fix. The input for the script is a comment with integer arguments for width and height. Arguments are for the number of pixels that the object's collision should span, not tiles. Since there are 32 pixels per tile, a collision argument of 32,32 corresponds to collision one tile wide. 32,64 means one tile long and two tiles high, 64,64 is a 2x2 square, etc.

The issue is that a width argument for an even number of tiles creates an odd number of colliding tiles. IE, an argument of 64 creates collision three tiles wide, an argument of 128 creates file tiles, etc. Height arguments work correctly for both even and odd. Here's the script:

class Game_Event < Game_Character  alias shaz_large_event_collision_clear_page_settings clear_page_settings  alias shaz_large_event_collision_setup_page_settings setup_page_settings  def clear_page_settings    shaz_large_event_collision_clear_page_settings    @collide_width = 0    @collide_height = 0  end  def setup_page_settings    shaz_large_event_collision_setup_page_settings    @collide_width = 0    @collide_height = 0    list_index = 0    while list_index < @list.size && [108,408].include?(@list[list_index].code)      colx, coly = @list[list_index].parameters[0].scan(/<collision: (\d+),(\d+)>/i)[0]      @collide_width = colx.nil? ? 0 : (colx.to_i / 64)      @collide_height = coly.nil? ? 0 : (coly.to_i / 32 - 1)      list_index = @list.size if @collide_width != 32 || @collide_height != 32      list_index += 1    end  end  def pos?(x,y)    x.between?(@x - @collide_width, @x + @collide_width) &&      y.between?(@y - @collide_height, @y)  endendIn any case, thanks for the script Shaz. Lifesaver.

I've also got a second question I might as well throw in here. Is any extra processing required for events that have walking animation checked, but movement set to fixed? I have thousands of blank events on various maps that are set this way, and many of these maps have so many events that they are starting to suffer reduced framerates. Would it be worthwhile to uncheck walking animation on all these (we're talking hours of monotony), or is that condition not even going to be checked for an event whose graphic is set to none and has movement set to fixed?
I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.


The reason for the odd number of tiles is that the area is centered on the tile the event was placed on. If you have a two-tile-wide sprite, it will take up that event's tile as well as the tile on the left and on the right. Hence 3 tiles.


The event question is unrelated and should go into its own thread in VX Ace Support. But do you mean walking animation or stepping animation? If you really mean stepping animation, see if they are set to parallel process - they shouldn't be, unless you actually have commands that you want run. If you need more help, please post a screenshot of one of those events - in a new thread in the correct place. And also indicate how many of these events you have on the maps. There are other causes of lagging, and unless you have an enormous number of events, I'd look at other possibilities too.
Hey, thanks for the script. It's very helpful the way it is, I was just hoping to shave off some more events on each map. I'm doing dynamically generated towns, so there are 100+ events on each map to create dynamic collision. They're playable at the moment, thanks to your script, but I can't add much more. I did some testing, and at 120 events the framerate starts dropping noticably. By 200 events it's a slideshow, even if the events are just freshly-created default ones. But overall I'm still happy with the towns I was able to make. I've got the cake and the icing, everything else is just sprinkles. I just thought there might be just a quick change to allow two-tile horizontal collision, since two-tile vertical collision works. But it seems that events grow left and right at the same time on the horizontal axis, whereas they only grow upward on the vertical axis, so I guess it's two very different situations.

Most of the events are basically just default: walking animation checked, no graphic, movement set to fixed, "Action button" interaction, and "Same as character" priority, with an added comment for the collision script. It just occured to me that the thousands of events I copy-pasted onto a few dozen different town maps might actually be doing some processing for the walking animation every frame, even if only to further check that movement is set to fixed and then move on. I'm really pushing processing by having so many events (some of which have a bunch of pages), so any potential optimization might be worth it. But I don't know if unchecking walking animation would even matter at all.
Here's a mod that will let you use as many tiles as you like - odd or even number.

The event needs to go in the bottom left corner. So if you have an event with <collision: 64,64> that event will cover the tile it's on as well as the one to the right, and the two above them.

class Game_Event < Game_Character alias shaz_large_event_collision_clear_page_settings clear_page_settings alias shaz_large_event_collision_setup_page_settings setup_page_settings def clear_page_settings shaz_large_event_collision_clear_page_settings @collide_width = 0 @collide_height = 0 end def setup_page_settings shaz_large_event_collision_setup_page_settings @collide_width = 0 @collide_height = 0 return if empty? @list.select{|cmd| [108,408].include?(cmd.code) && cmd.parameters[0].to_s =~ /<collision: (\d+),(\d+)/}.each {|cmd| @collide_width = $1.nil? ? 0 : ($1.to_i / 32 - 1) @collide_height = $2.nil? ? 0 : ($2.to_i / 32 - 1) } end def pos?(x,y) x.between?(@x, @x + @collide_width) && y.between?(@y - @collide_height, @y) endendOriginally I wrote this script with the size specified in pixels. I had a good reason at the time, but I can't imagine now what that would have been, and I've actually changed it long ago in my own project. Actually it might have had something to do with getting the size from the sprite itself, which was never implemented as part of the script anyway. If you already have heaps of events using the script - too many to go through and change, just use the script above. But if you're happy to change them all, the one below lets you specify how many tiles the event covers, rather than how many pixels. Anything that reduces the need to figure things out is always good 🙂 So an event that's to cover a square of 4 tiles would have <collision: 2,2> as the comment.

Code:
class Game_Event < Game_Character  alias shaz_large_event_collision_clear_page_settings clear_page_settings  alias shaz_large_event_collision_setup_page_settings setup_page_settings  def clear_page_settings    shaz_large_event_collision_clear_page_settings    @collide_width = 0    @collide_height = 0  end  def setup_page_settings    shaz_large_event_collision_setup_page_settings    @collide_width = 0    @collide_height = 0    return if empty?    @list.select{|cmd|       [108,408].include?(cmd.code) &&       cmd.parameters[0].to_s =~ /<collision: (\d+),(\d+)/}.each {|cmd|        @collide_width = $1.nil? ? 0 : ($1.to_i - 1)        @collide_height = $2.nil? ? 0 : ($2.to_i - 1)    }  end  def pos?(x,y)    x.between?(@x, @x + @collide_width) && y.between?(@y - @collide_height, @y)  endend
Thank you so much! The pixel script is great. That will save me hours of changing stuff. I have 24 different maps of 6 different towns in 4 different stages of growth with 5 different buildings that have 5 possible stages of growth, and a bunch of variable town addons as well... all with different collision requirements. so yeah, this is just awesome. Being able to add two-tile collision rather than having to use two one-tile events will cut out a bunch of events on each map, so that's just more stuff I can add.

Original thread: https://forums.rpgmakerweb.com/threads/shaz-large-collision-script.54628/