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?
Trying to get a hookshot to work
● ARCHIVED · READ-ONLY
-
-
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! -
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?
-
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.
-
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. -
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