I messed up event handling?

Hey there! I was working on my RMXP project, in which I use a lot of custom scripts.

Somehow I ended up needing to replace Game_Player and Game_Character, which I basically copied into respectively Playable_Character and NonPlayable_Character. This way I can do some stuff for my battle system more easily later on, and I got rid of Game_Player and Game_Character. I corrected all superclass and other issues, so everything should be fine I thought.

It seemed like I had got everything working, but when I playtested the player's speed was very high. I thought it was an issue with the dashing snippet I added to Playable_Character, but that wasn't the case. The player's speed was still 4, but in-game the player moved way too fast.
Then I wanted to interact with an event that gives the player 5 different items, but the event kept going somehow, it added 2 of each to the inventory instead of 1 of each. Another event, which changes the current active player, just caused to freeze the players graphic but you could move with an invisible character that randomly stops and keeps going again.

Here are the scripts.
This is NonPlayable Character, which is just Game_Character 1, 2, and 3 merged into 1 script under a new name.
The only thing changed: @character_name is now @graphic to avoid confusion with my other scripts.
  1. class NonPlayable_Character
  2.   attr_reader   :id
  3.   attr_reader   :x                        # map x-coordinate (logical)
  4.   attr_reader   :y                        # map y-coordinate (logical)
  5.   attr_reader   :real_x                   # map x-coordinate (real * 128)
  6.   attr_reader   :real_y                   # map y-coordinate (real * 128)
  7.   attr_reader   :tile_id                  # tile ID (invalid if 0)
  8.   attr_reader   :character_hue            # character hue
  9.   attr_reader   :opacity                  # opacity level
  10.   attr_reader   :blend_type               # blending method
  11.   attr_reader   :direction                # direction
  12.   attr_reader   :pattern                  # pattern
  13.   attr_reader   :move_route_forcing       # forced move route flag
  14.   attr_reader   :through                  # through
  15.   attr_accessor :graphic                  # graphic file name
  16.   attr_accessor :animation_id             # animation ID
  17.   attr_accessor :transparent              # transparent flag
  18.  
  19.   def initialize(graphic="")
  20.      @id = 0
  21.      @x = 0
  22.      @y = 0
  23.      @real_x = 0
  24.      @real_y = 0
  25.      @tile_id = 0
  26.      @graphic = graphic
  27.      @character_hue = 0
  28.      @opacity = 255
  29.      @blend_type = 0
  30.      @direction = 2
  31.      @pattern = 0
  32.      @move_route_forcing = false
  33.      @through = false
  34.      @animation_id = 0
  35.      @transparent = false
  36.      @original_direction = 2
  37.      @original_pattern = 0
  38.      @move_type = 0
  39.      @move_speed = 3.5
  40.      @move_frequency = 6
  41.      @move_route = nil
  42.      @move_route_index = 0
  43.      @original_move_route = nil
  44.      @original_move_route_index = 0
  45.      @walk_anime = true
  46.      @step_anime = false
  47.      @direction_fix = false
  48.      @always_on_top = false
  49.      @anime_count = 0
  50.      @stop_count = 0
  51.      @jump_count = 0
  52.      @jump_peak = 0
  53.      @wait_count = 0
  54.      @locked = false
  55.      @prelock_direction = 0
  56.    end
  57.    
  58.   #--------------------------------------------------------------------------
  59.   # * Determine if Moving
  60.   #--------------------------------------------------------------------------
  61.   def moving?
  62.     # If logical coordinates differ from real coordinates,
  63.     # movement is occurring.
  64.     return (@real_x != @x * 128 or @real_y != @y * 128)
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # * Determine if Jumping
  68.   #--------------------------------------------------------------------------
  69.   def jumping?
  70.     # A jump is occurring if jump count is larger than 0
  71.     return @jump_count > 0
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # * Straighten Position
  75.   #--------------------------------------------------------------------------
  76.   def straighten
  77.     # If moving animation or stop animation is ON
  78.     if @walk_anime or @step_anime
  79.       # Set pattern to 0
  80.       @pattern = 0
  81.     end
  82.     # Clear animation count
  83.     @anime_count = 0
  84.     # Clear prelock direction
  85.     @prelock_direction = 0
  86.   end
  87.   #--------------------------------------------------------------------------
  88.   # * Force Move Route
  89.   #     move_route : new move route
  90.   #--------------------------------------------------------------------------
  91.   def force_move_route(move_route)
  92.     # Save original move route
  93.     if @original_move_route == nil
  94.       @original_move_route = @move_route
  95.       @original_move_route_index = @move_route_index
  96.     end
  97.     # Change move route
  98.     @move_route = move_route
  99.     @move_route_index = 0
  100.     # Set forced move route flag
  101.     @move_route_forcing = true
  102.     # Clear prelock direction
  103.     @prelock_direction = 0
  104.     # Clear wait count
  105.     @wait_count = 0
  106.     # Move cutsom
  107.     move_type_custom
  108.   end
  109.   #--------------------------------------------------------------------------
  110.   # * Determine if Passable
  111.   #     x : x-coordinate
  112.   #     y : y-coordinate
  113.   #     d : direction (0,2,4,6,8)
  114.   #         * 0 = Determines if all directions are impassable (for jumping)
  115.   #--------------------------------------------------------------------------
  116.   def passable?(x, y, d)
  117.     # Get new coordinates
  118.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  119.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  120.     # If coordinates are outside of map
  121.     unless $game_map.valid?(new_x, new_y)
  122.       # impassable
  123.       return false
  124.     end
  125.     # If through is ON
  126.     if @through
  127.       # passable
  128.       return true
  129.     end
  130.     # If unable to leave first move tile in designated direction
  131.     unless $game_map.passable?(x, y, d, self)
  132.       # impassable
  133.       return false
  134.     end
  135.     # If unable to enter move tile in designated direction
  136.     unless $game_map.passable?(new_x, new_y, 10 - d)
  137.       # impassable
  138.       return false
  139.     end
  140.     # Loop all events
  141.     for event in $game_map.events.values
  142.       # If event coordinates are consistent with move destination
  143.       if event.x == new_x and event.y == new_y
  144.         # If through is OFF
  145.         unless event.through
  146.           # If self is event
  147.           unless self.is_a?(Playable_Character)
  148.             # impassable
  149.             return false
  150.           end
  151.           # With self as the player and partner graphic as character
  152.           if event.graphic != ""
  153.             # impassable
  154.             return false
  155.           end
  156.         end
  157.       end
  158.     end
  159.     # If player coordinates are consistent with move destination
  160.     if getActiveChar.x == new_x and getActiveChar.y == new_y
  161.       # If through is OFF
  162.       unless getActiveChar.through
  163.         # If your own graphic is the character
  164.         if @graphic != ""
  165.           # impassable
  166.           return false
  167.         end
  168.       end
  169.     end
  170.     # passable
  171.     return true
  172.   end
  173.   #--------------------------------------------------------------------------
  174.   # * Lock
  175.   #--------------------------------------------------------------------------
  176.   def lock
  177.     # If already locked
  178.     if @locked
  179.       # End method
  180.       return
  181.     end
  182.     # Save prelock direction
  183.     @prelock_direction = @direction
  184.     # Turn toward player
  185.     turn_toward_player
  186.     # Set locked flag
  187.     @locked = true
  188.   end
  189.   #--------------------------------------------------------------------------
  190.   # * Determine if Locked
  191.   #--------------------------------------------------------------------------
  192.   def lock?
  193.     return @locked
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # * Unlock
  197.   #--------------------------------------------------------------------------
  198.   def unlock
  199.     # If not locked
  200.     unless @locked
  201.       # End method
  202.       return
  203.     end
  204.     # Clear locked flag
  205.     @locked = false
  206.     # If direction is not fixed
  207.     unless @direction_fix
  208.       # If prelock direction is saved
  209.       if @prelock_direction != 0
  210.         # Restore prelock direction
  211.         @direction = @prelock_direction
  212.       end
  213.     end
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # * Move to Designated Position
  217.   #     x : x-coordinate
  218.   #     y : y-coordinate
  219.   #--------------------------------------------------------------------------
  220.   def moveto(x, y)
  221.     @x = x % $game_map.width
  222.     @y = y % $game_map.height
  223.     @real_x = @x * 128
  224.     @real_y = @y * 128
  225.     @prelock_direction = 0
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # * Get Screen X-Coordinates
  229.   #--------------------------------------------------------------------------
  230.   def screen_x
  231.     # Get screen coordinates from real coordinates and map display position
  232.     return (@real_x - $game_map.display_x + 3) / 4 + 16
  233.   end
  234.   #--------------------------------------------------------------------------
  235.   # * Get Screen Y-Coordinates
  236.   #--------------------------------------------------------------------------
  237.   def screen_y
  238.     # Get screen coordinates from real coordinates and map display position
  239.     y = (@real_y - $game_map.display_y + 3) / 4 + 32
  240.     # Make y-coordinate smaller via jump count
  241.     if @jump_count >= @jump_peak
  242.       n = @jump_count - @jump_peak
  243.     else
  244.       n = @jump_peak - @jump_count
  245.     end
  246.     return y - (@jump_peak * @jump_peak - n * n) / 2
  247.   end
  248.   #--------------------------------------------------------------------------
  249.   # * Get Screen Z-Coordinates
  250.   #     height : character height
  251.   #--------------------------------------------------------------------------
  252.   def screen_z(height = 0)
  253.     # If display flag on closest surface is ON
  254.     if @always_on_top
  255.       # 999, unconditional
  256.       return 999
  257.     end
  258.     # Get screen coordinates from real coordinates and map display position
  259.     z = (@real_y - $game_map.display_y + 3) / 4 + 32
  260.     # If tile
  261.     if @tile_id > 0
  262.       # Add tile priority * 32
  263.       return z + $game_map.priorities[@tile_id] * 32
  264.     # If character
  265.     else
  266.       # If height exceeds 32, then add 31
  267.       return z + ((height > 32) ? 31 : 0)
  268.     end
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # * Get Thicket Depth
  272.   #--------------------------------------------------------------------------
  273.   def bush_depth
  274.     # If tile, or if display flag on the closest surface is ON
  275.     if @tile_id > 0 or @always_on_top
  276.       return 0
  277.     end
  278.     # If element tile other than jumping, then 12; anything else = 0
  279.     if @jump_count == 0 and $game_map.bush?(@x, @y)
  280.       return 12
  281.     else
  282.       return 0
  283.     end
  284.   end
  285.   #--------------------------------------------------------------------------
  286.   # * Get Terrain Tag
  287.   #--------------------------------------------------------------------------
  288.   def terrain_tag
  289.     return $game_map.terrain_tag(@x, @y)
  290.   end
  291.  
  292.   def update
  293.     # Branch with jumping, moving, and stopping
  294.     if jumping?
  295.       update_jump
  296.     elsif moving?
  297.       update_move
  298.     else
  299.       update_stop
  300.     end
  301.     # If animation count exceeds maximum value
  302.     # * Maximum value is move speed * 1 taken from basic value 18
  303.     if @anime_count > 18 - @move_speed * 2
  304.       # If stop animation is OFF when stopping
  305.       if not @step_anime and @stop_count > 0
  306.         # Return to original pattern
  307.         @pattern = @original_pattern
  308.       # If stop animation is ON when moving
  309.       else
  310.         # Update pattern
  311.         @pattern = (@pattern + 1) % 4
  312.       end
  313.       # Clear animation count
  314.       @anime_count = 0
  315.     end
  316.     # If waiting
  317.     if @wait_count > 0
  318.       # Reduce wait count
  319.       @wait_count -= 1
  320.       return
  321.     end
  322.     # If move route is forced
  323.     if @move_route_forcing
  324.       # Custom move
  325.       move_type_custom
  326.       return
  327.     end
  328.     # When waiting for event execution or locked
  329.     if @starting or lock?
  330.       # Not moving by self
  331.       return
  332.     end
  333.     # If stop count exceeds a certain value (computed from move frequency)
  334.     if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
  335.       # Branch by move type
  336.       case @move_type
  337.       when 1  # Random
  338.         move_type_random
  339.       when 2  # Approach
  340.         move_type_toward_player
  341.       when 3  # Custom
  342.         move_type_custom
  343.       end
  344.     end
  345.   end
  346.   #--------------------------------------------------------------------------
  347.   # * Frame Update (jump)
  348.   #--------------------------------------------------------------------------
  349.   def update_jump
  350.     # Reduce jump count by 1
  351.     @jump_count -= 1
  352.     # Calculate new coordinates
  353.     @real_x = (@real_x * @jump_count + @x * 128) / (@jump_count + 1)
  354.     @real_y = (@real_y * @jump_count + @y * 128) / (@jump_count + 1)
  355.   end
  356.   #--------------------------------------------------------------------------
  357.   # * Update frame (move)
  358.   #--------------------------------------------------------------------------
  359.   def update_move
  360.     # Convert map coordinates from map move speed into move distance
  361.     distance = 2 ** @move_speed
  362.     # If logical coordinates are further down than real coordinates
  363.     if @y * 128 > @real_y
  364.       # Move down
  365.       @real_y = [@real_y + distance, @y * 128].min
  366.     end
  367.     # If logical coordinates are more to the left than real coordinates
  368.     if @x * 128 < @real_x
  369.       # Move left
  370.       @real_x = [@real_x - distance, @x * 128].max
  371.     end
  372.     # If logical coordinates are more to the right than real coordinates
  373.     if @x * 128 > @real_x
  374.       # Move right
  375.       @real_x = [@real_x + distance, @x * 128].min
  376.     end
  377.     # If logical coordinates are further up than real coordinates
  378.     if @y * 128 < @real_y
  379.       # Move up
  380.       @real_y = [@real_y - distance, @y * 128].max
  381.     end
  382.     # If move animation is ON
  383.     if @walk_anime
  384.       # Increase animation count by 1.5
  385.       @anime_count += 1.5
  386.     # If move animation is OFF, and stop animation is ON
  387.     elsif @step_anime
  388.       # Increase animation count by 1
  389.       @anime_count += 1
  390.     end
  391.   end
  392.   #--------------------------------------------------------------------------
  393.   # * Frame Update (stop)
  394.   #--------------------------------------------------------------------------
  395.   def update_stop
  396.     # If stop animation is ON
  397.     if @step_anime
  398.       # Increase animation count by 1
  399.       @anime_count += 1
  400.     # If stop animation is OFF, but current pattern is different from original
  401.     elsif @pattern != @original_pattern
  402.       # Increase animation count by 1.5
  403.       @anime_count += 1.5
  404.     end
  405.     # When waiting for event execution, or not locked
  406.     # * If lock deals with event execution coming to a halt
  407.     unless @starting or lock?
  408.       # Increase stop count by 1
  409.       @stop_count += 1
  410.     end
  411.   end
  412.   #--------------------------------------------------------------------------
  413.   # * Move Type : Random
  414.   #--------------------------------------------------------------------------
  415.   def move_type_random
  416.     # Branch by random numbers 0-5
  417.     case rand(6)
  418.     when 0..3  # Random
  419.       move_random
  420.     when 4  # 1 step forward
  421.       move_forward
  422.     when 5  # Temporary stop
  423.       @stop_count = 0
  424.     end
  425.   end
  426.  
  427.   #--------------------------------------------------------------------------
  428.   # * Move Type : Custom
  429.   #--------------------------------------------------------------------------
  430.   def move_type_custom
  431.     # Interrupt if not stopping
  432.     if jumping? or moving?
  433.       return
  434.     end
  435.     # Loop until finally arriving at move command list
  436.     while @move_route_index < @move_route.list.size
  437.       # Acquiring move command
  438.       command = @move_route.list[@move_route_index]
  439.       # If command code is 0 (last part of list)
  440.       if command.code == 0
  441.         # If [repeat action] option is ON
  442.         if @move_route.repeat
  443.           # First return to the move route index
  444.           @move_route_index = 0
  445.         end
  446.         # If [repeat action] option is OFF
  447.         unless @move_route.repeat
  448.           # If move route is forcing
  449.           if @move_route_forcing and not @move_route.repeat
  450.             # Release forced move route
  451.             @move_route_forcing = false
  452.             # Restore original move route
  453.             @move_route = @original_move_route
  454.             @move_route_index = @original_move_route_index
  455.             @original_move_route = nil
  456.           end
  457.           # Clear stop count
  458.           @stop_count = 0
  459.         end
  460.         return
  461.       end
  462.       # During move command (from move down to jump)
  463.       if command.code <= 14
  464.         # Branch by command code
  465.         case command.code
  466.         when 1  # Move down
  467.           move_down
  468.         when 2  # Move left
  469.           move_left
  470.         when 3  # Move right
  471.           move_right
  472.         when 4  # Move up
  473.           move_up
  474.         when 5  # Move lower left
  475.           move_lower_left
  476.         when 6  # Move lower right
  477.           move_lower_right
  478.         when 7  # Move upper left
  479.           move_upper_left
  480.         when 8  # Move upper right
  481.           move_upper_right
  482.         when 9  # Move at random
  483.           move_random
  484.         when 10  # Move toward player
  485.           move_toward_player
  486.         when 11  # Move away from player
  487.           move_away_from_player
  488.         when 12  # 1 step forward
  489.           move_forward
  490.         when 13  # 1 step backward
  491.           move_backward
  492.         when 14  # Jump
  493.           jump(command.parameters[0], command.parameters[1])
  494.         end
  495.         # If movement failure occurs when [Ignore if can't move] option is OFF
  496.         if not @move_route.skippable and not moving? and not jumping?
  497.           return
  498.         end
  499.         @move_route_index += 1
  500.         return
  501.       end
  502.       # If waiting
  503.       if command.code == 15
  504.         # Set wait count
  505.         @wait_count = command.parameters[0] * 2 - 1
  506.         @move_route_index += 1
  507.         return
  508.       end
  509.       # If direction change command
  510.       if command.code >= 16 and command.code <= 26
  511.         # Branch by command code
  512.         case command.code
  513.         when 16  # Turn down
  514.           turn_down
  515.         when 17  # Turn left
  516.           turn_left
  517.         when 18  # Turn right
  518.           turn_right
  519.         when 19  # Turn up
  520.           turn_up
  521.         when 20  # Turn 90° right
  522.           turn_right_90
  523.         when 21  # Turn 90° left
  524.           turn_left_90
  525.         when 22  # Turn 180°
  526.           turn_180
  527.         when 23  # Turn 90° right or left
  528.           turn_right_or_left_90
  529.         when 24  # Turn at Random
  530.           turn_random
  531.         when 25  # Turn toward player
  532.           turn_toward_player
  533.         when 26  # Turn away from player
  534.           turn_away_from_player
  535.         end
  536.         @move_route_index += 1
  537.         return
  538.       end
  539.       # If other command
  540.       if command.code >= 27
  541.         # Branch by command code
  542.         case command.code
  543.         when 27  # Switch ON
  544.           $game_switches[command.parameters[0]] = true
  545.           $game_map.need_refresh = true
  546.         when 28  # Switch OFF
  547.           $game_switches[command.parameters[0]] = false
  548.           $game_map.need_refresh = true
  549.         when 29  # Change speed
  550.           @move_speed = command.parameters[0]
  551.         when 30  # Change freq
  552.           @move_frequency = command.parameters[0]
  553.         when 31  # Move animation ON
  554.           @walk_anime = true
  555.         when 32  # Move animation OFF
  556.           @walk_anime = false
  557.         when 33  # Stop animation ON
  558.           @step_anime = true
  559.         when 34  # Stop animation OFF
  560.           @step_anime = false
  561.         when 35  # Direction fix ON
  562.           @direction_fix = true
  563.         when 36  # Direction fix OFF
  564.           @direction_fix = false
  565.         when 37  # Through ON
  566.           @through = true
  567.         when 38  # Through OFF
  568.           @through = false
  569.         when 39  # Always on top ON
  570.           @always_on_top = true
  571.         when 40  # Always on top OFF
  572.           @always_on_top = false
  573.         when 41  # Change Graphic
  574.           @tile_id = 0
  575.           @graphic = command.parameters[0]
  576.           @character_hue = command.parameters[1]
  577.           if @original_direction != command.parameters[2]
  578.             @direction = command.parameters[2]
  579.             @original_direction = @direction
  580.             @prelock_direction = 0
  581.           end
  582.           if @original_pattern != command.parameters[3]
  583.             @pattern = command.parameters[3]
  584.             @original_pattern = @pattern
  585.           end
  586.         when 42  # Change Opacity
  587.           @opacity = command.parameters[0]
  588.         when 43  # Change Blending
  589.           @blend_type = command.parameters[0]
  590.         when 44  # Play SE
  591.           $game_system.se_play(command.parameters[0])
  592.         when 45  # Script
  593.           result = eval(command.parameters[0])
  594.         end
  595.         @move_route_index += 1
  596.       end
  597.     end
  598.   end
  599.   #--------------------------------------------------------------------------
  600.   # * Increase Steps
  601.   #--------------------------------------------------------------------------
  602.   def increase_steps
  603.     # Clear stop count
  604.     @stop_count = 0
  605.   end
  606.  
  607.   #--------------------------------------------------------------------------
  608.   # * Move Down
  609.   #     turn_enabled : a flag permits direction change on that spot
  610.   #--------------------------------------------------------------------------
  611.   def move_down(turn_enabled = true)
  612.     # Turn down
  613.     if turn_enabled
  614.       turn_down
  615.     end
  616.     # If passable
  617.     if passable?(@x, @y, 2)
  618.       # Turn down
  619.       turn_down
  620.       # Update coordinates
  621.       @y += 1
  622.       # Increase steps
  623.       increase_steps
  624.     # If impassable
  625.     else
  626.       # Determine if touch event is triggered
  627.       check_event_trigger_touch(@x, @y+1)
  628.     end
  629.   end
  630.   #--------------------------------------------------------------------------
  631.   # * Move Left
  632.   #     turn_enabled : a flag permits direction change on that spot
  633.   #--------------------------------------------------------------------------
  634.   def move_left(turn_enabled = true)
  635.     # Turn left
  636.     if turn_enabled
  637.       turn_left
  638.     end
  639.     # If passable
  640.     if passable?(@x, @y, 4)
  641.       # Turn left
  642.       turn_left
  643.       # Update coordinates
  644.       @x -= 1
  645.       # Increase steps
  646.       increase_steps
  647.     # If impassable
  648.     else
  649.       # Determine if touch event is triggered
  650.       check_event_trigger_touch(@x-1, @y)
  651.     end
  652.   end
  653.   #--------------------------------------------------------------------------
  654.   # * Move Right
  655.   #     turn_enabled : a flag permits direction change on that spot
  656.   #--------------------------------------------------------------------------
  657.   def move_right(turn_enabled = true)
  658.     # Turn right
  659.     if turn_enabled
  660.       turn_right
  661.     end
  662.     # If passable
  663.     if passable?(@x, @y, 6)
  664.       # Turn right
  665.       turn_right
  666.       # Update coordinates
  667.       @x += 1
  668.       # Increase steps
  669.       increase_steps
  670.     # If impassable
  671.     else
  672.       # Determine if touch event is triggered
  673.       check_event_trigger_touch(@x+1, @y)
  674.     end
  675.   end
  676.   #--------------------------------------------------------------------------
  677.   # * Move up
  678.   #     turn_enabled : a flag permits direction change on that spot
  679.   #--------------------------------------------------------------------------
  680.   def move_up(turn_enabled = true)
  681.     # Turn up
  682.     if turn_enabled
  683.       turn_up
  684.     end
  685.     # If passable
  686.     if passable?(@x, @y, 8)
  687.       # Turn up
  688.       turn_up
  689.       # Update coordinates
  690.       @y -= 1
  691.       # Increase steps
  692.       increase_steps
  693.     # If impassable
  694.     else
  695.       # Determine if touch event is triggered
  696.       check_event_trigger_touch(@x, @y-1)
  697.     end
  698.   end
  699.   #--------------------------------------------------------------------------
  700.   # * Move Lower Left
  701.   #--------------------------------------------------------------------------
  702.   def move_lower_left
  703.     # If no direction fix
  704.     unless @direction_fix
  705.       # Face down is facing right or up
  706.       @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  707.     end
  708.     # When a down to left or a left to down course is passable
  709.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
  710.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  711.       # Update coordinates
  712.       @x -= 1
  713.       @y += 1
  714.       # Increase steps
  715.       increase_steps
  716.     end
  717.   end
  718.   #--------------------------------------------------------------------------
  719.   # * Move Lower Right
  720.   #--------------------------------------------------------------------------
  721.   def move_lower_right
  722.     # If no direction fix
  723.     unless @direction_fix
  724.       # Face right if facing left, and face down if facing up
  725.       @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  726.     end
  727.     # When a down to right or a right to down course is passable
  728.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
  729.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  730.       # Update coordinates
  731.       @x += 1
  732.       @y += 1
  733.       # Increase steps
  734.       increase_steps
  735.     end
  736.   end
  737.   #--------------------------------------------------------------------------
  738.   # * Move Upper Left
  739.   #--------------------------------------------------------------------------
  740.   def move_upper_left
  741.     # If no direction fix
  742.     unless @direction_fix
  743.       # Face left if facing right, and face up if facing down
  744.       @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  745.     end
  746.     # When an up to left or a left to up course is passable
  747.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
  748.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  749.       # Update coordinates
  750.       @x -= 1
  751.       @y -= 1
  752.       # Increase steps
  753.       increase_steps
  754.     end
  755.   end
  756.   #--------------------------------------------------------------------------
  757.   # * Move Upper Right
  758.   #--------------------------------------------------------------------------
  759.   def move_upper_right
  760.     # If no direction fix
  761.     unless @direction_fix
  762.       # Face right if facing left, and face up if facing down
  763.       @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  764.     end
  765.     # When an up to right or a right to up course is passable
  766.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
  767.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  768.       # Update coordinates
  769.       @x += 1
  770.       @y -= 1
  771.       # Increase steps
  772.       increase_steps
  773.     end
  774.   end
  775.   #--------------------------------------------------------------------------
  776.   # * Move at Random
  777.   #--------------------------------------------------------------------------
  778.   def move_random
  779.     case rand(4)
  780.     when 0  # Move down
  781.       move_down(false)
  782.     when 1  # Move left
  783.       move_left(false)
  784.     when 2  # Move right
  785.       move_right(false)
  786.     when 3  # Move up
  787.       move_up(false)
  788.     end
  789.   end
  790.   #--------------------------------------------------------------------------
  791.   # * Move toward Player
  792.   #--------------------------------------------------------------------------
  793.   def move_toward_player
  794.     # Get difference in player coordinates
  795.     sx = @x - getActiveChar.x
  796.     sy = @y - getActiveChar.y
  797.     # If coordinates are equal
  798.     if sx == 0 and sy == 0
  799.       return
  800.     end
  801.     # Get absolute value of difference
  802.     abs_sx = sx.abs
  803.     abs_sy = sy.abs
  804.     # If horizontal and vertical distances are equal
  805.     if abs_sx == abs_sy
  806.       # Increase one of them randomly by 1
  807.       rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
  808.     end
  809.     # If horizontal distance is longer
  810.     if abs_sx > abs_sy
  811.       # Move towards player, prioritize left and right directions
  812.       sx > 0 ? move_left : move_right
  813.       if not moving? and sy != 0
  814.         sy > 0 ? move_up : move_down
  815.       end
  816.     # If vertical distance is longer
  817.     else
  818.       # Move towards player, prioritize up and down directions
  819.       sy > 0 ? move_up : move_down
  820.       if not moving? and sx != 0
  821.         sx > 0 ? move_left : move_right
  822.       end
  823.     end
  824.   end
  825.   #--------------------------------------------------------------------------
  826.   # * Move away from Player
  827.   #--------------------------------------------------------------------------
  828.   def move_away_from_player
  829.     # Get difference in player coordinates
  830.     sx = @x - getActiveChar.x
  831.     sy = @y - getActiveChar.y
  832.     # If coordinates are equal
  833.     if sx == 0 and sy == 0
  834.       return
  835.     end
  836.     # Get absolute value of difference
  837.     abs_sx = sx.abs
  838.     abs_sy = sy.abs
  839.     # If horizontal and vertical distances are equal
  840.     if abs_sx == abs_sy
  841.       # Increase one of them randomly by 1
  842.       rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
  843.     end
  844.     # If horizontal distance is longer
  845.     if abs_sx > abs_sy
  846.       # Move away from player, prioritize left and right directions
  847.       sx > 0 ? move_right : move_left
  848.       if not moving? and sy != 0
  849.         sy > 0 ? move_down : move_up
  850.       end
  851.     # If vertical distance is longer
  852.     else
  853.       # Move away from player, prioritize up and down directions
  854.       sy > 0 ? move_down : move_up
  855.       if not moving? and sx != 0
  856.         sx > 0 ? move_right : move_left
  857.       end
  858.     end
  859.   end
  860.   #--------------------------------------------------------------------------
  861.   # * 1 Step Forward
  862.   #--------------------------------------------------------------------------
  863.   def move_forward
  864.     case @direction
  865.     when 2
  866.       move_down(false)
  867.     when 4
  868.       move_left(false)
  869.     when 6
  870.       move_right(false)
  871.     when 8
  872.       move_up(false)
  873.     end
  874.   end
  875.   #--------------------------------------------------------------------------
  876.   # * 1 Step Backward
  877.   #--------------------------------------------------------------------------
  878.   def move_backward
  879.     # Remember direction fix situation
  880.     last_direction_fix = @direction_fix
  881.     # Force directino fix
  882.     @direction_fix = true
  883.     # Branch by direction
  884.     case @direction
  885.     when 2  # Down
  886.       move_up(false)
  887.     when 4  # Left
  888.       move_right(false)
  889.     when 6  # Right
  890.       move_left(false)
  891.     when 8  # Up
  892.       move_down(false)
  893.     end
  894.     # Return direction fix situation back to normal
  895.     @direction_fix = last_direction_fix
  896.   end
  897.   #--------------------------------------------------------------------------
  898.   # * Jump
  899.   #     x_plus : x-coordinate plus value
  900.   #     y_plus : y-coordinate plus value
  901.   #--------------------------------------------------------------------------
  902.   def jump(x_plus, y_plus)
  903.     # If plus value is not (0,0)
  904.     if x_plus != 0 or y_plus != 0
  905.       # If horizontal distnace is longer
  906.       if x_plus.abs > y_plus.abs
  907.         # Change direction to left or right
  908.         x_plus < 0 ? turn_left : turn_right
  909.       # If vertical distance is longer, or equal
  910.       else
  911.         # Change direction to up or down
  912.         y_plus < 0 ? turn_up : turn_down
  913.       end
  914.     end
  915.     # Calculate new coordinates
  916.     new_x = @x + x_plus
  917.     new_y = @y + y_plus
  918.     # If plus value is (0,0) or jump destination is passable
  919.     if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
  920.       # Straighten position
  921.       straighten
  922.       # Update coordinates
  923.       @x = new_x
  924.       @y = new_y
  925.       # Calculate distance
  926.       distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
  927.       # Set jump count
  928.       @jump_peak = 10 + distance - @move_speed
  929.       @jump_count = @jump_peak * 2
  930.       # Clear stop count
  931.       @stop_count = 0
  932.     end
  933.   end
  934.   #--------------------------------------------------------------------------
  935.   # * Turn Down
  936.   #--------------------------------------------------------------------------
  937.   def turn_down
  938.     unless @direction_fix
  939.       @direction = 2
  940.       @stop_count = 0
  941.     end
  942.   end
  943.   #--------------------------------------------------------------------------
  944.   # * Turn Left
  945.   #--------------------------------------------------------------------------
  946.   def turn_left
  947.     unless @direction_fix
  948.       @direction = 4
  949.       @stop_count = 0
  950.     end
  951.   end
  952.   #--------------------------------------------------------------------------
  953.   # * Turn Right
  954.   #--------------------------------------------------------------------------
  955.   def turn_right
  956.     unless @direction_fix
  957.       @direction = 6
  958.       @stop_count = 0
  959.     end
  960.   end
  961.   #--------------------------------------------------------------------------
  962.   # * Turn Up
  963.   #--------------------------------------------------------------------------
  964.   def turn_up
  965.     unless @direction_fix
  966.       @direction = 8
  967.       @stop_count = 0
  968.     end
  969.   end
  970.   #--------------------------------------------------------------------------
  971.   # * Turn 90° Right
  972.   #--------------------------------------------------------------------------
  973.   def turn_right_90
  974.     case @direction
  975.     when 2
  976.       turn_left
  977.     when 4
  978.       turn_up
  979.     when 6
  980.       turn_down
  981.     when 8
  982.       turn_right
  983.     end
  984.   end
  985.   #--------------------------------------------------------------------------
  986.   # * Turn 90° Left
  987.   #--------------------------------------------------------------------------
  988.   def turn_left_90
  989.     case @direction
  990.     when 2
  991.       turn_right
  992.     when 4
  993.       turn_down
  994.     when 6
  995.       turn_up
  996.     when 8
  997.       turn_left
  998.     end
  999.   end
  1000.   #--------------------------------------------------------------------------
  1001.   # * Turn 180°
  1002.   #--------------------------------------------------------------------------
  1003.   def turn_180
  1004.     case @direction
  1005.     when 2
  1006.       turn_up
  1007.     when 4
  1008.       turn_right
  1009.     when 6
  1010.       turn_left
  1011.     when 8
  1012.       turn_down
  1013.     end
  1014.   end
  1015.   #--------------------------------------------------------------------------
  1016.   # * Turn 90° Right or Left
  1017.   #--------------------------------------------------------------------------
  1018.   def turn_right_or_left_90
  1019.     if rand(2) == 0
  1020.       turn_right_90
  1021.     else
  1022.       turn_left_90
  1023.     end
  1024.   end
  1025.   #--------------------------------------------------------------------------
  1026.   # * Turn at Random
  1027.   #--------------------------------------------------------------------------
  1028.   def turn_random
  1029.     case rand(4)
  1030.     when 0
  1031.       turn_up
  1032.     when 1
  1033.       turn_right
  1034.     when 2
  1035.       turn_left
  1036.     when 3
  1037.       turn_down
  1038.     end
  1039.   end
  1040.   #--------------------------------------------------------------------------
  1041.   # * Turn Towards Player
  1042.   #--------------------------------------------------------------------------
  1043.   def turn_toward_player
  1044.     # Get difference in player coordinates
  1045.     sx = @x - getActiveChar.x
  1046.     sy = @y - getActiveChar.y
  1047.     # If coordinates are equal
  1048.     if sx == 0 and sy == 0
  1049.       return
  1050.     end
  1051.     # If horizontal distance is longer
  1052.     if sx.abs > sy.abs
  1053.       # Turn to the right or left towards player
  1054.       sx > 0 ? turn_left : turn_right
  1055.     # If vertical distance is longer
  1056.     else
  1057.       # Turn up or down towards player
  1058.       sy > 0 ? turn_up : turn_down
  1059.     end
  1060.   end
  1061.   #--------------------------------------------------------------------------
  1062.   # * Turn Away from Player
  1063.   #--------------------------------------------------------------------------
  1064.   def turn_away_from_player
  1065.     # Get difference in player coordinates
  1066.     sx = @x - getActiveChar.x
  1067.     sy = @y - getActiveChar.y
  1068.     # If coordinates are equal
  1069.     if sx == 0 and sy == 0
  1070.       return
  1071.     end
  1072.     # If horizontal distance is longer
  1073.     if sx.abs > sy.abs
  1074.       # Turn to the right or left away from player
  1075.       sx > 0 ? turn_right : turn_left
  1076.     # If vertical distance is longer
  1077.     else
  1078.       # Turn up or down away from player
  1079.       sy > 0 ? turn_down : turn_up
  1080.     end
  1081.   end
  1082. end
Expand to see the code.


This is PlayableCharacter
  1. class Playable_Character < NonPlayable_Character
  2.  
  3.   attr_reader   :equipped                 # equipped items
  4.   attr_reader   :name                     # Character's name
  5.   attr_reader   :can_play                 # Playability flag
  6.   attr_reader   :wallet_size
  7.   attr_reader   :steps    
  8.   attr_reader   :max_health
  9.   attr_reader   :health
  10.   attr_reader   :max_energy
  11.   attr_accessor :energy
  12.   attr_accessor :defending
  13.   attr_accessor :multiplier
  14.   attr_accessor :items
  15.   attr_accessor :key_items
  16.   attr_accessor :gold
  17.   attr_accessor :sprinting
  18.  
  19.   CENTER_X = (($WIDTH/2) - 16) * 4   # Center screen x-coordinate * 4
  20.   CENTER_Y = (($HEIGHT/2) - 16) * 4   # Center screen y-coordinate * 4
  21.  
  22.    def initialize(name,graphic)    
  23.      super(graphic)
  24.      @id=-1
  25.      @name=name
  26.      @equipped = ["",""]
  27.      @can_play = true
  28.      @max_health = 5
  29.      @health = 500
  30.      @max_energy = 20
  31.      @energy = 2000.0
  32.      @defending = false
  33.      @multiplier = 1
  34.      @absolute_max = 16
  35.      @inventory_size = 20
  36.      @items = {}
  37.      @key_items = {}
  38.      @gold = 0
  39.      @wallet_size=99
  40.      @sprinting=false
  41.      @steps=0
  42.    end
  43.    
  44.   def add_heart(amt=1,heal=true)
  45.     @max_health=[@max_health+amt,@absolute_max].min
  46.     @health=@max_health*100
  47.     $scene.spriteset.huds.health.update
  48.   end
  49.  
  50.   def increase_wallet(amt)
  51.     @wallet_size+=amt
  52.   end
  53.    
  54. #-------------------------------------------------------------------------------
  55. # Battle System methods
  56. #-------------------------------------------------------------------------------
  57.    def equip(side, item) #outdated
  58.      last_equip=@equipped
  59.      if side==0 # A
  60.        @equipped[0]=item
  61.        @equipped[1]=last_equip[0] if @equipped[1]==item
  62.      elsif side==1 # S
  63.        @equipped[1]=item
  64.        @equipped[0]=last_equip[1] if @equipped[0]==item
  65.      end
  66.    end
  67.    
  68.    def unequip(side)
  69.      if side<0
  70.        @equipped[0]=""
  71.      elsif side>0
  72.        @equipped[1]=""
  73.      end
  74.    end
  75.  
  76.  
  77.   def hurt(dmg)
  78.     @health=[@health-dmg,0].max
  79.     $scene.spriteset.huds.health.update
  80.     die if @health==0
  81.   end
  82.  
  83.   def heal(amt)
  84.     @health=[@health+amt,@max_health*100].min
  85.   end  
  86.    
  87. #-------------------------------------------------------------------------------
  88. # Gold/Inventory management
  89. #-------------------------------------------------------------------------------  
  90.    def gain_item(item_id, n)
  91.     # Update quantity data in the hash.
  92.    if @items.keys.size==@inventory_size
  93.     unless @items.keys.include?(item_id)
  94.     $scene.notify("#{$game_system.active_char}'s inventory is full.", "XXX-ErrorX") if $scene.is_a?(Scene_Map)
  95.     return
  96.     end
  97.    end
  98.     if item_id > 0
  99.      @items[item_id] = [[item_number(item_id) + n, 0].max, 99].min
  100.      $scene.notify("Found #{n}x #{$data_items[item_id].name}.",$data_items[item_id].icon_name) if $scene.is_a?(Scene_Map)
  101.     end
  102.    end # gain_item
  103.  
  104.    def lose_item(item_id, n)
  105.     # Reverse the numerical value and call it gain_item
  106.     gain_item(item_id, -n)
  107.    end
  108.  
  109.    def item_number(item_id)
  110.     # If quantity data is in the hash, use it. If not, return 0
  111.     return @items.include?(item_id) ? @items[item_id] : 0
  112.   end  
  113.  
  114. #-------------------------------------------------------------------------------
  115. # Movement
  116. #-------------------------------------------------------------------------------
  117.   def passable?(x, y, d)
  118.     # Get new coordinates
  119.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  120.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  121.     # If coordinates are outside of map
  122.     unless $game_map.valid?(new_x, new_y)
  123.       # Impassable
  124.       return false
  125.     end
  126.     # If debug mode is ON and ctrl key was pressed
  127.     if $DEBUG and Input.press?(Input::CTRL)
  128.       # Passable
  129.       return true
  130.     end
  131.     super
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # * Set Map Display Position to Center of Screen
  135.   #--------------------------------------------------------------------------
  136.   def center(x, y)
  137.     max_x = ($game_map.width - 20) * 128
  138.     max_y = ($game_map.height - 15) * 128
  139.     $game_map.display_x = [0, [x * 128 - CENTER_X, max_x].min].max
  140.     $game_map.display_y = [0, [y * 128 - CENTER_Y, max_y].min].max
  141.   end
  142.   #--------------------------------------------------------------------------
  143.   # * Move to Designated Position
  144.   #     x : x-coordinate
  145.   #     y : y-coordinate
  146.   #--------------------------------------------------------------------------
  147.   def moveto(x, y)
  148.     super
  149.     center(x, y)
  150.   end
  151.   #--------------------------------------------------------------------------
  152.   # * Increase Steps
  153.   #--------------------------------------------------------------------------
  154.   def increase_steps
  155.     super
  156.     @steps+=1
  157.     unless @move_route_forcing
  158.       # Number of steps are an even number
  159.       if @steps % 2 == 0
  160.         #slip damage every other step
  161.       end
  162.     end
  163.    end
  164.   #--------------------------------------------------------------------------
  165.   # * Same Position Starting Determinant
  166.   #--------------------------------------------------------------------------
  167.   def check_event_trigger_here(triggers)
  168.     result = false
  169.     # If event is running
  170.     if $game_system.map_interpreter.running?
  171.       return result
  172.     end
  173.     # All event loops
  174.     for event in $game_map.events.values
  175.       # If event coordinates and triggers are consistent
  176.       if event.x == @x and event.y == @y and triggers.include?(event.trigger)
  177.         # If starting determinant is same position event (other than jumping)
  178.         if not event.jumping? and event.over_trigger?
  179.           event.start
  180.           result = true
  181.         end
  182.       end
  183.     end
  184.     return result
  185.   end
  186.   #--------------------------------------------------------------------------
  187.   # * Front Envent Starting Determinant
  188.   #--------------------------------------------------------------------------
  189.   def check_event_trigger_there(triggers)
  190.     result = false
  191.     # If event is running
  192.     if $game_system.map_interpreter.running?
  193.       return result
  194.     end
  195.     # Calculate front event coordinates
  196.     new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  197.     new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  198.     # All event loops
  199.     for event in $game_map.events.values
  200.       # If event coordinates and triggers are consistent
  201.       if event.x == new_x and event.y == new_y and
  202.          triggers.include?(event.trigger)
  203.         # If starting determinant is front event (other than jumping)
  204.         if not event.jumping? and not event.over_trigger?
  205.           event.start
  206.           result = true
  207.         end
  208.       end
  209.     end
  210.     # If fitting event is not found
  211.     if result == false
  212.       # If front tile is a counter
  213.       if $game_map.counter?(new_x, new_y)
  214.         # Calculate 1 tile inside coordinates
  215.         new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  216.         new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  217.         # All event loops
  218.         for event in $game_map.events.values
  219.           # If event coordinates and triggers are consistent
  220.           if event.x == new_x and event.y == new_y and
  221.              triggers.include?(event.trigger)
  222.             # If starting determinant is front event (other than jumping)
  223.             if not event.jumping? and not event.over_trigger?
  224.               event.start
  225.               result = true
  226.             end
  227.           end
  228.         end
  229.       end
  230.     end
  231.     return result
  232.   end
  233.   #--------------------------------------------------------------------------
  234.   # * Touch Event Starting Determinant
  235.   #--------------------------------------------------------------------------
  236.   def check_event_trigger_touch(x, y)
  237.     result = false
  238.     # If event is running
  239.     if $game_system.map_interpreter.running?
  240.       return result
  241.     end
  242.     # All event loops
  243.     for event in $game_map.events.values
  244.       # If event coordinates and triggers are consistent
  245.       if event.x == x and event.y == y and [1,2].include?(event.trigger)
  246.         # If starting determinant is front event (other than jumping)
  247.         if not event.jumping? and not event.over_trigger?
  248.           event.start
  249.           result = true
  250.         end
  251.       end
  252.     end
  253.     return result
  254.   end
  255.  
  256.  
  257.  
  258.   #--------------------------------------------------------------------------
  259.   # * Frame Update
  260.   #--------------------------------------------------------------------------
  261.   def update
  262.     # If player is sprinting
  263.     if @sprinting
  264.       unless @energy<=0
  265.        @energy-=10 if moving? # reduce energy if moving
  266.       end
  267.      else # restore
  268.       unless @energy.to_i>=@max_energy*100
  269.        @energy+=2.5
  270.        @energy+=1 unless moving? # restore bonus if standing still
  271.       end
  272.     end
  273.     # set energy to max if it crossed it
  274.     if @energy.to_i > @max_energy*100
  275.       @energy = @max_energy*100
  276.     end
  277.    
  278.     # While pressing SHIFT enter sprinting mode if enough energy available
  279.      if Input.press?(Input::SHIFT) && moving?
  280.        if @energy>2.5
  281.         @sprinting=true
  282.         @move_speed=5
  283.       else
  284.         @move_speed=4
  285.         @sprinting=false
  286.        end
  287.      else
  288.       @sprinting=false
  289.       @move_speed=4
  290.     end
  291.    
  292.     # Remember whether or not moving in local variables
  293.     last_moving = moving?
  294.     # If moving, event running, move route forcing, and message window
  295.     # display are all not occurring
  296.     unless moving? or $game_system.map_interpreter.running? or
  297.            @move_route_forcing or $game_temp.message_window_showing
  298.       # Move player in the direction the directional button is being pressed
  299.       case Input.dir4
  300.       when 2
  301.         move_down
  302.       when 4
  303.         move_left
  304.       when 6
  305.         move_right
  306.       when 8
  307.         move_up
  308.       end
  309.     end
  310.     # Remember coordinates in local variables
  311.     last_real_x = @real_x
  312.     last_real_y = @real_y
  313.     super
  314.     # If character moves down and is positioned lower than the center
  315.     # of the screen
  316.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  317.       # Scroll map down
  318.       $game_map.scroll_down(@real_y - last_real_y)
  319.     end
  320.     # If character moves left and is positioned more let on-screen than
  321.     # center
  322.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  323.       # Scroll map left
  324.       $game_map.scroll_left(last_real_x - @real_x)
  325.     end
  326.     # If character moves right and is positioned more right on-screen than
  327.     # center
  328.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  329.       # Scroll map right
  330.       $game_map.scroll_right(@real_x - last_real_x)
  331.     end
  332.     # If character moves up and is positioned higher than the center
  333.     # of the screen
  334.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  335.       # Scroll map up
  336.       $game_map.scroll_up(last_real_y - @real_y)
  337.     end
  338.     # If not moving
  339.     unless moving?
  340.       # If player was moving last time
  341.       if last_moving
  342.         # Event determinant is via touch of same position event
  343.         result = check_event_trigger_here([1,2])
  344.         if result == false
  345.           # Disregard if debug mode is ON and ctrl key was pressed
  346.           unless $DEBUG and Input.press?(Input::CTRL)
  347.            #
  348.           end
  349.         end
  350.        
  351.       end
  352.       # If C button was pressed
  353.       if Input.trigger?(Input::C)
  354.         # Same position and front event determinant
  355.         check_event_trigger_here([0])
  356.         check_event_trigger_there([0,1,2])
  357.       end
  358.     end
  359.    
  360.   end # update
  361. end
Expand to see the code.


The idea is i have a hash in Game_System which stores all the playable characters, and their respective inventories, gold, etcetc. the hash looks like this:
  1.  
  2. @played_characters = {
  3. "character's name" => <0xPlayableCharacter....>,
  4. "character2's name" =><0xPlayableCharacter....> }  
  5.  
Expand to see the code.

so then I have the following method to return the active player object
  1.  
  2.  def getActiveChar
  3.   return $game_system.played_characters[$game_system.active_char]
  4.  end
  5.  
Expand to see the code.

So basicly $game_player and getActiveChar are the same, except the Playable_Character class getActiveChar returns has more methods and attributes.



So that's the issue, the events above were working properly before. My question is, would there be a way to fix this problem, preferably not involving having to switch back to Game_Player and Game_Character?
My initial thoughts were that event handling may have suffered from the switch I made, not doing the trigger or ending detections properly, but now I don't really think that is the case.

I really hope someone has an idea of what could be the issue. If you should need more information or if I should post another script, please just ask.

Thanks in advance! 🙂

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=77572