Advertisement
jesterruby

Map Edge Transfer (VX-Ace) v2.3

Feb 18th, 2013
2,549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.26 KB | None | 0 0
  1. #~ Map Edge Transfer (VX-Ace) v2.3 by Lain (formerly Jester)
  2.  
  3. #~ Version History:
  4. #~ 06.FEB.2013 -> 1.0 -> Initial Release
  5. #~ 08.FEB.2013 -> 1.1 -> Bugfixes, Syntax Overhaul, 8-dir compatibility
  6. #~ 18.FEB.2013 -> 2.0 -> More Customization and compatibility with Slide-Effect
  7. #~ 05.MAR.2013 -> 2.1 -> Compatibility improvement
  8. #~ 12.MAR.2013 -> 2.1a-> Minor optimizations
  9. #~ 15.MAR.2013 -> 2.2 -> A Script call to manually choose the transfer coordinates (Take a look at line 72 and below)
  10. #~ 15.MAR.2013 -> 2.2a -> Hotfix
  11. #~ 21.SEP.2013 -> 2.3 -> Added "Offset" Script call (Take a look at line ~100 and below)
  12.  
  13. #~ Features:
  14. #~ Automatic Map-Edge-Transfer system
  15. #~ More realistic looking transfer
  16.  
  17. #~ This Script allows the player to automatically transfer to the next
  18. #~ map when hitting the edge of the current map, using in-game variables.
  19. #~ It also adds a small feature to make it look like the player actually
  20. #~ WALKS out of the current map into the new map instead of teleporting.
  21.  
  22. #~ This Script is NOT PLUG'N'PLAY, but relatively easy to use.
  23. #~ Take a look at the Customization section.
  24. #~ If you still have problems, try out the recent Demo before asking for help!
  25.  
  26. #~ Bugs:
  27. #~ (no known issues)
  28.  
  29. #~ Conflicts:
  30. #~ Place this Script below any movement scripts, like 8-dir-movement
  31. #~ I am fine with Compatibility fix requests if you say "PLEEAASEEEE!!!"
  32.  
  33. #~ Feel free to report any Bugs and Conflicts that are not listed above.
  34. #~ I am available for feedback at rmrk.net and rpgmakervxace.net.
  35.  
  36. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  37. $jimported ||= {} #<- DON'T TOUCH ME!!!
  38. $jimported[:jms_met] = 2.3 #<- DON'T TOUCH ME!!!
  39. module JMSC # Jester Mini-Script Customization
  40.   module MET # Map Edge Transfer
  41. #~~~~~~~~~~~~~~~~~~~~~~~~~Customization~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  42.  
  43. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
  44. # Autotransfer Options:
  45.   # In-Game Variables that define the Map-ID you will transfer to, when
  46.   # hitting the Map Edge on the respective cardinal direction.
  47.   # Setting them to 0 will disable transfer for the specific Edge:
  48.     MapID_North_Variable = 21 #North
  49.     MapID_East_Variable  = 22 #East
  50.     MapID_South_Variable = 23 #South
  51.     MapID_West_Variable  = 24 #West
  52.    
  53.   # In-Game Switch to temporarely disable Map Edge Transfer:
  54.     Disable_AutoEdgeTransfer_Switch = 21
  55.    
  56.   # The default Transfer-Effect for Map Edge Transfer:
  57.   # 0 = Black
  58.   # 1 = White
  59.   # 2 = None
  60.     Fade_Type = 2
  61. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
  62.  
  63. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
  64. # Compatibility Options:
  65.   # Set to true, if you use Scripts like Pixel Movement:
  66.     New_Move_Straight = false
  67. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
  68. # END OF CUSTOMIZATION!
  69.  
  70. #~ OPTIONAL script calls:
  71. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
  72. #~ You can specifically change the transfer information with this Script call
  73. #~ (The informations will reset after transferring):
  74. #~ $game_player.jms_met_transferinfo(card, x, y, d)
  75.  
  76. #~      card = The cardinal direction you want to change the transfer info of
  77. #~             (8, 6, 4 or 2) or ("North", "East", "South" or "West")
  78.  
  79. #~      x = The x coordinates the player will transfer to
  80. #~              Can be a Integer or false (false = no change)
  81.  
  82. #~      y = The y coordinates the player will transfer to
  83. #~              Can be a Integer of false (false = no change)
  84.  
  85. #~      d = The direction (8/6/4/2) the player will face after transfer
  86. #~              (8, 6, 4 or 2) or false (false = no change)
  87.  
  88. #~    Example:
  89. #~    $game_player.jms_met_transferinfo(8, 5, false, 4)
  90. #~       Changes transfer informations for if you travel through the north
  91. #~       It will force the player to transfer to x coordinate "5"
  92. #~       The y coordinate the player will transfer to doesn't change
  93. #~       The player will face into direction "4" (which is West)
  94.  
  95.  
  96. #~ You can also add an Offset to the x or y coordinates with these script calls
  97. #~ (The informations will reset after transferring):
  98. #~ $game_player.jms_met_addoffset(card, axis, offset)
  99.  
  100. #~      card = The cardinal direction you want to add a offset to
  101. #~             (8, 6, 4 or 2) or ("North", "East", "South" or "West")
  102.  
  103. #~      axis = "x" or "y"
  104.  
  105. #~      offset = The amount of offset you want to add (can be negative)
  106.  
  107. #~    Example:
  108. #~    $game_player.jms_met_addoffset("North", "x", -3)
  109. #~       Adds offset if you travel through the north
  110. #~       3 will be subtracted from the x-axis
  111.  
  112. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
  113.  
  114. #~~~~~~~~~~~~~~~~~~~~~~~Main Script~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  115. # Don't edit anything below, unless you know what you are doing:
  116.   end #module MET
  117. end #module JMSC
  118.  
  119. #==============================================================================
  120. # ** Game_Player
  121. #==============================================================================
  122. class Game_Player < Game_Character
  123.  
  124.   #--------------------------------------------------------------------------
  125.   # * [Alias] initialize
  126.   # *   Adding new variables
  127.   #--------------------------------------------------------------------------
  128.   alias jms_MapEdgeTransfer_GameCharacterBase_init initialize
  129.   def initialize
  130.     jms_MapEdgeTransfer_GameCharacterBase_init
  131.     @jms_met_through = false
  132.     @jms_met_xnorth = @jms_met_ynorth = @jms_met_dnorth = false
  133.     @jms_met_xeast = @jms_met_yeast = @jms_met_deast = false
  134.     @jms_met_xsouth = @jms_met_ysouth = @jms_met_dsouth = false
  135.     @jms_met_xwest = @jms_met_ywest = @jms_met_dwest = false
  136.     @jms_met_xoffnorth = @jms_met_yoffnorth = @jms_met_xoffeast = 0
  137.     @jms_met_yoffeast = @jms_met_xoffsouth = @jms_met_yoffsouth = 0
  138.     @jms_met_xoffwest = @jms_met_yoffwest = 0
  139.   end
  140.  
  141.   #--------------------------------------------------------------------------
  142.   # * [Alias] passable?
  143.   # *   If the new variable is on, everything will be passable!
  144.   #--------------------------------------------------------------------------
  145.   alias jms_MapEdgeTransfer_GameCharacterBase_passable? passable?
  146.   def passable?(x, y, d)
  147.     return true if @jms_met_through
  148.     jms_MapEdgeTransfer_GameCharacterBase_passable?(x, y, d)
  149.   end
  150.  
  151.   #--------------------------------------------------------------------------
  152.   # * [Alias] update
  153.   # *   Makes autotransfer possible
  154.   #--------------------------------------------------------------------------
  155.   alias jms_MapEdgeTransfer_GamePlayer_update update
  156.         def update
  157.     jms_met_autotransfer
  158.     jms_MapEdgeTransfer_GamePlayer_update
  159.   end
  160.  
  161.   #--------------------------------------------------------------------------
  162.   # * [Alias] move_by_input
  163.   # *   Makes passing through map edges possible
  164.   #--------------------------------------------------------------------------
  165.   alias jms_MapEdgeTransfer_GamePlayer_movebyinput move_by_input
  166.   def move_by_input
  167.     if jms_met_edgeblock? && jms_met_edgepassable? > 0
  168.       jms_met_executeedgepassing
  169.     else
  170.       jms_MapEdgeTransfer_GamePlayer_movebyinput
  171.     end
  172.   end
  173.  
  174.   #--------------------------------------------------------------------------
  175.   # * [Alias] reserve_transfer
  176.   # *   Resets variables of the scriptcall(s)
  177.   #--------------------------------------------------------------------------
  178.   alias jms_MapEdgeTransfer_gameplayer_reservetransfer reserve_transfer
  179.   def reserve_transfer(*args)
  180.     @jms_met_xnorth = @jms_met_ynorth = @jms_met_dnorth = false
  181.     @jms_met_xeast = @jms_met_yeast = @jms_met_deast = false
  182.     @jms_met_xsouth = @jms_met_ysouth = @jms_met_dsouth = false
  183.     @jms_met_xwest = @jms_met_ywest = @jms_met_dwest = false
  184.     @jms_met_xoffnorth = @jms_met_yoffnorth = @jms_met_xoffeast = 0
  185.     @jms_met_yoffeast = @jms_met_xoffsouth = @jms_met_yoffsouth = 0
  186.     @jms_met_xoffwest = @jms_met_yoffwest = 0
  187.     jms_MapEdgeTransfer_gameplayer_reservetransfer(*args)
  188.   end
  189.  
  190. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  191. # Method-chain: Map Edge Passing
  192.  
  193. # Relevant Methods:
  194. # jms_met_edgeblock? <- Player movement blocked by edge?
  195. # jms_met_edgepassable? <- Is the edge passable and which edge is it?
  196. # jms_met_executeedgepassing <- Actually pass through the edge
  197.  
  198. # Useful methods
  199. # jms_met_corner? <- Which Corner is the Player in? (diagonal number)
  200. # jms_met_movethrough(d) <- Move through everything, even edges (dir4 only)
  201. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  202.   #--------------------------------------------------------------------------
  203.   # * [New Method] jms_met_edgeblock?
  204.   # *   Return true if input will be blocked by a potentially passable edge
  205.   #--------------------------------------------------------------------------
  206.   def jms_met_edgeblock?
  207.     return false if $game_switches[JMSC::MET::Disable_AutoEdgeTransfer_Switch]
  208.     return true if jms_met_edgex? == jms_met_dirconvx?
  209.     return true if jms_met_edgey? == jms_met_dirconvy?
  210.     return false
  211.   end
  212.  
  213.   #--------------------------------------------------------------------------
  214.   # * [New Method] jms_met_edgepassable?
  215.   # *   Return dir number if edge that blocks the Player is passable variable-wise
  216.   #--------------------------------------------------------------------------
  217.   def jms_met_edgepassable?
  218.     return 8 if jms_met_dirconvy? == 8 && jms_met_edgey? == 8 && $game_variables[JMSC::MET::MapID_North_Variable] > 0
  219.     return 6 if jms_met_dirconvx? == 6 && jms_met_edgex? == 6 && $game_variables[JMSC::MET::MapID_East_Variable] > 0
  220.     return 2 if jms_met_dirconvy? == 2 && jms_met_edgey? == 2 && $game_variables[JMSC::MET::MapID_South_Variable] > 0
  221.     return 4 if jms_met_dirconvx? == 4 && jms_met_edgex? == 4 && $game_variables[JMSC::MET::MapID_West_Variable] > 0
  222.     return 0
  223.   end
  224.  
  225.   #--------------------------------------------------------------------------
  226.   # * [New Method] jms_met_executeedgepassing
  227.   # *   Move the player through the edge
  228.   #--------------------------------------------------------------------------
  229.   def jms_met_executeedgepassing
  230.     d = jms_met_edgepassable?
  231.     jms_met_movethrough(d) unless jms_met_edgepassable? == 0
  232.   end  
  233.  
  234.   #--------------------------------------------------------------------------
  235.   # * [New Method] jms_met_movethrough(d)
  236.   # *   Forces the player to move_straight through everything in direction "d"
  237.   #--------------------------------------------------------------------------
  238.   def jms_met_movethrough(d)
  239.     return if !movable? || $game_map.interpreter.running?
  240.     @jms_met_through = true
  241.     jms_met_move_straight(d) if JMSC::MET::New_Move_Straight
  242.     move_straight(d) if !JMSC::MET::New_Move_Straight
  243.     @jms_met_through = false
  244.   end
  245.  
  246.   #--------------------------------------------------------------------------
  247.   # * [New Method] jms_met_dir8convx?
  248.   # *   Converts a dir8 input into a dir4 NUMBER (x axis)
  249.   #--------------------------------------------------------------------------
  250.   def jms_met_dirconvx?
  251.     return 4 if Input.dir8 == 7 || Input.dir8 == 1 || Input.dir4 == 4 #west
  252.     return 6 if Input.dir8 == 9 || Input.dir8 == 3 || Input.dir4 == 6 #east
  253.   end
  254.    
  255.   #--------------------------------------------------------------------------
  256.   # * [New Method] jms_met_dir8convy?
  257.   # *   Converts a dir8 input into a dir4 NUMBER (y axis)
  258.   #--------------------------------------------------------------------------
  259.   def jms_met_dirconvy?
  260.     return 8 if Input.dir8 == 7 || Input.dir8 == 9 || Input.dir4 == 8 #north
  261.     return 2 if Input.dir8 == 1 || Input.dir8 == 3 || Input.dir4 == 2 #south
  262.   end
  263.    
  264.   #--------------------------------------------------------------------------
  265.   # * [New Method] jms_met_corner?
  266.   # *   Return (diagonal) direction number if Player is on a map corner
  267.   #--------------------------------------------------------------------------
  268.   def jms_met_corner?
  269.     return 9 if jms_met_edgex? == 8 && jms_met_edgey? == 6 #north-east
  270.     return 3 if jms_met_edgex? == 2 && jms_met_edgey? == 6 #south-east
  271.     return 1 if jms_met_edgex? == 2 && jms_met_edgey? == 4 #south-west
  272.     return 7 if jms_met_edgex? == 8 && jms_met_edgey? == 4 #north-west
  273.     return 0
  274.   end
  275.  
  276.   #--------------------------------------------------------------------------
  277.   # * [New Method] jms_met_edgex?
  278.   # *   Return direction number if Player is on on a map edge (x axis)
  279.   #--------------------------------------------------------------------------
  280.   def jms_met_edgex?
  281.     return 4 if @real_x == 0 #west
  282.     return 6 if @real_x + 1 == $game_map.width #east
  283.     return 0
  284.   end
  285.  
  286.   #--------------------------------------------------------------------------
  287.   # * [New Method] jms_met_edgey?
  288.   # *   Return direction number if Player is on on a map edge (y axis)
  289.   #--------------------------------------------------------------------------
  290.   def jms_met_edgey?
  291.     return 8 if @real_y == 0 #north
  292.     return 2 if @real_y + 1 == $game_map.height #south
  293.     return 0
  294.   end
  295. #End of Method-Chain: Map Edge Passing
  296.  
  297. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  298. # Method-chain: Automatic Transfer
  299.  
  300. # Relevant Methods:
  301. # jms_met_autotransfer <- Checks if Conditions for automatic transfer are met
  302.  
  303. # Useful Methods:
  304. # jms_met_overedge? <- Return number if Player is directly behind an edge
  305. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  306.   #--------------------------------------------------------------------------
  307.   # * [New Method] jms_met_autotransfer
  308.   # *   Go on with autotransfer, if player passed through an edge
  309.   #--------------------------------------------------------------------------
  310.   def jms_met_autotransfer
  311.     jms_met_transfer(8) if jms_met_overedge? == 8 && $game_variables[JMSC::MET::MapID_North_Variable] > 0
  312.                 jms_met_transfer(6) if jms_met_overedge? == 6 && $game_variables[JMSC::MET::MapID_East_Variable] > 0
  313.                 jms_met_transfer(2) if jms_met_overedge? == 2 && $game_variables[JMSC::MET::MapID_South_Variable] > 0
  314.                 jms_met_transfer(4) if jms_met_overedge? == 4 && $game_variables[JMSC::MET::MapID_West_Variable] > 0
  315.         end
  316.  
  317.   #--------------------------------------------------------------------------
  318.   # * [New Method] jms_met_tranfer(d)
  319.   # *   Executing the automatic transfer to cardinal direction map "d"
  320.   #--------------------------------------------------------------------------
  321.         def jms_met_transfer(d)
  322.     $game_temp.fade_type = JMSC::MET::Fade_Type
  323.     dtrans = d
  324.     if d == 8 #north
  325.       new_map = $game_variables[JMSC::MET::MapID_North_Variable]
  326.       load_map = load_data(sprintf("Data/Map%03d.rvdata2", new_map))
  327.       new_x = @real_x unless @jms_met_xnorth
  328.       new_x = @jms_met_xnorth if @jms_met_xnorth
  329.       new_x += @jms_met_xoffnorth
  330.       new_y = load_map.height - 1 unless @jms_met_ynorth
  331.       new_y = @jms_met_ynorth if @jms_met_ynorth
  332.       new_y += @jms_met_yoffnorth
  333.       dtrans = @jms_met_dnorth if @jms_met_dnorth
  334.     end
  335.     if d == 6 #east
  336.       new_x = 0 unless @jms_met_xeast
  337.       new_x = @jms_met_xeast if @jms_met_xeast
  338.       new_x += @jms_met_xoffeast
  339.       new_y = @real_y unless @jms_met_yeast
  340.       new_y = @jms_met_yeast if @jms_met_yeast
  341.       new_y += @jms_met_yoffeast
  342.       new_map = $game_variables[JMSC::MET::MapID_East_Variable]
  343.       dtrans = @jms_met_deast if @jms_met_deast
  344.     end
  345.     if d == 2 #south
  346.       new_x = @real_x unless @jms_met_xsouth
  347.       new_x = @jms_met_xsouth if @jms_met_xsouth
  348.       new_x += @jms_met_xoffsouth
  349.       new_y = 0 unless @jms_met_ysouth
  350.       new_y = @jms_met_ysouth if @jms_met_ysouth
  351.       new_y += @jms_met_yoffsouth
  352.       new_map = $game_variables[JMSC::MET::MapID_South_Variable]
  353.       dtrans = @jms_met_dsouth if @jms_met_dsouth
  354.     end
  355.     if d == 4 #west
  356.       new_map = $game_variables[JMSC::MET::MapID_West_Variable]
  357.       load_map = load_data(sprintf("Data/Map%03d.rvdata2", new_map))
  358.       new_x = load_map.width - 1 unless @jms_met_xwest
  359.       new_x = @jms_met_xwest if @jms_met_xwest
  360.       new_x += @jms_met_xoffwest
  361.       new_y = @real_y unless @jms_met_ywest
  362.       new_y = @jms_met_ywest if @jms_met_ywest
  363.       new_y += @jms_met_yoffwest
  364.       dtrans = @jms_met_dwest if @jms_met_dwest
  365.     end
  366.     if $jimported[:jms_sef] != nil
  367.       $game_temp.jms_met_sliding = true unless $game_switches[JMSC::SEF::Disable_Sliding_Switch]
  368.     end
  369.     reserve_transfer(new_map, new_x, new_y, dtrans)
  370.   end
  371.  
  372.   #--------------------------------------------------------------------------
  373.   # * [New Method] jms_met_transferinfo(card, x, y, d)
  374.   # *   Changes transfer details
  375.   #--------------------------------------------------------------------------
  376.   def jms_met_transferinfo(card, x = false, y = false, d = false)
  377.     if card == "North" || card == 8
  378.       @jms_met_xnorth = x
  379.       @jms_met_ynorth = y
  380.       @jms_met_dnorth = d
  381.     end
  382.     if card == "East" || card == 6
  383.       @jms_met_xeast = x
  384.       @jms_met_yeast = y
  385.       @jms_met_deast = d
  386.     end
  387.     if card == "South" || card == 2
  388.       @jms_met_xsouth = x
  389.       @jms_met_ysouth = y
  390.       @jms_met_dsouth = d
  391.     end
  392.     if card == "West" || card == 4
  393.       @jms_met_xwest = x
  394.       @jms_met_ywest = y
  395.       @jms_met_dwest = d
  396.     end
  397.   end
  398.  
  399.   def jms_met_addoffset(card, axis, offset)
  400.     if card == "North" || card == 8
  401.       @jms_met_xoffnorth = offset if axis == "x"
  402.       @jms_met_yoffnorth = offset if axis == "y"
  403.     end
  404.     if card == "East" || card == 6
  405.       @jms_met_xoffeast = offset if axis == "x"
  406.       @jms_met_yoffeast = offset if axis == "y"
  407.     end
  408.     if card == "South" || card == 2
  409.       @jms_met_xoffsouth = offset if axis == "x"
  410.       @jms_met_yoffsouth = offset if axis == "y"
  411.     end
  412.     if card == "West" || card == 4
  413.       @jms_met_xoffwest = offset if axis == "x"
  414.       @jms_met_yoffwest = offset if axis == "y"
  415.     end
  416.   end
  417.  
  418.   #--------------------------------------------------------------------------
  419.   # * [New Method] jms_met_overedge?
  420.   # *   Return direction number if Player passed one of the map edges
  421.   #--------------------------------------------------------------------------
  422.   def jms_met_overedge?
  423.     return 8 if @real_y + 1 == 0 #north
  424.     return 6 if $game_map.width == @real_x #east
  425.     return 2 if $game_map.height == @real_y #south
  426.     return 4 if @real_x + 1 == 0 #west
  427.     return 0
  428.   end
  429. #End of Method-Chain: Automatic Transfer
  430.  
  431. #Compatibility fix: Pixel Movement
  432.   #--------------------------------------------------------------------------
  433.   # * [New Method] jms_met_move_straight
  434.   # *   Copy of move_straight
  435.   #--------------------------------------------------------------------------
  436.   def jms_met_move_straight(d, turn_ok = true)
  437.     @move_succeed = passable?(@x, @y, d)
  438.     if @move_succeed
  439.       set_direction(d)
  440.       @x = $game_map.round_x_with_direction(@x, d)
  441.       @y = $game_map.round_y_with_direction(@y, d)
  442.       @real_x = $game_map.x_with_direction(@x, reverse_dir(d))
  443.       @real_y = $game_map.y_with_direction(@y, reverse_dir(d))
  444.       increase_steps
  445.     elsif turn_ok
  446.       set_direction(d)
  447.       check_event_trigger_touch_front
  448.     end
  449.   end
  450. #End of Compatibility fix: Pixel Movement
  451.  
  452. end #Game_Player
  453. # END OF SCRIPT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement