WIP: Looping Map Script for XP (Cant get Sprites to Loop)

Heretic86

Veteran
Veteran
Joined
Nov 30, 2014
Messages
240
Reaction score
167
First Language
Engrish
Primarily Uses
Yay, another script in the works!   :naughty:  Im hoping this forum is a bit more active...

What I want this script to do is to Loop the Map like is possible in VX / Ace, but I dont have copies of either, which doesnt help.  So far, the Map does loop, Passable works, Fogs and Panoramas (mostly) seem to work, but I dont think Im doing that quite right either.  Where Im stuck is getting Events that are close to Map Edges do not display at all times because the Player is repositioned.  Im not sure how they pulled it off in VX / Ace.  I could be going about this totally wrong as well and correcting positions at the wrong time.  Events need to be able to display consistently, so Im thinking maybe some sort of adjustment either to Sprites, or screen_x and screen_y?

Oh, and to add to the complexity, Im also hoping to have this script compatible with ANY form of Anti Lag script where Sprites dont get updated if they are not close to the screen.  I havent even touched the Anti Lag part of it yet.  Some assistance here is requested...  Im fine with a collaboration script where any who put any effort into this are also titled as Authors.

Anyway, here is the script:

# This script is NOT intended for use or distribution.  It has BUGS and will# not work in its present form as expected.  This is what I need a bit# of assistance with!  Panoramas and Fogs dont work quite right, and# Events close to Map Edges are not always displayed when Map is Looped.## - Heretic# Map ID - Obvious# Loop Type:#   0 - No Looping (Normal Maps and Collisions#   1 - Vertical Loop, no Horizontal#   2 - Horizontal Loop, no Vertical#   3 - Loop Horizontal and Vertical# ConfigLOOP_MAPS = [ [map_id = 1, loop_type = 3] ]# End Configclass Game_Map  #--------------------------------------------------------------------------  # * Public Instance Variables - Game_Map  #--------------------------------------------------------------------------  attr_accessor    :loop_type   # 0: Off, 1: Vertical, 2: Horizontal, 3: Both  attr_accessor    :fog_ox      # Fog Origin X  attr_accessor    :fog_oy      # Fog Origin Y  attr_accessor    :loop_pan_x  # Panorama Adjustment when Looping Horizontal  attr_accessor    :loop_pan_y  # Panorama Adjustment when Looping Vertical  #--------------------------------------------------------------------------  # * Setup - Game_Map  #     map_id : Map ID  #--------------------------------------------------------------------------  alias loop_map_setup setup unless $@  def setup(map_id)    # Set the Default Loop Type    @loop_type = 0    # Panorama Adjustments for Looping    @loop_pan_x = 0    @loop_pan_y = 0    # If Config has Looping Map    for loops in LOOP_MAPS      # Set Loop Type based on Config      @loop_type = loops[1] if loops[0] == map_id    end    # Call Original or other Aliases of Setup    loop_map_setup(map_id)  end  #--------------------------------------------------------------------------  # * Loop Horizontally? - Game_Map  #--------------------------------------------------------------------------  def loop_horizontal?    @loop_type > 1  end  #--------------------------------------------------------------------------  # * Loop Vertically? - Game_Map  #--------------------------------------------------------------------------  def loop_vertical?    @loop_type == 1 or @loop_type == 3  end  #--------------------------------------------------------------------------  # * Valid? - Game_Map  #  - Adjusts X and Y values for Looping Maps  #--------------------------------------------------------------------------  alias map_loop_valid? valid? unless $@  def valid?(x, y)    # Fix X Value to Map Range if Map Loops Horizontally    x %= @map.width if loop_horizontal?    # Fix Y Value to Map Range if Map Loops Vertically    y %= @map.height if loop_vertical?    # Call Original or other Aliases    map_loop_valid?(x, y)  end  #--------------------------------------------------------------------------  # * Passable? - Game_Map  #  - Adjusts X and Y values for Looping Maps  #--------------------------------------------------------------------------  alias map_loop_passable? passable? unless $@  def passable?(x, y, d, self_event = nil)    # Fix X Value to Map Range if Map Loops Horizontally    x %= @map.width if loop_horizontal?    # Fix Y Value to Map Range if Map Loops Vertically    y %= @map.height if loop_vertical?    # Call Original or other Aliases with updated X and Y    map_loop_passable?(x, y, d, self_event)  end  #--------------------------------------------------------------------------  # * Scroll Down  #     distance : scroll distance  #--------------------------------------------------------------------------  alias map_loop_scroll_down scroll_down unless $@  def scroll_down(distance)    # If Map Loops Vertically    if loop_vertical?      # Update Display with no Limiters      @display_y += distance    else      # Call Original or other Aliases      map_loop_scroll_down(distance)    end  end  #--------------------------------------------------------------------------  # * Scroll Left  #     distance : scroll distance  #--------------------------------------------------------------------------  alias map_loop_scroll_left scroll_left unless $@  def scroll_left(distance)    # If Map Loops Horizontal    if loop_horizontal?      # Update Display with no Limiters      @display_x -= distance    else      # Call Original or other Aliases      map_loop_scroll_left(distance)    end  end  #--------------------------------------------------------------------------  # * Scroll Right  #     distance : scroll distance  #--------------------------------------------------------------------------  alias map_loop_scroll_right scroll_right unless $@  def scroll_right(distance)    # If Map Loops Horizontal    if loop_horizontal?      @display_x += distance    else      # Call Original or other Aliases      map_loop_scroll_right(distance)    end  end  #--------------------------------------------------------------------------  # * Scroll Up  #     distance : scroll distance  #--------------------------------------------------------------------------  alias map_loop_scroll_up scroll_up unless $@  def scroll_up(distance)    # If Map Loops Vertically    if loop_vertical?      @display_y -= distance    else      # Call Original or other Aliases      map_loop_scroll_up(distance)    end  endendclass Spriteset_Map  #--------------------------------------------------------------------------  # * Update - Spriteset_Map  #  - Adjusts Panorama Position on Looping Maps  #--------------------------------------------------------------------------   alias loop_map_update update unless $@  def update    # Call Original or other Aliases    loop_map_update    # Clear Fog Looping Flags    @panorama.ox += $game_map.loop_pan_x    @panorama.oy += $game_map.loop_pan_y  endendclass Game_Event  #--------------------------------------------------------------------------  # * Determine if Near Visible Area of Screen - VXA  #     dx:  A certain number of tiles left/right of screen's center  #     dy:  A certain number of tiles above/below screen's center  #--------------------------------------------------------------------------  def near_the_screen?(dx = 12, dy = 8)    ax = $game_map.adjust_x(@real_x) - Graphics.width / 2 / 32    ay = $game_map.adjust_y(@real_y) - Graphics.height / 2 / 32    ax >= -dx && ax <= dx && ay >= -dy && ay <= dy  end  #--------------------------------------------------------------------------  # * Map Loop Position - Game_Player  #  - Calls for Corrections when Player triggers a Map Loop  #--------------------------------------------------------------------------   def event_map_loop_position    return unless $game_map.loop_type > 0 and (moving? or jumping?)    # If Horizontal Map Loop    if $game_map.loop_horizontal?      # Correct Positions if outside Map Boundaries      if @real_x < 0 or @real_x > $game_map.width * 128        # Fix Event's Position        @x %= $game_map.width        @real_x %= $game_map.width * 128             end    end    # If Horizontal Map Loop    if $game_map.loop_vertical?      # Correct Positions if outside Map Boundaries      if @real_y < 0 or @real_y > $game_map.height * 128        # Fix Event's Position        @y %= $game_map.height        @real_y %= $game_map.height * 128             end    end     end   #--------------------------------------------------------------------------  # * Update - Game_Event  #--------------------------------------------------------------------------  alias map_loop_update update unless $@  def update    # Call Original or other Aliases    map_loop_update    # Update Map Loop Positions    event_map_loop_position  end endclass Game_Player  #--------------------------------------------------------------------------  # * Set Map Display Position to Center of Screen - Game_Player  #--------------------------------------------------------------------------  alias loop_map_center center unless $@  def center(x, y)    # Call Original or other Aliases    loop_map_center(x, y)       # Recenter Display Horizontally if Map Loops Horizontal    $game_map.display_x = x * 128 - CENTER_X if $game_map.loop_horizontal?    # Recenter Display Vertically if Map Loops Vertical    $game_map.display_y = y * 128 - CENTER_Y if $game_map.loop_vertical?  end  #--------------------------------------------------------------------------  # * Correct Loop Left - Game_Player  #  - Corrects Player Coordinates, Fogs, and Panoramas on a Map Loop  #--------------------------------------------------------------------------    def correct_loop_left    fog_ox = $game_map.fog_ox    # Fix Player's Position    @x %= $game_map.width    @real_x %= $game_map.width * 128    # Correct Map Display    $game_map.display_x %= $game_map.width * 128    # Correct Fog Display    $game_map.fog_ox -= $game_map.width * 32    $game_map.fog_ox %= $game_map.width * 128    # Correct Panorama Display    $game_map.loop_pan_x -= $game_map.width * 16  end  #--------------------------------------------------------------------------  # * Correct Loop Right - Game_Player  #  - Corrects Player Coordinates, Fogs, and Panoramas on a Map Loop  #--------------------------------------------------------------------------    def correct_loop_right    # Fix Player's Position    @x %= $game_map.width    @real_x %= $game_map.width * 128    # Correct Map Display    $game_map.display_x %= @real_x - $game_map.width * 128 - 2 ** @move_speed    # Correct Fog Display    $game_map.fog_ox += $game_map.width * 32    $game_map.fog_ox %= $game_map.width * 128    # Correct Panorama Display    $game_map.loop_pan_x += $game_map.width * 16  end  #--------------------------------------------------------------------------  # * Correct Loop Up - Game_Player  #  - Corrects Player Coordinates, Fogs, and Panoramas on a Map Loop  #--------------------------------------------------------------------------    def correct_loop_up    # Fix Player's Position    @y %= $game_map.height    @real_y %= $game_map.height * 128    # Correct Map Display    $game_map.display_y %= $game_map.height * 128    # Correct Fog Display    $game_map.fog_oy -= $game_map.height * 32    # Correct Panorama Display    $game_map.loop_pan_y -= $game_map.height * 16  end  #--------------------------------------------------------------------------  # * Correct Loop Down - Game_Player  #  - Corrects Player Coordinates, Fogs, and Panoramas on a Map Loop  #--------------------------------------------------------------------------   def correct_loop_down    # Fix Player's Position    @y %= $game_map.height    @real_y %= $game_map.height * 128    # Correct Map Display    $game_map.display_y %= @real_y - $game_map.height * 128 - 2 ** @move_speed    # Correct Fog Display    $game_map.fog_oy += $game_map.height * 32    # Correct Panorama Display    $game_map.loop_pan_y += $game_map.height * 16     end  #--------------------------------------------------------------------------  # * Map Loop Position - Game_Player  #  - Calls for Corrections when Player triggers a Map Loop  #--------------------------------------------------------------------------   def map_loop_position    return unless $game_map.loop_type > 0 and (moving? or jumping?)    # If Horizontal Map Loop    if $game_map.loop_horizontal?      # Correct Positions if outside Map Boundaries      correct_loop_left if @real_x < 0      correct_loop_right if @real_x > $game_map.width * 128    end    # If Horizontal Map Loop    if $game_map.loop_vertical?      # Correct Positions if outside Map Boundaries      correct_loop_up if @real_y < 0      correct_loop_down if @real_y > $game_map.height * 128    end     end  #--------------------------------------------------------------------------  # * Update - Game_Player  #--------------------------------------------------------------------------  alias map_loop_update update unless $@  def update    # Call Original or other Aliases    map_loop_update    # Update Map Loop Positions    map_loop_position  endend
Feel free to replace the existing code in here if you'd like!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Do you particularly WANT to write your own? I'd be surprised if there weren't map looping scripts out there for XP already.
 

