Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Player Touch trigger? [Resolved]

EDIT: RESOLVED.
I will probably make a post to help others with the same problem. Sometime. Now I have to celebrate.



Messing around with pixelmovement in the Moving Platform script, I noticed a problem: when you set a passable event to Player Touch, the event commands do not execute.

I believe (correct me if I'm wrong) the player touch trigger refers to check_event_trigger_here. However, this does not seem to activate do to a strange error with last_moving not being set correctly.

The RGSS (only relevant chunks, including self edits) are below.
Code:
 

class Game_Player < Game_Character

  def check_event_trigger_here(triggers)

    result = false

    if $game_system.map_interpreter.running?

      return result

    end

    for event in $game_map.events.values

      m = ((((((event.real_x).to_f)/128)*8).to_i).to_f)/8

      n = ((((((event.real_y).to_f)/128)*8).to_i).to_f)/8

      if (m - 0.749 <= @x) and (m + 0.749 >= @x) and (n - 0.999 <= @y) and

        (n + 0.374 >= @y) and triggers.include?(event.trigger) and

        not event.jumping? and event.over_trigger?

        if $game_variables[50] != event.id # for testing purposes only

          event.start # will replace variable 50 with class variable

          $game_variables[50] = event.id

          result = true

        else

          $game_variables[50] = 0

        end

      end

    end

    return result

  end

  #--------------------------------------------------------------------------

  def check_event_trigger_there(triggers)

    result = false

    if $game_system.map_interpreter.running?

      return result

    end

    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

    for event in $game_map.events.values

      m = ((((((event.real_x).to_f)/128)*8).to_i).to_f)/8

      n = ((((((event.real_y).to_f)/128)*8).to_i).to_f)/8

      if (m - 0.749 <= new_x) and (m + 0.749 >= new_x) and (n - 0.999 <= new_y) and

        (n + 0.374 >= new_y) and triggers.include?(event.trigger)

        if not event.jumping? and not event.over_trigger?

          event.start

          result = true

        end

      end

    end

    if result == false

      if $game_map.counter?(new_x, new_y)

        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

        for event in $game_map.events.values

          m = ((((((event.real_x).to_f)/128)*8).to_i).to_f)/8

          n = ((((((event.real_y).to_f)/128)*8).to_i).to_f)/8

          if (m - 0.749 <= new_x) and (m + 0.749 >= new_x) and (n - 0.999 <= new_y) and

            (n + 0.374 >= new_y) and triggers.include?(event.trigger)

            if not event.jumping? and not event.over_trigger?

              event.start

              result = true

            end

          end

        end

      end

    end

    return result

  end

  #--------------------------------------------------------------------------

  def check_event_trigger_touch(x, y)

    result = false

    if $game_system.map_interpreter.running?

      return result

    end

    for event in $game_map.events.values

      m = ((((((event.real_x).to_f)/128)*8).to_i).to_f)/8

      n = ((((((event.real_y).to_f)/128)*8).to_i).to_f)/8

      if (m - 0.749 <= x) and (m + 0.749 >= x) and (n - 0.999 <= y) and

        (n + 0.374 >= y) and [1,2].include?(event.trigger)

        if not event.jumping? and not event.over_trigger?

          event.start

          result = true

        end

      end

    end

    return result

  end

  #--------------------------------------------------------------------------

 

  def update

    unless moving? or $game_system.map_interpreter.running? or

      @move_route_forcing or $game_temp.message_window_showing

        case Input.dir8

        when 2

          move_down

        when 4

          move_left

        when 6

          move_right

        when 8

          move_up

        when 1

          move_lower_left

        when 3

          move_lower_right

        when 7

          move_upper_left

        when 9

          move_upper_right

      end

    end

    last_real_x = @real_x

    last_real_y = @real_y

    super

    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y

      $game_map.scroll_down(@real_y - last_real_y)

    end

    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X

      $game_map.scroll_left(last_real_x - @real_x)

    end

    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X

      $game_map.scroll_right(@real_x - last_real_x)

    end

    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y

      $game_map.scroll_up(last_real_y - @real_y)

    end

    unless moving?

      if @x.to_i != $game_variables[8] or @y.to_i != $game_variables[9]

        result = check_event_trigger_here([1,2])

      end

      if Input.trigger?(Input::C) 

        return false if self.action != nil

        check_event_trigger_here([0])

        check_event_trigger_there([0,1,2])

      end

    end

    $game_variables[8] = @x.to_i # Player Map X

    $game_variables[9] = @y.to_i # Player Map Y

  end

  #--------------------------------------------------------------------------

end

Thanks for any assistance.
 

Star

Sponsor

I noticed this as well, I'm working on a platformer game that uses that same exact script. If you do find a solution or someone else please post it here so it can help me out. In the mean time Regi, I figured a way around it just by asking for players x and y in variables and using conditional branches to certain coordinates. But that in itself is a pain in the arse.
 
Ah, that's a nice workaround, though I'd still prefer to solve this scriptwise.

I think I narrowed it down to check_event_trigger_here(1), though I'm not sure why it doesn't seem to be working. I'll put the chunk of code in the first post.
 

Star

Sponsor

Maybe it's not registering that the event.over_trigger? It might be possible that the method call gets interrupted due to the pixelmovement script because it's not exactly over it.

Oh btw I also noticed that event touch doesn't work when the event has a graphic, it might be related to that. But when you don't have a graphic it works fine.
 
I looked at the default scripts and over_trigger? just checks if an event is through/passable.

I did a few more tests and it seems like check_event_trigger_here isn't even being called. The only two places in the default code are if you press C (Action Button) and after you move, but that merely lowers the encounter count and nothing else, which is very puzzling.
 

Star

Sponsor

Found it. Look for Def Touch in the Platform script and change it to this

Code:
  def touch?(mode = 0)

    if mode == 0

        check_event_trigger_touch(@x, @y)

    else

        check_event_trigger_touch(@x, @y)

    end

    end
 

Star

Sponsor

BubblesVonSalamancer":3qmvc5ge said:
Are you using a different version? Because I can't seem to find that in my script.
Oh crap, I thought it was the PlatFORMER script I was working with. I got confused, but it had the same exact problem with it. I want to help you with the rest of it since you helped me work out my problem, but I can't find the script you're working with since that demo is downloadable anymore.

viewtopic.php?f=11&t=68686&hilit=Platform+Move
 

Star

Sponsor

BubblesVonSalamancer":3ctaznrq said:
Ah don't worry about it. Since the demo link's down, I posted the relevant sections of the script in the first post, if you'd like to take a look anyway.
I put the relevant script in there, and I got Player touch to work fine with a graphic. Without a graphic it was no go.

so with some minor commenting out and a few changed moving the method call check event touch around I managed to get it working for you

Code:
 

class Game_Player < Game_Character

  def check_event_trigger_here(triggers)

    result = false

    if $game_system.map_interpreter.running?

      return result

    end

    for event in $game_map.events.values

      m = ((((((event.real_x).to_f)/128)*8).to_i).to_f)/8

      n = ((((((event.real_y).to_f)/128)*8).to_i).to_f)/8

      if (m - 0.749 <= @x) and (m + 0.749 >= @x) and (n - 0.999 <= @y) and

        (n + 0.374 >= @y) and triggers.include?(event.trigger)

        if not event.jumping? and event.over_trigger?

          event.start

          result = true

        end

      end

    end

    return result

  end

  #--------------------------------------------------------------------------

  def check_event_trigger_there(triggers)

    result = false

    if $game_system.map_interpreter.running?

      return result

    end

    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

    for event in $game_map.events.values

      m = ((((((event.real_x).to_f)/128)*8).to_i).to_f)/8

      n = ((((((event.real_y).to_f)/128)*8).to_i).to_f)/8

      if (m - 0.749 <= new_x) and (m + 0.749 >= new_x) and (n - 0.999 <= new_y) and

        (n + 0.374 >= new_y) and triggers.include?(event.trigger)

        if not event.jumping? and not event.over_trigger?

          event.start

          result = true

        end

      end

    end

    if result == false

      if $game_map.counter?(new_x, new_y)

        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

        for event in $game_map.events.values

          m = ((((((event.real_x).to_f)/128)*8).to_i).to_f)/8

          n = ((((((event.real_y).to_f)/128)*8).to_i).to_f)/8

          if (m - 0.749 <= new_x) and (m + 0.749 >= new_x) and (n - 0.999 <= new_y) and

            (n + 0.374 >= new_y) and triggers.include?(event.trigger)

            if not event.jumping? and not event.over_trigger?

              event.start

              result = true

            end

          end

        end

      end

    end

    return result

  end

  #--------------------------------------------------------------------------

  def check_event_trigger_touch(x, y)

    result = false

    if $game_system.map_interpreter.running?

      return result

    end

    for event in $game_map.events.values

      m = ((((((event.real_x).to_f)/128)*8).to_i).to_f)/8

      n = ((((((event.real_y).to_f)/128)*8).to_i).to_f)/8

      if (m - 0.749 <= x) and (m + 0.749 >= x) and (n - 0.999 <= y) and

        (n + 0.374 >= y) and [1,2].include?(event.trigger)

       # if not event.jumping? and not event.over_trigger?

          event.start

          result = true

       # end

      end

    end

    return result

  end

  #--------------------------------------------------------------------------

 

  def update

    last_moving = moving? # last_moving always returns false for some reason

    unless moving? or $game_system.map_interpreter.running? or

      @move_route_forcing or $game_temp.message_window_showing

        case Input.dir8

        when 2

          move_down

        when 4

          move_left

        when 6

          move_right

        when 8

          move_up

        when 1

          move_lower_left

        when 3

          move_lower_right

        when 7

          move_upper_left

        when 9

          move_upper_right

      end

    end

    last_real_x = @real_x

    last_real_y = @real_y

    super

    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y

      $game_map.scroll_down(@real_y - last_real_y)

    end

    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X

      $game_map.scroll_left(last_real_x - @real_x)

    end

    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X

      $game_map.scroll_right(@real_x - last_real_x)

    end

    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y

      $game_map.scroll_up(last_real_y - @real_y)

    end

    unless moving?

      if last_moving # no result, because always false

        result = check_event_trigger_here([1,2])

      end

      if Input.trigger?(Input::C)

        return false if self.action != nil

        check_event_trigger_here([0])

        check_event_trigger_there([0,1,2])

      end

    end

  end

 

  #--------------------------------------------------------------------------

  def move_down(turn_enabled = true)

    a = 1.0

    if @direction == 2 and dir_passable?(@x, @y, 2)

      turn_down

      @y += a/8

      increase_steps

   # else

      check_event_trigger_touch(@x, @y+1)

    end

    if turn_enabled and @direction != 2

      turn_down

    end

  end

  #--------------------------------------------------------------------------

  def move_left(turn_enabled = true)

    a = 1.0

    if @direction == 4 and dir_passable?(@x, @y, 4)

      turn_left

      @x -= a/8

      increase_steps

    #else

      check_event_trigger_touch(@x-1, @y)

    end

    if turn_enabled and @direction != 4

      turn_left

    end

  end

  #--------------------------------------------------------------------------

  def move_right(turn_enabled = true)

    a = 1.0

    if @direction == 6 and dir_passable?(@x, @y, 6)

      turn_right

      @x += a/8

      increase_steps

    #else

      check_event_trigger_touch(@x+1, @y)

    end

    if turn_enabled and @direction != 6

      turn_right

    end

  end

  #--------------------------------------------------------------------------

  def move_up(turn_enabled = true)

    a = 1.0

    if @direction == 8 and dir_passable?(@x, @y, 8)

      turn_up

      @y -= a/8

      increase_steps

   # else

      check_event_trigger_touch(@x, @y-1)

    end

    if turn_enabled and @direction != 8

      turn_up

    end

  end

  #--------------------------------------------------------------------------

  def move_lower_left(turn_enabled = true)

    a = 1.0

    if (@direction == 2 or @direction == 4) and dir_passable?(@x, @y, 2) and

       dir_passable?(@x, @y, 4)

      @y += a/(8*Math.sqrt(2))

      @x -= a/(8*Math.sqrt(2))

      increase_steps

      check_event_trigger_touch(@x-1, @y+1)

    elsif dir_passable?(@x, @y, 4)

      move_left

    elsif dir_passable?(@x, @y, 2)

      move_down

   # else

      

    end

    if turn_enabled and @direction != 2 and @direction != 4

      turn_down

    end

  end

  #--------------------------------------------------------------------------

  def move_lower_right(turn_enabled = true)

    a = 1.0

    if (@direction == 2 or @direction == 6) and dir_passable?(@x, @y, 2) and

       dir_passable?(@x, @y, 6)

      @y += a/(8*Math.sqrt(2))

      @x += a/(8*Math.sqrt(2))

      increase_steps

      check_event_trigger_touch(@x+1, @y+1)

    elsif dir_passable?(@x, @y, 6)

      move_right

    elsif dir_passable?(@x, @y, 2)

      move_down

   # else

      

    end

    if turn_enabled and @direction != 2 and @direction != 6

      turn_right

    end

  end

  #--------------------------------------------------------------------------

  def move_upper_left(turn_enabled = true)

    a = 1.0

    if (@direction == 4 or @direction == 8) and dir_passable?(@x, @y, 4) and

       dir_passable?(@x, @y, 8)

      @y -= a/(8*Math.sqrt(2))

      @x -= a/(8*Math.sqrt(2))

      increase_steps

      check_event_trigger_touch(@x-1, @y-1)

    elsif dir_passable?(@x, @y, 8)

      move_up

    elsif dir_passable?(@x, @y, 4)

      move_left

   # else

      

    end

    if turn_enabled and @direction != 4 and @direction != 8

      turn_left

    end

  end

  #--------------------------------------------------------------------------

  def move_upper_right(turn_enabled = true)

    a = 1.0

    if (@direction == 6 or @direction == 8) and dir_passable?(@x, @y, 6) and

       dir_passable?(@x, @y, 8)

      @y -= a/(8*Math.sqrt(2))

      @x += a/(8*Math.sqrt(2))

      increase_steps

      check_event_trigger_touch(@x+1, @y-1)

    elsif dir_passable?(@x, @y, 8)

      move_up

    elsif dir_passable?(@x, @y, 6)

      move_right

   # else

      

    end

    if turn_enabled and @direction != 6 and @direction != 8

      turn_up

    end

  end

  #--------------------------------------------------------------------------

  def turn_down

    unless @direction_fix

      @direction = 2

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_left

    unless @direction_fix

      @direction = 4

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_right

    unless @direction_fix

      @direction = 6

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_up

    unless @direction_fix

      @direction = 8

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def dir_passable?(x, y, d)

    case d

    when 2

      if passable?(x, y+0.125, 2) and event_passable?(x, y+0.125, 2) and

         passable?(x+0.250, y+0.125, 2) and passable?(x-0.250, y+0.125, 2)

        return true

      end

    when 4

      if passable?(x, y, 4) and passable?(x, y+0.500, 4) and

         event_passable?(x, y, 4)

        return true

      end

    when 6

      if passable?(x, y, 6) and passable?(x, y+0.500, 6) and

         event_passable?(x, y, 6)

        return true

      end

    when 8

      if passable?(x, y, 8) and event_passable?(x, y, 8) and

         passable?(x+0.250, y, 8) and passable?(x-0.250, y, 8)

        return true

      end

    end

    return false

  end

  #--------------------------------------------------------------------------

  def passable?(x, y, d)

    case d

    when 6

      unless $game_map.valid?(x+0.125, y)

        return false

      end

      new_x = x + 1.0/8

      new_x = (new_x+0.750).to_i

      new_y = (y+0.5).to_i

    when 4

      unless $game_map.valid?(x-0.125, y)

        return false

      end

      new_x = x - 1.0/8

      new_x = (new_x+0.125).to_i

      new_y = (y+0.5).to_i

    when 2

      unless $game_map.valid?(x+0.250, y+0.125)

        return false

      end

      new_y = y + 1.0/8

      new_y = (new_y+0.875).to_i

      new_x = (x+0.5).to_i

    when 8

      unless $game_map.valid?(x+0.250, y-0.125)

        return false

      end

      new_y = y - 1.0/8

      new_y = (new_y+0.500).to_i

      new_x = (x+0.5).to_i

    else

      new_x = (x+0.5).to_i

      new_y = (y+0.5).to_i

    end

    x = (x+0.5).to_i

    y = (y+0.5).to_i

    if @through

      return true

    end

    if $DEBUG and Input.press?(Input::CTRL)

      return true

    end

    unless $game_map.passable_platform?(x, y, new_x, new_y, d, self)

      return false

    end

    unless $game_map.passable_platform?(new_x, new_y, x, y, 10 - d)

      return false

    end

    return true

  end

  #--------------------------------------------------------------------------

  def event_passable?(x, y, d)

    case d

    when 6

      unless $game_map.valid?(x+0.125, y)

        return false

      end

      new_x = x + 1.0/8

      new_y = y

    when 4

      unless $game_map.valid?(x-0.125, y)

        return false

      end

      new_x = x - 1.0/8

      new_y = y

    when 2

      unless $game_map.valid?(x+0.250, y+0.125)

        return false

      end

      new_y = y + 1.0/8

      new_x = x

    when 8

      unless $game_map.valid?(x+0.250, y-0.125)

        return false

      end

      new_y = y - 1.0/8

      new_x = x

    else

      new_x = x

      new_y = y

    end

    if $DEBUG and Input.press?(Input::CTRL)

      return true

    end

    for event in $game_map.events.values

      m = ((((((event.real_x).to_f)/128)*8).to_i).to_f)/8

      n = ((((((event.real_y).to_f)/128)*8).to_i).to_f)/8

      if (m - 0.750 <= new_x) and (m + 0.750 >= new_x) and

        (n - 0.875 <= new_y) and (n + 0.375 >= new_y)

        unless event.through

          if self != $game_player

            return false

          end

          if event.character_name != ""

            return false

          end

        end

      end

    end

    return true

  end

  #--------------------------------------------------------------------------

end
 
I appreciate the effort but that didn't do quite what I was looking for. The way the code was set up, check_event_trigger_touch checked for events in front of the player, rather than sharing the same tile, which is why I need check_event_trigger_here to work instead.

I have a solution, I just can't get it to work right. Adding to the main post right now.
 

Star

Sponsor

I think it always returns false because it might be written well.

I'm assuming check_event_trigger 0 means action button 1 means player touch and 2 means event touch

If last moving = moving?

And then it asks. Unless moving? Which means do this if not moving

if last moving which means do this if moving

I think that's why it's not activating, maybe it's not necessary to check if they are moving, if you removed those would it work then?

like this

# unless moving?
# if last_moving # no result, because always false

result = check_event_trigger_here([1,2])
check_event_trigger_there([1,2])
# end
unless moving? # checking if moving here seems more logical. Since this are for action
if Input.trigger?(Input::C)
return false if self.action != nil
check_event_trigger_here([0])
check_event_trigger_there([0]) #except I don't think check event trigger there 1 and 2 should be stopped if your moving
end
end
 
But that would check for the trigger practically every frame, which means the event would loop endlessly, not allowing the player to move out of the way.

The line last_moving = moving? saves if the player is currently moving. Then, unless moving? checks that the move has finished, and the player stopped moving. The if last_moving is supposed to check if the player just stopped, versus having stayed still for awhile. In theory, it should work fine, but the very first last_moving = moving? appears to return false with no results. That's why I'm looking for a different method to solve this, by checking x and y coordinate changes instead.



EDIT: DONE! Thanks for the help. I got it to work by setting a variable when the event activates and resetting it when the player is off the event.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top