#=============================================================================== # ** Hidden Grottos for Essentials ** # by Drimer #=============================================================================== # Events with '#HIDDEN GROTTO' on its name will be affected by this script. #=============================================================================== module HiddenGrottos # Graphic used for visible items, must be in 'Graphics/Characters/' POKEBALL_ICON = "" # Respawn steps STEPS_REQUIRED = 255 # Percent REGENERATION_CHANCE = 5 # Pokemon level if not specified in its array DEFAULT_LEVEL = 10 end # To keep track on current existing items. class PokemonGlobalMetadata attr_accessor :hidden_grottos, :hidden_grottos_steps alias initialize_hidden_grottos initialize def initialize initialize_hidden_grottos @hidden_grottos = {} @hidden_grottos_steps = 0 end end module HiddenGrottos # Hash, keys are maps ID. Key 0 will be used as Global Items. # key 0 will have 60% chances to be used, map specific data will have 40% def self.table { 0 => [ # if third param is true the item will be displayed [:item, :POTION, true], # if missing or false, the item will be hidden [:item, :POKEBALL], # for pokemon -- third parameter (level) is optional [:pokemon, :PIKACHU, 5], # if missing it take the DEFAULT_LEVEL constant's value [:pokemon, :ARBOK] ] } end def self.createEvent(map_id, event) return false if !HiddenGrottos.table[0] if $PokemonGlobal.hidden_grottos[map_id] == true return false end if HiddenGrottos.table[map_id] && (rand(100) < 40) data = HiddenGrottos.table[map_id] else data = HiddenGrottos.table[0] end $PokemonGlobal.hidden_grottos[map_id] = data.shuffle.first name = command = "" case $PokemonGlobal.hidden_grottos[map_id][0] when :item if $PokemonGlobal.hidden_grottos[map_id][2] name = HiddenGrottos::POKEBALL_ICON end command = "Kernel.pbItemBall(:#{$PokemonGlobal.hidden_grottos[map_id][1]});" command += "$PokemonGlobal.hidden_grottos[#{map_id}] = true" when :pokemon name = sprintf("%03d", getID(PBSpecies, $PokemonGlobal.hidden_grottos[map_id][1])) level = $PokemonGlobal.hidden_grottos[map_id][2] ? $PokemonGlobal.hidden_grottos[map_id][2] : HiddenGrottos::DEFAULT_LEVEL command = "pbSEPlay(\"Cries/#{name}Cry\");" command += "pbWildBattle(:#{$PokemonGlobal.hidden_grottos[map_id][1]}, #{level});" command += "$PokemonGlobal.hidden_grottos[#{map_id}] = true" end key = [map_id, event.id, "A"] $game_self_switches[key] = false e = RPG::Event.new(event.x, event.y) e.name = event.name e.id = event.id e.pages[0].graphic.character_name = name e.pages[0].list.unshift(RPG::EventCommand.new) e.pages[0].list.push(RPG::EventCommand.new) e.pages[0].list[0].code = 355 e.pages[0].list[0].parameters[0] = command e.pages[0].step_anime = $PokemonGlobal.hidden_grottos[map_id][0] == :pokemon e.pages[0].through = $PokemonGlobal.hidden_grottos[map_id][0] == :item && !$PokemonGlobal.hidden_grottos[map_id][2] e.pages[0].list[1].code = 123 e.pages[0].list[1].parameters[0] = 'A' e.pages[0].list[1].parameters[1] = 0 e.pages[1] = RPG::Event::Page.new e.pages[1].condition.self_switch_valid = true e.pages[1].condition.self_switch_ch = 'A' return e end end # After a certain number of steps and under some conditions, generates a new # Event Events.onStepTaken+=proc{ if !$PokemonGlobal.hidden_grottos_steps $PokemonGlobal.hidden_grottos_steps = 0 end $PokemonGlobal.hidden_grottos_steps += 1 if $PokemonGlobal.hidden_grottos_steps >= HiddenGrottos::STEPS_REQUIRED $PokemonGlobal.hidden_grottos.each{|key, value| next if !(HiddenGrottos::REGENERATION_CHANCE >= rand(100)) next if $PokemonGlobal.hidden_grottos[key].is_a?(Array) if $PokemonGlobal.hidden_grottos[key] == true || !$PokemonGlobal.hidden_grottos[key] $PokemonGlobal.hidden_grottos[key] = false end } $PokemonGlobal.hidden_grottos_steps = 0 end } # Overrides the Grotto Event with a new one class Game_Map alias _setup_hidden_g setup def setup(map_id) _setup_hidden_g(map_id) for event in @map.events.values if event.name[/#HIDDEN GROTTO/] e = HiddenGrottos.createEvent(map_id, event) return if !e @map.events.each{|key, value| if value == event @events[key] = Game_Event.new(@map_id, e, self) end } end end end end