Heretic86

Veteran
Veteran
Joined
Nov 30, 2014
Messages
240
Reaction score
167
First Language
Engrish
Primarily Uses
Yes, I particularly DO want to write my own.  I am interested in seeing how others achieved the same thing, but it isnt the point.  If I just let everyone else build everything, then I dont learn anything for myself.  How many Pendulum Scripts have you seen?  Probably not many that I know of.  And being able to build these things for myself is exactly the point.
 

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
Hello Heretic! Nice to meet you. Here's some code based on the way Ace does it:

class Game_Map def adjust_x(x) # Display X in "tile values". dx = @display_x / 128.0 # 20 represents the number of horizontal tiles in the screen. return x - dx + @map.width if loop_horizontal? && x < dx - (width - 20) / 2 x - dx end def adjust_y(y) # Display Y in "tile values". dy = @display_y / 128.0 # 15 represents the number of vertical tiles in the screen. return y - dy + @map.height if loop_vertical? && y < dy - (height - 15) / 2 y - dy endendclass Game_Character def screen_x $game_map.adjust_x(@real_x / 128.0) * 32 + 16 end def screen_y shift_y = (@tile_id > 0 || @character_name[0, 1] == '!') ? 0 : 4 height = (@jump_peak * @jump_peak - (@jump_count - @jump_peak).abs ** 2) / 2 $game_map.adjust_y(@real_y / 128.0) * 32 + 32 - shift_y - height end endclass Game_Event def event_map_loop_position # No need for this method anymore. end end
Oh, and to add to the complexity, Im also hoping to have this script compatible with ANY form of Anti Lag script where Sprites dont get updated if they are not close to the screen.  I havent even touched the Anti Lag part of it yet.  Some assistance here is requested...  Im fine with a collaboration script where any who put any effort into this are also titled as Authors.
Compatibility with other anti lag scripts depends on the method used by other anti lag scripts to know if the events are visible (since most of them just do the "don't touch if it is not visible" thing). If those scripts were not made with compatibility with loop maps in mind, there could be a problem when the camera is focusing on the borders of the map. I'm not sure if there is much you can do about it (unless you want to patch all existing anti lag scripts).

