• Hi, Guest!
    Some images might be missing as we move away from using embedded images, sorry for the mess!
    From now on, you'll be required to use a third party to host images. You can learn how to add images here, and if your thread is missing images you can request them here.
    Do not use Discord to host any images you post, these links expire quickly!
Resource icon

v19 Timer Based Safari Zone 1.0

This resource pertains to version 19 of Pokémon Essentials.
Pokémon Essentials Version
v19.1 ➖
Ruby:
############################################################
####TIMER BASED SAFARI ZONE V1.0 FOR POKEMON ESSENTIALS V19.1#####
############################################################
################Instructions for Install############################
############################################################
######Just copy and paste over the existing Safari Zone script#############
#######then adjust bug contest time in the settings script################
#########No credit needed for usage. but a follow#####################
##########@twitch.tv/hobbs_live would be nice :)#####################
##########################ENJOY#############################
############################################################
############################################################


class SafariState
  attr_accessor :ballcount
  attr_accessor :decision
  attr_reader   :timer
  TimerSeconds = Settings::BUG_CONTEST_TIME

  def initialize
    @start      = nil
    @ballcount  = 0
    @inProgress = false
    @steps      = 0
    @decision   = 0
  end

  def expired?
    return false if !undecided?
    return false if TimerSeconds<=0
    curtime=@timer+TimerSeconds*Graphics.frame_rate
    curtime=[curtime-Graphics.frame_count,0].max
    return (curtime<=0)
  end

  def pbReceptionMap
    return @inProgress ? @start[0] : 0
  end

  def inProgress?
    return @inProgress
  end

  def undecided?
    return (@inProgress && @decision==0)
  end
 
  def pbGoToStart
    if $scene.is_a?(Scene_Map)
      pbFadeOutIn {
        $game_temp.player_transferring   = true
        $game_temp.transition_processing = true
        $game_temp.player_new_map_id    = @start[0]
        $game_temp.player_new_x         = @start[1]
        $game_temp.player_new_y         = @start[2]
        $game_temp.player_new_direction = 2
        $scene.transfer_player
      }
    end
  end

  def pbStart(ballcount)
    @start      = [$game_map.map_id,$game_player.x,$game_player.y,$game_player.direction]
    @ballcount  = ballcount
    @inProgress = true
    @timer    = Graphics.frame_count
  end

  def pbEnd
    @start      = nil
    @ballcount  = 0
    @inProgress = false
    @decision   = 0
    timenow=pbGetTimeNow
    $game_map.need_refresh = true
  end
end

class TimerDisplay # :nodoc:
  def initialize(start,maxtime)
    @timer=Window_AdvancedTextPokemon.newWithSize("",Graphics.width-120,0,120,64)
    @timer.z=99999
    @total_sec=nil
    @start=start
    @maxtime=maxtime
  end

  def dispose
    @timer.dispose
  end

  def disposed?
    @timer.disposed?
  end

  def update
    curtime=[(@start+@maxtime)-Graphics.frame_count,0].max
    curtime/=Graphics.frame_rate
    if curtime != @total_sec
      # Calculate total number of seconds
      @total_sec = curtime
      # Make a string for displaying the timer
      min = @total_sec / 60
      sec = @total_sec % 60
      @timer.text = _ISPRINTF("<ac>{1:02d}:{2:02d}", min, sec)
    end
  end
end


Events.onMapChange += proc { |_sender,*args|
  pbSafariState.pbEnd if !pbInSafari?
}

def pbInSafari?
  if pbSafariState.inProgress?
    # Reception map is handled separately from safari map since the reception
    # map can be outdoors, with its own grassy patches.
    reception = pbSafariState.pbReceptionMap
    return true if $game_map.map_id == reception
    map_metadata = GameData::MapMetadata.try_get($game_map.map_id)
    return true if map_metadata && map_metadata.safari_map
  end
  return false
end

def pbSafariState
  $PokemonGlobal.safariState = SafariState.new if !$PokemonGlobal.safariState
  return $PokemonGlobal.safariState
end

Events.onMapSceneChange += proc { |_sender,e|
  scene=e[0]
  if pbInSafari? && pbSafariState.decision==0 && SafariState::TimerSeconds>0
    scene.spriteset.addUserSprite(TimerDisplay.new(
       pbSafariState.timer,
       SafariState::TimerSeconds*Graphics.frame_rate))
  end
}

Events.onMapUpdate += proc { |_sender,_e|
  if !$game_player.move_route_forcing && !pbMapInterpreterRunning? &&
     !$game_temp.message_window_showing
      if pbSafariState.expired?
      pbMessage(_INTL("ANNOUNCER:  BEEEEEP!"))
      pbMessage(_INTL("Time's up!"))
      pbSafariState.decision = 1
      pbSafariState.pbGoToStart
    end
  end
}

Events.onWildBattleOverride += proc { |_sender,e|
  species = e[0]
  level   = e[1]
  handled = e[2]
  next if handled[0]!=nil
  next if !pbInSafari?
  handled[0] = pbSafariBattle(species,level)
}

def pbSafariBattle(species,level)
  # Generate a wild Pokémon based on the species and level
  pkmn = pbGenerateWildPokemon(species,level)
  foeParty = [pkmn]
  # Calculate who the trainer is
  playerTrainer = $Trainer
  # Create the battle scene (the visual side of it)
  scene = pbNewBattleScene
  # Create the battle class (the mechanics side of it)
  battle = PokeBattle_SafariZone.new(scene,playerTrainer,foeParty)
  battle.ballCount = pbSafariState.ballcount
  pbPrepareBattle(battle)
  # Perform the battle itself
  decision = 0
  pbBattleAnimation(pbGetWildBattleBGM(foeParty),0,foeParty) {
    pbSceneStandby {
      decision = battle.pbStartBattle
    }
  }
  Input.update
  # Update Safari game data based on result of battle
  pbSafariState.ballcount = battle.ballCount
  if pbSafariState.ballcount<=0
    if decision!=2   # Last Safari Ball was used to catch the wild Pokémon
      pbMessage(_INTL("Announcer: You're out of Safari Balls! Game over!"))
    end
    pbSafariState.decision = 1
    pbSafariState.pbGoToStart
  end
  # Save the result of the battle in Game Variable 1
  #    0 - Undecided or aborted
  #    2 - Player ran out of Safari Balls
  #    3 - Player or wild Pokémon ran from battle, or player forfeited the match
  #    4 - Wild Pokémon was caught
  pbSet(1,decision)
  # Used by the Poké Radar to update/break the chain
  Events.onWildBattleEnd.trigger(nil,species,level,decision)
  # Return the outcome of the battle
  return decision
end
Credits
no credit needed. enjoy :)
  • Like
Reactions: TechSkylander1518
Author
hobbs
Views
604
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from hobbs

Back
Top