• Do not use Discord to host any images you post, these links expire quickly! You can learn how to add images to your posts here.
  • The Eevee Expo Game Jam has concluded! 🎉 Head on over to the game jam forum to play through the games.
    Don't forget to come back September 21st to vote for your favorites!
  • Reminder: AI-generated content is not allowed on the forums per the Rules and Regulations. Please contact us if you have any questions!

Idea Speed of skateboard doesn't change, remains like speed of walking

Obermarschall

Novice
Member
Joined
Jan 27, 2018
Posts
20
#===============================================================================

# Skateboard Plugin for Pokémon Essentials v21.1

#===============================================================================

module SkateboardSystem

SKATE_ITEM = :SKATEBOARD # Item symbol that enables skateboarding

SKATE_SWITCH = 999 # Switch ID that disables skateboarding when ON

end

class PokemonGlobalMetadata

attr_accessor :skateboarding

end

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

# Player mount/dismount skateboard and movement change

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

def pbMountSkateboard

return if $PokemonGlobal.skateboarding

return unless $bag.has?(SkateboardSystem::SKATE_ITEM)

$PokemonGlobal.skateboarding = true

# Change player charset to skateboard sprite

$game_player.character_name = "boy_skate"

$game_player.refresh

# Set custom movement type (defined below)

$game_player.set_movement_type(:skateboarding)

# Play sound effect (change to your sound)

pbSEPlay("Skateboard_Start")

end

def pbDismountSkateboard

return unless $PokemonGlobal.skateboarding

$PokemonGlobal.skateboarding = false

# Revert player charset to default

$game_player.character_name = "boy_walk"

$game_player.refresh

# Revert movement type to walking

$game_player.set_movement_type(:walking)

# Play sound effect

pbSEPlay("Skateboard_Stop")

end

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

# Extend Game_Player to add skateboard movement type

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

class Game_Player < Game_Character

alias_method :skateboard_set_movement_type, :set_movement_type

def set_movement_type(type)

if type == :skateboarding

u/move_speed = 5

u/move_time = 0.1

u/animation_speed = 3

u/walking_animation = true

else

skateboard_set_movement_type(type)

end

end

alias_method :original_move_speed, :move_speed

def move_speed

return 5 if $PokemonGlobal.skateboarding

original_move_speed

end

end

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

# Add input handler to toggle skateboarding with a button press

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

module Input

SKATE_KEY = Input::USE # Change to whichever button you want

def self.update_skate_toggle

return unless Input.trigger?(:USE) # <-- This is the correct line

return if $game_temp.in_menu || $game_temp.in_battle

return if $PokemonGlobal.nil? || $PokemonGlobal.bicycle || $PokemonGlobal.surfing || $PokemonGlobal.diving

return if $game_switches[SkateboardSystem::SKATE_SWITCH]

return if !$bag.has?(SkateboardSystem::SKATE_ITEM)

if $PokemonGlobal.skateboarding

pbDismountSkateboard

else

pbMountSkateboard

end

$game_player.refresh

end

class << self

alias_method :skateboard_original_update, :update

def update(*args)

skateboard_original_update(*args)

update_skate_toggle

end

end

end

module SkateboardHandler

def self.toggle_skateboard(item = nil)

if $PokemonGlobal.skateboarding

pbDismountSkateboard

pbMessage(_INTL("You got off your skateboard."))

else

if $PokemonGlobal.bicycle || $PokemonGlobal.surfing || $PokemonGlobal.diving

pbMessage(_INTL("You can't use your skateboard right now!"))

else

pbMountSkateboard

pbMessage(_INTL("You got on your skateboard!"))

end

end

return true

end

end

ItemHandlers::UseInField.add(:SKATEBOARD, proc { |item|

SkateboardHandler.toggle_skateboard(item)

})

ItemHandlers::UseFromBag.add(:SKATEBOARD, proc { |item|

next 2

})
What is necessary or what am I missing to change the speed? While running and using the bike the speed changes, so i tried to mimic that. The player graphic changes when using the item... but the speed doesn't? Why?
 
I had some free time, so I looked at it.
I tried to keep it clean and in the same style
Hopes it helps

Ruby:
Expand Collapse Copy
#===============================================================================
# Skateboard Plugin for Pokémon Essentials v21.1
#===============================================================================
module SkateboardSystem
  SKATE_ITEM = :SKATEBOARD # Item symbol that enables skateboarding
  SKATE_SWITCH = 99 # Switch ID that disables skateboarding when ON
  SKATE_KEY = Input::AUX1 # Change to whichever button you want
end

class PokemonGlobalMetadata
  attr_accessor :skateboarding
end

#-------------------------------------------------------------------------------
# Player mount/dismount skateboard and movement change
#-------------------------------------------------------------------------------
def pbMountSkateboard
  return if $PokemonGlobal.skateboarding
  return unless $bag.has?(SkateboardSystem::SKATE_ITEM)
  $PokemonGlobal.skateboarding = true
  # Change player charset to skateboard sprite
  $game_player.pbUpdateVehicle
  # Play sound effect (change to your sound)
  pbSEPlay("Skateboard_Start")
end

def pbDismountSkateboard
  return unless $PokemonGlobal.skateboarding
  $PokemonGlobal.skateboarding = false
  # Revert player charset to default
  $game_player.pbUpdateVehicle
  # Play sound effect
  pbSEPlay("Skateboard_Stop")
end

