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.

PULL an object?

uupa99

Member

I know how to push an object... that is quite easy... but pulling is a different story. Ive tried to mess around with things using my knowledge of RPGXP, but unless I missed something, I can't find a way. Perhaps a script? Or maybe something easy like pushing an object. I'm really not sure.

So please, If someone could tell me how to make an object that you can push also make able to pull (maybe by pressing and/or holding the action key?) then I would greatly appreciate it.
 
Here's a screenshop from an old event of mine. Please ignore the fact that it has 2 other pages. I was attempting to make a Golden Sun style pushable crate, and failed miserably. Anyway, the screen contains all the instyructions you need, all you have to do is change the directions.

pushpull.png
 
Try this (paste below Scene_Debug)
Code:
module Pullable

  Button = Input::SHIFT

  Comment = 'pullable'

end

 

class Game_Event

  attr_reader :pullable

  alias_method :seph_pullableevents_gmevt_refresh, :refresh

  def refresh

    seph_pullableevents_gmevt_refresh

    @pullable = false

    return if @erased || @list == nil

    for ec in @list

      next unless ec.code == 108 || ec.code == 408

      if ec.parameters[0].downcase.include?(Pullable::Comment.downcase)

        @pullable = true

        break

      end

    end

  end

end

 

class Game_Player

  alias_method :seph_pullableevents_gmplyr_init, :initialize

  def initialize

    @pulling_event = false

    seph_pullableevents_gmplyr_init

  end

  alias_method :seph_pullableevents_gmplyr_update, :update

  def update

    seph_pullableevents_gmplyr_update

    if moving? == false && @pulling_event

      @pulling_event = false

      @direction_fix = @pulling_event_fix

    end

    if Input.trigger?(Pullable::Button)

      x, y, d = $game_player.x, $game_player.y, $game_player.direction

      x = d == 4 ? x - 1 : d == 6 ? x + 1 : x

      y = d == 2 ? y + 1 : d == 8 ? y - 1 : y

      for event in $game_map.events.values

        if event.x == x && event.y == y && event.pullable

          @pulling_event = true

          @pulling_event_fix = @direction_fix

          @direction_fix = true

          move_backward

          event.move_toward_player

        end

      end

    end

  end

end

Let me know if that works. To make an event pullable, just use a comment with "pullable" in it.
 

uupa99

Member

Thanks everyone. However, they didn't work for me D:

Glitchfinder, your's for some reason only worked for me to pull the object upward.

SephirothSpawn, yours did nothing. When I pressed shift it gave me an error.
 
uupa99":1q0j2xdx said:
Glitchfinder, your's for some reason only worked for me to pull the object upward.

That's because you have to change the directions if you want it to pull in other directions. If you look, the last command is the start of another set, instead to pull it to the right. I just gave you the command to pull it up, but it's the same kind of thing in any other direction. Oh, and my event also pushes the object as well.
 
I created a push and pull event awhile ago. The coding was pretty similar to Glitchfinder's, with a few changes.

What I did was first set the box to Parallel Processing. Then, set four variables to Player's Map X, Player's Map Y, Event's Map X, Event's Map Y. I then checked if the player was one tile away from the event using the variables, and if the player was facing the box. The rest of the code was the same as the Conditional Branch in Glitch's method, checking which button is pressed and moving the player and box.

There's also a method that doesn't require using variables. When checking the distance between player and event, you can use:
Code:
$game_player.x == $game_map.events[ID].x - 1 and $game_player.y == $game_map.events[ID].y

That checks if the player is one tile left of the event. You'll have to do a bit of adjusting for the other 3 directions.

It's a little complicated, so just tell me if you need me to elaborate.
 
I got Glitch's code to work just fine. You'll wind up with 4 overall conditionals that check what direction you're facing, so his pic is only the first part. You need one each for each direction you face, and potentially 1-4 more nested inside this depending on how much freedom you want to give the player to move the object (I only use 2 for each direction, so that you can only Push or Pull, not drag side to side, but scripting side to side wouldn't take much more).

Seriously though, it works splendidly. Just set every single Move Route (both Event and Player) to Ignore if Impossible, because it can freeze up if you don't. That did happen at first.
 
Nearly Infinite":2ggge6f2 said:
I got Glitch's code to work just fine. You'll wind up with 4 overall conditionals that check what direction you're facing, so his pic is only the first part. You need one each for each direction you face, and potentially 1-4 more nested inside this depending on how much freedom you want to give the player to move the object (I only use 2 for each direction, so that you can only Push or Pull, not drag side to side, but scripting side to side wouldn't take much more).

Seriously though, it works splendidly. Just set every single Move Route (both Event and Player) to Ignore if Impossible, because it can freeze up if you don't. That did happen at first.
I noticed the problem with ingoring impossible moves right after uploading the project. It was a very old project of mine where I was working on some advanced events (this one was an unfinished one intended to be nearly identical to the Golden Sun pushable blocks/crate/etc that you could jump on as well), and I abandoned it a long time ago. I'm just glad I'm of the belief that everything should be saved. That's one of the reasons I need so much space on my computers. Can you believe I've even archived games (and their CDs) that were originally intended for Windows 95? (As well as some stuff that actually goes as far back as the DOS based OSs, which I have to emulate)
 
Hmm, now that I look at it again, your code is a lot simpler and works just as nice as mine :smile: There's only a slight difference, you don't have to hold the action key and you must move within half a second or it won't trigger. But it's still very efficient.

One tiny nitpick though, you should usually avoid "Wait for Move's Completion", using "Wait" frames instead. It's only a problem on maps with events on repeating or long movement paths though, so you don't have to take the suggestion unless that's a problem.
 

uupa99

Member

Glitchfinder":1qgxyc34 said:
uupa99":1qgxyc34 said:
Glitchfinder, your's for some reason only worked for me to pull the object upward.

That's because you have to change the directions if you want it to pull in other directions. If you look, the last command is the start of another set, instead to pull it to the right. I just gave you the command to pull it up, but it's the same kind of thing in any other direction. Oh, and my event also pushes the object as well.

I did do that... that is why I was wondering why it didn't work. Idk, maybe i'm doing someting wrong. If somone can give me a demo of thier script or event that will be all I need probobly. I can just work with it from their.
 
did you add the comment pullable in the event? Did you press the shift button (by default) to pull the object? If you want to change that, change:

Button = Input::SHIFT

to

Button = Input::C

or one of the other input buttons
 
Try changing

if event.x == x && event.y == y && event.pullable

to

if event.x == x && event.y == y && event.pullable && event.moving? == false

If that doesn't work, also change

if Input.trigger?(Pullable::Button)

to

if Input.trigger?(Pullable::Button) && moving? == false


That should fix it.
 
It seems like you've got this pretty well figured out. When I first read the post, I evented it to see what I could come up with. It's pretty simple actually, but when pulling, the player walks back and then a very slight second after the object follows. It works pretty well though. If the scripts are too complicated, or you'd like to use the events instead, let me know, I can post a demo.

However; I do believe the script you're using will run much smoother than any eventing you can do.

Lol. I just read Zeriab's post. That's something to look into. Seems that he's got a handle on the eventing.
 

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