Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # DPPt Honey Trees - By Vendily [v17/v18]
- #===============================================================================
- # This script adds in Honey Trees from DPPt, and all the bells and whistles
- # as described on Bulbapedia. That means Tree Shakes, The Group A/B/C, Munchlax
- # trees, all that jazz.
- #===============================================================================
- # To use it, you must create an event named "HoneyTree(X)", where X is the
- # tree's id (zero indexed). More than one event can have the same id, they
- # will act like the same tree in that case. The script will find these events
- # when you interact with them, much like how boulders ask to use strength.
- # Place these events at the base of your honey tree. They can only be interacted
- # from the the bottom (facing up). Remove the "next if $game_player.direction!=8"
- # to disable that behavior.
- # You can technically put event commands in the Honey Tree event, but they
- # activate after the honey tree asks to slather honey.
- # The species is fixed as soon as the honey is applied, much like DPPt.
- # Soft resets will only change the generated properties like level and nature.
- # There are 4 Munchlax trees, calculated using the HONEYTREE_MAX_TREES and the
- # Trainer ID. If HONEYTREE_MAX_TREES is less than 4, the Munchlax trees will
- # stack up. I don't recommend fewer than 5 trees, but it won't break.
- #===============================================================================
- # * The Total number of trees in the game. Try not to change it after release,
- # doing so will cause Munchlax trees to be recalculated and probably change.
- # Ideally should be more than 4.
- # * Time before the tree will show that there is an encounter in the tree.
- # (Default 6 hours)
- # * Time before the honey fades away and the encounter is lost. (Default 24 hours)
- # * The animation ids used to show a pokemon in the tree.
- # * The ratios used to calculate the number of shakes for a given group.
- # * The encounter table. Groups A and B must have the same number of entries as
- # HONEYTREE_ENCOUNTER_RATIOS, but Group C is a 1:1 ratio and can have any
- # length
- # * The ratios used to generate a species in Groups A and B.
- # Think Encounter Densities, that's this.
- #===============================================================================
- begin
- PluginManager.register({
- :name => "DPPt Honey Trees",
- :version => "1.0",
- :link => "https://reliccastle.com/resources/422/",
- :credits => "Vendily"
- })
- rescue
- # not v18
- end
- HONEYTREE_MAX_TREES = 5
- HONEYTREE_TIME_ENCOUNTER = 6*60*60 # 6 hours
- HONEYTREE_TIME_FADE = 24*60*60 # 24 hours
- HONEYTREE_TREESHAKE_ANIMS=[
- RUSTLE_NORMAL_ANIMATION_ID, # 0 shakes, but there is a mon
- RUSTLE_VIGOROUS_ANIMATION_ID, # 1 shake
- RUSTLE_SHINY_ANIMATION_ID, # 2 shakes
- PLANT_SPARKLE_ANIMATION_ID # 3 shakes
- ]
- HONEYTREE_TREESHAKE_RATIOS=[
- [20,59,20,1],
- [1,20,75,4],
- [1,1,5,93]
- ]
- HONEYTREE_ENCOUNTER_GROUPS=[
- [:COMBEE,:WURMPLE,:BURMY,:CHERUBI,:AIPOM,:AIPOM], # Group A
- [:BURMY,:CHERUBI,:COMBEE,:AIPOM,:AIPOM,:HERACROSS], # Group B
- [:MUNCHLAX] # Group C
- ]
- HONEYTREE_ENCOUNTER_RATIOS=[40,20,20,10,5,5]
- class PokemonGlobalMetadata
- attr_accessor :honeytrees
- attr_accessor :lasthoneytree
- def honeytrees
- @honeytrees=[] if !@honeytrees
- return @honeytrees
- end
- end
- Events.onAction+=proc{|sender,e|
- next if $game_player.direction!=8
- facingEvent = $game_player.pbFacingEvent
- if facingEvent && facingEvent.name[/HoneyTree\((\d+)\)/]
- pbHoneyTree($~[1].to_i)
- end
- }
- def pbHoneyTree(tree)
- raise "Invalid tree ID #{tree}" if tree>=HONEYTREE_MAX_TREES
- treedata=$PokemonGlobal.honeytrees[tree]
- now=pbGetTimeNow
- if !treedata || now-treedata[2]>HONEYTREE_TIME_FADE
- Kernel.pbMessage(_INTL("There is a sweet scent in the air...\\1"))
- elsif now-treedata[2]<HONEYTREE_TIME_ENCOUNTER
- Kernel.pbMessage(_INTL("The bark is slathered with Honey...\\1"))
- elsif treedata[0]>0 # in window, active tree
- Kernel.pbMessage(_INTL("Oh! A Pokémon is in the tree!"))
- pbWildBattle(treedata[0],rand(11)+5)
- $PokemonGlobal.honeytrees[tree]=nil
- return
- else
- Kernel.pbMessage(_INTL("The bark is slathered with Honey...\\1"))
- end
- if $PokemonBag.pbHasItem?(:HONEY)&& Kernel.pbConfirmMessage(_INTL("Slather the bark with Honey?"))
- $PokemonBag.pbDeleteItem(:HONEY,1)
- lasttree=$PokemonGlobal.lasthoneytree
- group=nil
- if lasttree && lasttree[0]==tree && rand(10)>0 # 90% chance to repick
- group=lasttree[1]
- group=0 if group==3
- end
- if !group
- if honey_tree_munchlax.include?(tree)
- ratio=[20,70,1,9]
- else
- ratio=[70,20,0,10]
- end
- total=ratio[0]+ratio[1]+ratio[2]+ratio[3]
- num=rand(total)
- cumtotal=0
- for i in 0...4
- cumtotal+=ratio[i]
- if num<cumtotal
- group=i
- break
- end
- end
- end
- now=pbGetTimeNow
- if group<3 # if pokemon, generate species
- table=HONEYTREE_ENCOUNTER_GROUPS[group]
- if group==2 # munchlax
- species=getID(table[rand(table.length)])
- else
- ratio=HONEYTREE_ENCOUNTER_RATIOS
- total=0
- ratio.each{|r| total+=r}
- num=rand(total)
- cumtotal=0
- for i in 0...4
- cumtotal+=ratio[i]
- if num<cumtotal
- species=table[i]
- break
- end
- end
- end
- ratio=HONEYTREE_TREESHAKE_RATIOS[group]
- total=0
- ratio.each{|r| total+=r}
- num=rand(total)
- cumtotal=0
- for i in 0...4
- cumtotal+=ratio[i]
- if num<cumtotal
- shakes=i
- break
- end
- end
- mon=[getID(PBSpecies,species),group,now,shakes]
- else
- mon=[0,3,now]
- end
- $PokemonGlobal.lasthoneytree=[tree,group]
- $PokemonGlobal.honeytrees[tree]=mon
- Kernel.pbMessage(_INTL("The bark was slathered with Honey."))
- end
- end
- def honey_tree_munchlax
- id=$Trainer.id
- sid1,sid2,tid1,tid2=id&(0xFF<<24),id&(0xFF<<16),id&(0xFF<<8),id&(0xFF)
- a=sid1 % HONEYTREE_MAX_TREES
- b=sid2 % HONEYTREE_MAX_TREES
- c=tid1 % HONEYTREE_MAX_TREES
- d=tid2 % HONEYTREE_MAX_TREES
- if a==b
- b+=1
- b%=HONEYTREE_MAX_TREES
- end
- if a==c
- c+=1
- c%=HONEYTREE_MAX_TREES
- elsif b==c
- c+=1
- c%=HONEYTREE_MAX_TREES
- end
- if a==d
- d+=1
- d%=HONEYTREE_MAX_TREES
- elsif b==d
- d+=1
- d%=HONEYTREE_MAX_TREES
- elsif c==d
- d+=1
- d%=HONEYTREE_MAX_TREES
- end
- return [a,b,c,d]
- end
- class HoneyTreeSprite
- def initialize(event,map,viewport)
- @event=event
- @map=map
- @disposed=false
- @frames=0
- @frameskip=25+rand(10)+rand(10)
- event.name[/HoneyTree\((\d+)\)/]
- @treeid=$~[1].to_i
- end
- def dispose
- @event=nil
- @map=nil
- @disposed=true
- end
- def disposed?
- @disposed
- end
- def update
- @frames+=1
- if @frames>=@frameskip
- @frames=0
- treedata=$PokemonGlobal.honeytrees[@treeid]
- now=pbGetTimeNow
- return if !treedata
- return if now-treedata[2]<HONEYTREE_TIME_ENCOUNTER
- return if now-treedata[2]>HONEYTREE_TIME_FADE
- return if treedata[0] && treedata[0]<=0
- return if !$scene.spriteset
- $scene.spriteset.addUserAnimation(HONEYTREE_TREESHAKE_ANIMS[treedata[3]],@event.x,
- @event.y-1,true)
- end
- end
- end
- Events.onSpritesetCreate+=proc{|sender,e|
- spriteset=e[0]
- viewport=e[1]
- map=spriteset.map
- for i in map.events.keys
- if map.events[i].name[/HoneyTree\((\d+)\)/]
- spriteset.addUserSprite(HoneyTreeSprite.new(map.events[i],map,viewport))
- end
- end
- }
Add Comment
Please, Sign In to add comment