Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Spinners" #222

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Data/Scripts/004_Game classes/006_Game_Character.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ def triggerLeaveTile
if @oldX && @oldY && @oldMap &&
(@oldX != self.x || @oldY != self.y || @oldMap != self.map.map_id)
EventHandlers.trigger(:on_leave_tile, self, @oldMap, @oldX, @oldY)
EventHandlers.trigger(:on_player_leave_tile,self, @oldMap, @oldX, @oldY) if self == $game_player
end
@oldX = self.x
@oldY = self.y
Expand Down
34 changes: 34 additions & 0 deletions Data/Scripts/012_Overworld/001_Overworld.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,40 @@ def pbCheckAllFainted
}
)

# Turn a "spinner" towards the player if running or on the bike.
# An event's name must contain "spinner" and "trainer()" or "sight()".
# A spinner's can be blocked from spinning in a any number of directions if the event name contains noleft, noright, noup, or nodown.
# I recommend making spinners stationary, as the interaction with move routes is untested.
# NOTE: The player cannot open a submenu to pause spinning momentarily, as can be done in official games.
EventHandlers.add(:on_player_leave_tile, :turn_spinner_toward_player,
proc {
if ($game_player.can_run? || $PokemonGlobal.bicycle) && true
$game_map.events.each_value do |event|
next if !event.name[/spinner/] # Event must be a spinner
next if !event.name[/(?:sight|trainer)\((\d+)\)/i] # Event must have sight
distance = $~[1].to_i
sx = event.x + (event.width / 2.0) - ($game_player.x + ($game_player.width / 2.0))
sy = event.y - (event.height / 2.0) - ($game_player.y - ($game_player.height / 2.0))
next if sx.abs > distance || sy.abs > distance # Don't spin if the player isn't in the range sight
next if sx == 0 && sy == 0
if sx.abs > sy.abs
if sx > 0 && !event.name[/(?:\(|\,)noleft(?:\)|\,)/] #left
pbMoveRoute(event, [PBMoveRoute::TURN_LEFT])
elsif sx <= 0 && !event.name[/(?:\(|\,)noright(?:\)|\,)/] #right
pbMoveRoute(event, [PBMoveRoute::TURN_RIGHT])
end
else
if sy > 0 && !event.name[/(?:\(|\,)noup(?:\)|\,)/] #up
pbMoveRoute(event, [PBMoveRoute::TURN_UP])
elsif sy <= 0 && !event.name[/(?:\(|\,)nodown(?:\)|\,)/] #down
pbMoveRoute(event, [PBMoveRoute::TURN_DOWN])
end
end
end
end
}
)

def pbOnStepTaken(eventTriggered)
if $game_player.move_route_forcing || pbMapInterpreterRunning?
EventHandlers.trigger(:on_step_taken, $game_player)
Expand Down