• 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.
  • Eevee Expo's webhost has been having technical issues since Nov. 20th and you might be unable to connect to our site. Staff are also facing issues connecting, so please send a DM to Cat on-site or through Discord directly for faster service!
Resource icon

v19 Pokemon Broker 1

This resource pertains to version 19 of Pokémon Essentials.
Pokémon Essentials Version
v19.1 ➖
A script from my own game that has an NPC that asks for specific types of Pokemon that the NPC wishes to purchase. All types of Pokemon are also options. Just use the appropriate script commands at the bottom of the script. The event should have a conditional branch that makes sure the player has more than one pokemon and will refuse to purchase the player's last pokemon from their party. Their is a brief explanation of how to set this conditional branch up in an event. You can modify the equation that determines Pokemon value, but I based it on catch rate and total stats and added the cost of the pokeball used along with half the cost of any item the Pokemon may be holding. Shiny Pokemon are sold at double the normal rate. You may notice Alpha is also listed and is sold for double. My game uses a custom script that enables Alpha Pokemon; if your game does not, it should be fine.

I give permission for anyone to use and modify this script for their own Pokemon projects. I will not be updating this script for use with higher versions of Pokemon Essentials and have no plans to add more functionality to the script. Credit: Pokemon Liberator

Pokemon Broker:
Expand Collapse Copy
################################################################################
# ChooseAblePokemonByType Method
################################################################################

def pbChooseAblePokemonByType(variableNumber, nameVarNumber, type = nil)
  eligible_pokemon = $Trainer.party.select do |pkmn|
    if type.nil?
      true
    else
      pkmn.hasType?(type)
    end
  end

  if eligible_pokemon.empty?
    Kernel.pbMessage(_INTL("You have no eligible Pokémon."))
    pbSet(variableNumber, -1)
    pbSet(nameVarNumber, "")
    return
  end

  chosen = pbChooseRosterPokemon(eligible_pokemon, _INTL("Choose a Pokémon."), -1)
  pbSet(variableNumber, chosen)
  pbSet(nameVarNumber, $Trainer.party[chosen].name)
end


################################################################################
# Pokemon Broker
################################################################################

def pbChooseAblePokemonByType(variableNumber, nameVarNumber, type = nil)
  pbChoosePokemon(variableNumber, nameVarNumber, proc { |pkmn|
    next false if pkmn.isEgg?
    next true if type.nil?  # Allow all Pokémon if type is not specified
    next pkmn.hasType?(type)
  })
end

def sellPokemonToNPC(pokemon_type = nil)
  eligible_pokemon = $Trainer.party.select do |pkmn|
    if pokemon_type
      pkmn.hasType?(pokemon_type)
    else
      true
    end
  end

  if eligible_pokemon.empty?
    Kernel.pbMessage(_INTL("You have no Pokémon that can be sold."))
    return
  end

  pbChooseAblePokemonByType(1, 3, pokemon_type)
  chosen_index = pbGet(1)

  if chosen_index == -1
    return
  end

  chosen_pokemon = $Trainer.party[chosen_index]

  total_stats = chosen_pokemon.baseStats[:HP] +
                chosen_pokemon.baseStats[:ATTACK] +
                chosen_pokemon.baseStats[:DEFENSE] +
                chosen_pokemon.baseStats[:SPECIAL_ATTACK] +
                chosen_pokemon.baseStats[:SPECIAL_DEFENSE] +
                chosen_pokemon.baseStats[:SPEED]

  species_data = GameData::Species.get(chosen_pokemon.species)
  catch_rate = species_data.catch_rate

  base_price = total_stats - (catch_rate * 1) + (chosen_pokemon.level * 2)

  multiplier = 1

  base_price *= 2 if chosen_pokemon.shiny?
  base_price *= 2 if chosen_pokemon.ot == "Alpha"

  pokeball_price = (GameData::Item.get(species_data.egg_groups[0].to_sym).price rescue 0)
  if pokeball_price > 0
    base_price += pokeball_price
  end

  base_price += ((GameData::Item.get(chosen_pokemon.item).price rescue 0) / 2) if chosen_pokemon.item

  if Kernel.pbConfirmMessage(_INTL("Would you like to sell your {1} for ${2}?", chosen_pokemon.name, base_price))
    $Trainer.party.delete_at(chosen_index)
    $Trainer.money += base_price
    Kernel.pbMessage(_INTL("You sold your {1} for ${2}.", chosen_pokemon.name, base_price))
  else
    Kernel.pbMessage("Player declined the sale.")
  end
end