#-------------------------------------------------------------------------------
# Extend Game_Player to add skateboard movement type
#-------------------------------------------------------------------------------
class Game_Player < Game_Character

  def can_run?
    return @move_speed > 3 if @move_route_forcing
    return false if @bumping
    return false if $game_temp.in_menu || $game_temp.in_battle ||
                    $game_temp.message_window_showing || pbMapInterpreterRunning?
    return false if !$player.has_running_shoes && !$PokemonGlobal.diving &&
                    !$PokemonGlobal.surfing && !$PokemonGlobal.bicycle && !$PokemonGlobal.skateboarding
    return false if jumping?
    return false if pbTerrainTag.must_walk
    return ($PokemonSystem.runstyle == 1) ^ Input.press?(Input::BACK)
  end

  def set_movement_type(type)
    meta = GameData::PlayerMetadata.get($player&.character_ID || 1)
    new_charset = nil
    case type
    when :fishing
      new_charset = pbGetPlayerCharset(meta.fish_charset)
    when :surf_fishing
      new_charset = pbGetPlayerCharset(meta.surf_fish_charset)
    when :diving, :diving_fast, :diving_jumping, :diving_stopped
      self.move_speed = 3 if !@move_route_forcing
      new_charset = pbGetPlayerCharset(meta.dive_charset)
    when :surfing, :surfing_fast, :surfing_jumping, :surfing_stopped
      if !@move_route_forcing
        self.move_speed = (type == :surfing_jumping) ? 3 : 4
      end
      new_charset = pbGetPlayerCharset(meta.surf_charset)
    when :descending_waterfall, :ascending_waterfall
      self.move_speed = 2 if !@move_route_forcing
      new_charset = pbGetPlayerCharset(meta.surf_charset)
    when :cycling, :cycling_fast, :cycling_jumping, :cycling_stopped
      if !@move_route_forcing
        self.move_speed = (type == :cycling_jumping) ? 3 : 5
      end
      new_charset = pbGetPlayerCharset(meta.cycle_charset)
    when :skateboarding, :skateboarding_fast, :skateboarding_jumping, :skateboarding_stopped
      if !@move_route_forcing
        self.move_speed = (type == :skateboarding_jumping) ? 3 : 6 #Skate Speed
      end
      new_charset = pbGetPlayerCharset(meta.cycle_charset) #skate_charset
    when :running
      self.move_speed = 4 if !@move_route_forcing
      new_charset = pbGetPlayerCharset(meta.run_charset)
    when :ice_sliding
      self.move_speed = 4 if !@move_route_forcing
      new_charset = pbGetPlayerCharset(meta.walk_charset)
    else   # :walking, :jumping, :walking_stopped
      self.move_speed = 3 if !@move_route_forcing
      new_charset = pbGetPlayerCharset(meta.walk_charset)
    end
    self.move_speed = 3 if @bumping
    @character_name = new_charset if new_charset
  end

  def refresh_charset
    meta = GameData::PlayerMetadata.get($player&.character_ID || 1)
    new_charset = nil
    if $PokemonGlobal&.diving
      new_charset = pbGetPlayerCharset(meta.dive_charset)
    elsif $PokemonGlobal&.surfing
      new_charset = pbGetPlayerCharset(meta.surf_charset)
    elsif $PokemonGlobal&.bicycle
      new_charset = pbGetPlayerCharset(meta.cycle_charset)
    elsif $PokemonGlobal&.skateboarding
      new_charset = pbGetPlayerCharset(meta.cycle_charset) #skate_charset
    else
      new_charset = pbGetPlayerCharset(meta.walk_charset)
    end
    @character_name = new_charset if new_charset
  end

  def update_move
    if !@moved_last_frame || @stopped_last_frame   # Started a new step
      if $PokemonGlobal.ice_sliding || @last_terrain_tag.ice
        set_movement_type(:ice_sliding)
      elsif $PokemonGlobal.descending_waterfall
        set_movement_type(:descending_waterfall)
      elsif $PokemonGlobal.ascending_waterfall
        set_movement_type(:ascending_waterfall)
      else
        faster = can_run?
        if $PokemonGlobal&.diving
          set_movement_type((faster) ? :diving_fast : :diving)
        elsif $PokemonGlobal&.surfing
          set_movement_type((faster) ? :surfing_fast : :surfing)
        elsif $PokemonGlobal&.bicycle
          set_movement_type((faster) ? :cycling_fast : :cycling)
        elsif $PokemonGlobal&.skateboarding
          set_movement_type((faster) ? :skateboarding_fast : :skateboarding)
        else
          set_movement_type((faster) ? :running : :walking)
        end
      end
      if jumping?
        if $PokemonGlobal&.diving
          set_movement_type(:diving_jumping)
        elsif $PokemonGlobal&.surfing
          set_movement_type(:surfing_jumping)
        elsif $PokemonGlobal&.bicycle
          set_movement_type(:cycling_jumping)
        elsif $PokemonGlobal&.skateboarding
          set_movement_type(:skateboarding_jumping)
        else
          set_movement_type(:jumping)   # Walking speed/charset while jumping
        end
      end
    end
    was_jumping = jumping?
    super
    if was_jumping && !jumping? && !@transparent && (@tile_id > 0 || @character_name != "")
      if !$PokemonGlobal.surfing || $game_temp.ending_surf
        spriteset = $scene.spriteset(map_id)
        spriteset&.addUserAnimation(Settings::DUST_ANIMATION_ID, self.x, self.y, true, 1)
      end
    end
  end

  def update_stop
    if @stopped_last_frame
      if $PokemonGlobal&.diving
        set_movement_type(:diving_stopped)
      elsif $PokemonGlobal&.surfing
        set_movement_type(:surfing_stopped)
      elsif $PokemonGlobal&.bicycle
        set_movement_type(:cycling_stopped)
      elsif $PokemonGlobal&.skateboarding
        set_movement_type(:skateboarding_stopped)
      else
        set_movement_type(:walking_stopped)
      end
    end
    super
  end
end

def pbUpdateVehicle
  if $PokemonGlobal&.diving
    $game_player.set_movement_type(:diving_stopped)
  elsif $PokemonGlobal&.surfing
    $game_player.set_movement_type(:surfing_stopped)
  elsif $PokemonGlobal&.bicycle
    $game_player.set_movement_type(:cycling_stopped)
  elsif $PokemonGlobal&.skateboarding
    $game_player.set_movement_type(:skateboarding_stopped)
  else
    $game_player.set_movement_type(:walking_stopped)
  end