Cheers.
 
Last edited by a moderator:

Heretic86

Veteran
Veteran
Joined
Nov 30, 2014
Messages
240
Reaction score
167
First Language
Engrish
Primarily Uses
Are the values in Ace different than XP?  Trying to just replace (experimenting) screen_x / y and tossing in adjust_x / y into Game Map doesnt cause the adjustments to trigger in the if statements.  XP is 640 x 480 and Ace is 544 x 416?  How does that work?  I thought they'd be the same excluding higher resolution scripts, but apparently not?

Im not too worried about all anti lag scripts, only my own, and I'll fix that once I get my head wrapped around this.  XP seems to be very inefficient in the way it handles displaying graphics.  It seems to render sprites when they are off the screen and by preventing offscreen sprites from processing graphics yeilds pretty good performance increases.

I appreciate the assistance.  Its a lot more welcoming than "go google someone elses script and dont bother to learn" (no offense Shaz, but thats the way you came across).
 

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
Are the values in Ace different than XP?  Trying to just replace (experimenting) screen_x / y and tossing in adjust_x / y into Game Map doesnt cause the adjustments to trigger in the if statements.  XP is 640 x 480 and Ace is 544 x 416?  How does that work?  I thought they'd be the same excluding higher resolution scripts, but apparently not?
What do you mean? The code I provided should be pasted below your code. It works without editing anything.

