RPG Maker XP events can call Ruby scripts to integrate with Pokémon Essentials. This allows you to create custom gameplay without modifying core scripts.
# Give a Level 5 Pikachuspecies = PBSpecies::PIKACHUlevel = 5pokemon = PokeBattle_Pokemon.new(species, level, $Trainer)pbAddPokemon(pokemon)
With custom properties:
# Give a shiny Level 50 Charizard with a specific itemspecies = PBSpecies::CHARIZARDlevel = 50pokemon = PokeBattle_Pokemon.new(species, level, $Trainer)pokemon.makeShinypokemon.setItem(PBItems::CHARCOAL)pokemon.pbLearnMove(PBMoves::FLAMETHROWER)pbAddPokemon(pokemon)
# Check if player has a specific Pokémonhas_pikachu = falsefor pokemon in $Trainer.party if pokemon.species == PBSpecies::PIKACHU has_pikachu = true break endendif has_pikachu pbMessage("I see you have a Pikachu!")else pbMessage("You don't have a Pikachu.")end
# Check if first Pokémon is at full HPfirst_pokemon = $Trainer.party[0]if first_pokemon && first_pokemon.hp >= first_pokemon.totalhp pbMessage("Your Pokémon is at full health!")else pbMessage("Your Pokémon needs healing.")end
# Gets the value of a variable.def pbGet(id) return 0 if !id || !$game_variables return $game_variables[id]end# Sets the value of a variable.def pbSet(id,value) if id && id>=0 $game_variables[id]=value if $game_variables $game_map.need_refresh = true if $game_map endend
Usage in events:
# Store party size in variable 10pbSet(10, $Trainer.party.length)# Check variable valueif pbGet(10) >= 6 pbMessage("Your party is full!")end
# Runs a common event and waits until the common event is finished.def pbCommonEvent(id) return false if id<0 ce=$data_common_events[id] return false if !ce celist=ce.list interp=Interpreter.new interp.setup(celist,0) begin Graphics.update Input.update interp.update pbUpdateSceneMap end while interp.running? return trueend
# Set a timed event for 24 hours (86400 seconds)pbTimeEvent(15, 86400)# Check if time has elapsedif pbTimeEventValid(15) pbMessage("The daily event is ready!") # Reset the timer pbTimeEvent(15, 86400)else pbMessage("Come back tomorrow!")end
For day-based events:
# Set event to expire after 7 dayspbTimeEventDays(20, 7)if pbTimeEventValid(20) pbMessage("A week has passed!")end
# Heal only HPfor pokemon in $Trainer.party pokemon.healHPend# Heal only statusfor pokemon in $Trainer.party pokemon.healStatusend# Restore PP for all movesfor pokemon in $Trainer.party pokemon.healPPend
# Changes the happiness of this Pokémon depending on what happenedpokemon.changeHappiness("vitamin") # +5 happinesspokemon.changeHappiness("level up") # +5 happinesspokemon.changeHappiness("groom") # +10 happinesspokemon.changeHappiness("faint") # -1 happiness
Direct happiness change:
pokemon = $Trainer.party[0]pokemon.happiness = 255 # Max happiness
# Force evolution of first Pokémonpokemon = $Trainer.party[0]if pokemon # Check if can evolve new_species = pbCheckEvolution(pokemon, PBEvolution::Level) if new_species pbFadeOutInWithMusic { evo = PokemonEvolutionScene.new evo.pbStartScreen(pokemon, new_species) evo.pbEvolution evo.pbEndScreen } endend
# Change form of a Pokémon (e.g., Rotom)pokemon = $Trainer.party[0]if pokemon && pokemon.species == PBSpecies::ROTOM pokemon.form = 1 # Heat Rotom pokemon.calcStats # Recalculate stats for new formend
if $PokemonBag.pbQuantity(PBItems::REDAPRICORN) >= 1 cmd = pbMessage("Trade Red Apricorn for Poké Ball?", ["Yes", "No"], -1) if cmd == 0 $PokemonBag.pbDeleteItem(PBItems::REDAPRICORN, 1) pbReceiveItem(PBItems::POKEBALL) pbMessage("Here's your Poké Ball!") endelse pbMessage("You don't have a Red Apricorn.")end
if $game_switches[500] == false # First time species = PBSpecies::EEVEE level = 10 pokemon = PokeBattle_Pokemon.new(species, level, $Trainer) # 1 in 8192 chance for shiny if rand(8192) == 0 pokemon.makeShiny pbMessage("Wow! It's a shiny Eevee!") end pbAddPokemon(pokemon) $game_switches[500] = trueend
Always use switches to prevent events from repeating when they shouldn’t. Set a switch to true after completing an event.