end

def pbCancelVehicles(destination = nil, cancel_swimming = true)
  $PokemonGlobal.surfing = false if cancel_swimming
  $PokemonGlobal.diving  = false if cancel_swimming
  $PokemonGlobal.bicycle = false if !destination || !pbCanUseBike?(destination)
  $PokemonGlobal.skateboarding = false if !destination || !pbCanUseSkateboard?(destination)
  pbUpdateVehicle
end

#-------------------------------------------------------------------------------
# Add input handler to toggle skateboarding with a button press
#-------------------------------------------------------------------------------
module Input
  class << self
    alias_method :original_update, :update
    def update(*args)
      original_update(*args)
      update_skate_toggle
    end
  end

  def self.update_skate_toggle
    return unless Input.trigger?(SkateboardSystem::SKATE_KEY)
    return if $game_temp.in_menu || $game_temp.in_battle
    return if !pbSkateboardCheck && !$bag.has?(SkateboardSystem::SKATE_ITEM)
    return if $game_switches[SkateboardSystem::SKATE_SWITCH]
    if $PokemonGlobal.skateboarding
      pbDismountSkateboard
    else
      pbMountSkateboard
    end
  end
end

def pbSkateboardCheck
  if $PokemonGlobal.bicycle || $PokemonGlobal.surfing || $PokemonGlobal.diving ||
     (!$PokemonGlobal.skateboarding &&
     ($game_player.pbTerrainTag.must_walk || $game_player.pbTerrainTag.must_walk_or_run))
    pbMessage(_INTL("Can't use that here."))
    return false
  end
  if !$game_player.can_ride_vehicle_with_follower?
    pbMessage(_INTL("It can't be used when you have someone with you."))
    return false
  end
  map_metadata = $game_map.metadata
  if $PokemonGlobal.skateboarding
    if map_metadata&.always_bicycle
      pbMessage(_INTL("You can't dismount your Skate here."))
      return false
    end
    return true
  end
  if !map_metadata || (!map_metadata.can_bicycle && !map_metadata.outdoor_map)
    pbMessage(_INTL("Can't use that here."))
    return false
  end
  return true
end

def pbCanUseSkateboard?(map_id)
  map_metadata = GameData::MapMetadata.try_get(map_id)
  return false if !map_metadata
  return map_metadata.always_bicycle || map_metadata.can_bicycle# || map_metadata.outdoor_map
# I found it funny if you can use the skateboard indoors, but remove the "#" before "||" to enable the check for indoors
end

ItemHandlers::UseFromBag.add(SkateboardSystem::SKATE_ITEM, proc { |item|
  next (pbSkateboardCheck) ? 2 : 0
})

ItemHandlers::UseInField.add(SkateboardSystem::SKATE_ITEM, proc { |item|
  if pbSkateboardCheck
    if $PokemonGlobal.skateboarding
      pbDismountSkateboard
      pbMessage(_INTL("You got off your skateboard."))
    else
      pbMountSkateboard
      pbMessage(_INTL("You got on your skateboard!"))
    end
    next true
  end
  next false
})

module GameData
  class PlayerMetadata
    class << self
      alias original_editor_properties editor_properties
      def editor_properties
        original_editor_properties + [
          ["SkatebordCharset",  CharacterProperty, _INTL("Charset used while the player is lifting. Uses CycleCharset if undefined.")],
        ]
      end
    end

    SCHEMA["SkatebordCharset"] = [:skatebord_charset, "s"]

    alias original_initialize initialize
    def initialize(hash)
      original_initialize(hash)
      @skatebord_charset = hash[:skatebord_charset]
    end

    def skatebord_charset
      return @skatebord_charset || cycle_charset
    end
  end
end
 
Last edited:
Back
Top