Yes, Ace uses "tile" values for real_x and display_x, so the number of screen tiles (horizontally and vertically) is taken in consideration in display_x/y methods to decide the correct value in case the map loops (apparently just dividing XP's by 128 does the trick).

I included a replace (empty) for event_map_loop_position since that method would interfere with the other additions.

Maybe I didn't understand your message, let me know if you need more help or if you have more questions.
 

Heretic86

Veteran
Veteran
Joined
Nov 30, 2014
Messages
240
Reaction score
167
First Language
Engrish
Primarily Uses
Okay, that makes more sense. I thought that was relevant source code from Ace and didnt catch on that you had already adjusted it for XP.  My bad.  It does work when the player is close to the right edge of the map and an event is at the far left edge, however, the inverse doesnt work where the player is close to the left edge of the map and an event is on the right edge of the map.  I'll play with it unless you have a more efficient solution...

Im also confused by this line:

shift_y = (@tile_id > 0 || @character_name[0, 1] == '!') ? 0 : 4Events with a "!" in the name "001-Fighter01" are shifted?  Is that something unique to Ace?  What for?  I do remember that "$" file names use 4 rows for animation instead of 3 for VX, just not sure where this comes into play...
 

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
Okay, that makes more sense. I thought that was relevant source code from Ace and didnt catch on that you had already adjusted it for XP.  My bad.  It does work when the player is close to the right edge of the map and an event is at the far left edge, however, the inverse doesnt work where the player is close to the left edge of the map and an event is on the right edge of the map.  I'll play with it unless you have a more efficient solution...
I think that could have something to do with how you do the map loop, check the display_x/y values.

Im also confused by this line:

shift_y = (@tile_id > 0 || @character_name[0, 1] == '!') ? 0 : 4Events with a "!" in the name "001-Fighter01" are shifted?  Is that something unique to Ace?  What for?  I do remember that "$" file names use 4 rows for animation instead of 3 for VX, just not sure where this comes into play...
This is from the help file of Ace:

  • Adding an exclamation point (!) to the beginning of a file name cancels the application of the four-pixel offset, and also turns off the translucent effect applied by the bush attribute. This is used mainly for object-type characters on maps, such as doors and treasure chests. It can also be used in combination with the dollar sign ($) special character. 
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Yes, I particularly DO want to write my own.  I am interested in seeing how others achieved the same thing, but it isnt the point.  If I just let everyone else build everything, then I dont learn anything for myself.  How many Pendulum Scripts have you seen?  Probably not many that I know of.  And being able to build these things for myself is exactly the point.
That's alright - no need to get worked up about it. If everybody only ever wrote their own scripts, a lot of games would take a lot longer to make, and a lot would never be completed. I was simply curious whether you were more interested in getting it working (in which case an existing script would do the job) or in doing it yourself. You didn't say, so I had to ask. If you WERE only interested in getting it running, and we went through the whole process of helping you with the script, you (and we) would have wasted a heap of time ;)
 