# Script Command:
# sellPokemonToNPC - Will allow selling of any type.
# sellPokemonToNPC(:WATER) - Will allow selling only Water-type Pokémon.
A script from my own game that has an NPC that asks for specific types of Pokemon that the NPC wishes to purchase. All types of Pokemon are also options. Just use the appropriate script commands at the bottom of the script. The event should have a conditional branch that makes sure the player has more than one pokemon and will refuse to purchase the player's last pokemon from their party. Their is a brief explanation of how to set this conditional branch up in an event. You can modify the equation that determines Pokemon value, but I based it on catch rate and total stats and added the cost of the pokeball used along with half the cost of any item the Pokemon may be holding. Shiny Pokemon are sold at double the normal rate. You may notice Alpha is also listed and is sold for double. My game uses a custom script that enables Alpha Pokemon; if your game does not, it should be fine. 

I give permission for anyone to use and modify this script for their own Pokemon projects. I will not be updating this script for use with higher versions of Pokemon Essentials and have no plans to add more functionality to the script. Credit: Pokemon Liberator

[CODE lang="ruby" title="Pokemon Broker"]################################################################################
# ChooseAblePokemonByType Method
################################################################################

def pbChooseAblePokemonByType(variableNumber, nameVarNumber, type = nil)
  eligible_pokemon = $Trainer.party.select do |pkmn|
    if type.nil?
      true
    else
      pkmn.hasType?(type)
    end
  end

  if eligible_pokemon.empty?
    Kernel.pbMessage(_INTL("You have no eligible Pokémon."))
    pbSet(variableNumber, -1)
    pbSet(nameVarNumber, "")
    return
  end

  chosen = pbChooseRosterPokemon(eligible_pokemon, _INTL("Choose a Pokémon."), -1)
  pbSet(variableNumber, chosen)
  pbSet(nameVarNumber, $Trainer.party[chosen].name)
end


################################################################################
# Pokemon Broker
################################################################################

def pbChooseAblePokemonByType(variableNumber, nameVarNumber, type = nil)
  pbChoosePokemon(variableNumber, nameVarNumber, proc { |pkmn|
    next false if pkmn.isEgg?
    next true if type.nil?  # Allow all Pokémon if type is not specified
    next pkmn.hasType?(type)
  })
end

def sellPokemonToNPC(pokemon_type = nil)
  eligible_pokemon = $Trainer.party.select do |pkmn|
    if pokemon_type
      pkmn.hasType?(pokemon_type)
    else
      true
    end
  end

  if eligible_pokemon.empty?
    Kernel.pbMessage(_INTL("You have no Pokémon that can be sold."))
    return
  end

  pbChooseAblePokemonByType(1, 3, pokemon_type)
  chosen_index = pbGet(1)

  if chosen_index == -1
    return
  end

  chosen_pokemon = $Trainer.party[chosen_index]

  total_stats = chosen_pokemon.baseStats[:HP] +
                chosen_pokemon.baseStats[:ATTACK] +
                chosen_pokemon.baseStats[:DEFENSE] +
                chosen_pokemon.baseStats[:SPECIAL_ATTACK] +
                chosen_pokemon.baseStats[:SPECIAL_DEFENSE] +
                chosen_pokemon.baseStats[:SPEED]

  species_data = GameData::Species.get(chosen_pokemon.species)
  catch_rate = species_data.catch_rate

  base_price = total_stats - (catch_rate * 1) + (chosen_pokemon.level * 2)

  multiplier = 1

  base_price *= 2 if chosen_pokemon.shiny?
  base_price *= 2 if chosen_pokemon.ot == "Alpha"

  pokeball_price = (GameData::Item.get(species_data.egg_groups[0].to_sym).price rescue 0)
  if pokeball_price > 0
    base_price += pokeball_price
  end

  base_price += ((GameData::Item.get(chosen_pokemon.item).price rescue 0) / 2) if chosen_pokemon.item

  if Kernel.pbConfirmMessage(_INTL("Would you like to sell your {1} for ${2}?", chosen_pokemon.name, base_price))
    $Trainer.party.delete_at(chosen_index)
    $Trainer.money += base_price
    Kernel.pbMessage(_INTL("You sold your {1} for ${2}.", chosen_pokemon.name, base_price))
  else
    Kernel.pbMessage("Player declined the sale.")
  end
end

# Script Command:
# sellPokemonToNPC - Will allow selling of any type.
# sellPokemonToNPC(:WATER) - Will allow selling only Water-type Pokémon.
# sellPokemonToNPC(:FIRE) - Will allow selling only FIRE-type Pokémon.

#Event Setup:
#Event Condition to prevent the last pokemon in the party from being sold should
#be $Trainer.ablePokemonCount==1 used in a condtional branch and the script commands
#placed in the else portion of the same condtional branch.


#Event Setup:
#Event Condition to prevent the last pokemon in the party from being sold should
#be $Trainer.ablePokemonCount==1 used in a condtional branch and the script commands
#placed in the else portion of the same condtional branch.[/CODE]
Credits
Credit if used: Pokemon Liberator
  • Like
Reactions: TechSkylander1518
Author
Pokemon Liberator
Views
1,131
First release
Last update

Ratings

0.00 star(s) 0 ratings

More resources from Pokemon Liberator

Back
Top