Trying to get a hookshot to work

velvetisis

Warper
Member
Joined
Jul 6, 2014
Messages
3
Reaction score
2
First Language
English
Primarily Uses
I'm trying to get a hookshot for my game and have got it kinda working.  I have an invisible event that I call with a common event using Yanfly's button common events.  Originally I used move route to move it forward 5 paces and back 5 paces, but I ran into the problem that if it hit a wall before the 5 paces were up it would still move back 5 paces, going further than the firing point.  So I'm trying to script it.  This is what I have so far:

    def vis_hook
      for event in $game_map.events.values
        if event.name.include?("Hookshot") and !event.erased
          @hookstep = 0
            def fmove
              move_forward
              @hookstep += 1
                if @hookstep = 5 or !@move_suceed
                  $game_self_switches[[@map_id, @event_id, 'A']] = true
                end
            end
            def bmove
              move_backward
              @hookstep - 1
                if @hookstep = 0
                  $game_self_switches[[@map_id, @event_id, 'B']] = true
            end
          fmove
        end
      end
    end

with the idea being that it adds 1 to the @hookstep for every step it takes, then once it can't move it or it hits 5 moves the event switches the A self switch on, and the hookshot moves back as many steps are in @hookstep then switches on the B self switch to end the hookshot use.  So far the event moves forward but won't trigger the self switch :/  What am I messing up?
 

Diego2112

The Gaming Gamer Who Games
Veteran
Joined
May 10, 2013
Messages
681
Reaction score
159
First Language
English
Primarily Uses
RMVXA
I don't know about scripting in Ruby, but in C++ I would think that using some sort of array would be best.  It's a bit more code, but that way you're sure it works out fine, and will only move back however many spaces it moves forward-you'd just have to code it out for something like (psudocode inbound)

If hookshot travels X spaces, player goes back X spaces, where X = number of spaces traveled for that array.  If you have five spaces, you'd have five different outcomes for the array.

Again, I don't know Ruby, but I assume it has the ability to do that.

...

I don't know if that will help at all, but I hope it does!
 

YoraeRasante

Veteran
Veteran
Joined
Jun 6, 2014
Messages
1,643
Reaction score
420
First Language
Portuguese
Primarily Uses
RMMV
But... an array is many variables. All he needs is one value. I fail to see how an array would be better for this. Could you explain?
 

Diego2112

The Gaming Gamer Who Games
Veteran
Joined
May 10, 2013
Messages
681
Reaction score
159
First Language
English
Primarily Uses
RMVXA
Not really.  I'm just learning the basics of programming myself, and arrays are what my teacher suggested when we had something like this come up.  So.  Like I said, I'm not an expert in it, not even REALLY good in C++, but was trying to help as best I can.
 

Zoltor

Veteran
Veteran
Joined
Jan 18, 2014
Messages
1,550
Reaction score
211
First Language
English
Primarily Uses
This can be easily done without scripting I'm pretty sure(and probally will be in my game as well).

If you want it to be usable everywhere, you may want to use a Region code script so you don't have a million events on the map, but the hookshot its self shouldn't need any scripting at all.
 
Last edited by a moderator:

velvetisis

Warper
Member
Joined
Jul 6, 2014
Messages
3
Reaction score
2
First Language
English
Primarily Uses
I ended up getting it to work with the following: 

#==============================================================================
# Hookshot System
# by VelvetIsis
#------------------------------------------------------------------------------

#==============================================================================
# Game Character
#==============================================================================
class Game_Character
  #----------------------------------------------------------------------------
  # Local Variables
  #----------------------------------------------------------------------------
    attr_accessor :hookstep
  #----------------------------------------------------------------------------
  # Initialize
  #----------------------------------------------------------------------------
    alias hook_initialize initialize unless $@
    def initialize
      trace_initialize
      @hookstep = 0
    end
  #----------------------------------------------------------------------------
  # Shot
  #----------------------------------------------------------------------------
  def fmove
    move_forward
    @hookstep += 1
    if !@move_succeed or @hookstep == 5
      $game_switches[5] = true
    end
  end
  def bmove
    move_backward
    @hookstep -= 1
    if @hookstep == 0
      $game_switches[6] = true
      $game_switches[5] = false
    end
  end
end
 

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

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,049
Messages
1,018,546
Members
137,835
Latest member
yetisteven
Top