Heretic86

Veteran
Veteran
Joined
Nov 30, 2014
Messages
240
Reaction score
167
First Language
Engrish
Primarily Uses
It was the X / Y values.  Had to change it a bit tho.

  def adjust_x(x, id =nil)    # Display X in "tile values".    dx = @display_x / 128.0    # 20 represents the number of horizontal tiles in the screen.    if loop_horizontal?      # If Map Loop to the Right and Character close to Left Edge      return x - dx + @map.width if x < dx - (width - 20) / 2      # If Map Loop to the Left and Character close to Right Edge      return x - dx - @map.width if dx < 0 and x > 10    end    x - dx  end
I feel like a dumb dumb for not seeing that.  :p

Still a bit off when an event is at the top of the map and player is close to the bottom.  Probably screen Z this time, but eating now, so I'll take another look in a short while...  Ugh, so much to do.  Once I get this finished, still need to tie this into a Vehicle script, which I am doing my damnest to make superior in every way possible to the other piss poor vehicle scripts for XP that I've run into.
 

Heretic86

Veteran
Veteran
Joined
Nov 30, 2014
Messages
240
Reaction score
167
First Language
Engrish
Primarily Uses
Bump.. (If thats alright, browser trouble, I cant edit posts, not sure why but I'll work on that too, otherwise I'd edit over a bump, sorry)

Is it possible to make sure passable works as expected without replacing the passable definitions?  Game_Character passable determines new_x and new_y inside the method which makes a simple alias not seem plausible. 

I resolves several of the other issues, and need to work on Triggers now, yay, but more curious about Passable methods...
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Heretic86, please do not bump your topic unless it has been 72 hours later since your last post. You can review our forum rules here. Thank you.


If it hasn't been 3 days and yours is the last post, you either need to wait until the bump time has passed, or just edit your last post and add the extra info. If it's not urgent, it's better to wait, as editing your post and adding new info won't bring it up as 'new' for people to see.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,083
Members
137,583
Latest member
write2dgray
Top