- Joined
- Jul 18, 2021
- Posts
- 140
- Age
- 41
Hi all, I have a few new scripts I have made and successfully ran multiple times. However, after making the second script, it seemed to mess up the first script. They both used pbChooseAblePokemon at the time, and it seemed to be the cause of the error when I looked at the backtrace log. I also started to receive the wrong number of argument errors. My goal is for both scripts to be usable in my game. Both scripts are used for separate events that, for playtesting purposes, are currently on the same map.
The first script is for my Pokemon Broker event. It calculates the value of the chosen pokemon using pbChooseAblePokemon and allows the player to sell that pokemon if they want. The script allows two different script commands. The first allows any pokemon type to be sold 'sellPokemonToNPC' and the second 'sellPokemonToNPC(:WATER)' allows the Pokemon Broker event to specify a specific pokemon type, and the player may only select and sell the specified type of pokemon.
The second script is for a custom mechanic called Primal Boost, which is similar to Hyper Training and requires level 100, except it raises IV's and lowers the selected pokemon's level. Primal Boost also calls its own scene from a separate script when it is performed. These are the script commands for the event I am using. 'primal_boost = PokemonPrimalBoost.new' and 'primal_boost.primal_boost_pokemon'
When I wrote these scripts, they both playtested fine. It was when I attempted to sell a primal boosted pokemon that I received an error related to 'pbChoosePokemon', and so I began restructuring both scripts along with altering both events so that both mechanics could coexist. This was a long, confusing process that I have worked on for several days now. I have rewritten the scripts so many times! However, I had the common sense to save both the working scripts in Notepad before changing them so many times. I wish I would have done something similar (sceenshots) for the event layouts. Anyway, all my modifications only led to more error messages, and I have reverted everything back to normal, or at least as far back to working as possible. I thought I would ask for some help and see if anyone has some insight.
Some of my modifications included trying to use pbChooseAblePokemon in the events and even creating separate methods in the UI_Party. I tried not to use pbChoosePokemon but found that it is used when the party screen is called. I had a miserable attempt at trying to create a copy of the party screen too. Maybe I have been wrong about pbChoosePokemon, but that is why I am here now. I will post both scripts below and attach the current error messages and event screenshots. Currently, my Pokemon Broker event has an error, but the line of script in the conditional branch looks correct to me, and I couldn't find anything online or on the Wiki. Please note that I am using v19.1, so it's $trainer, not $player.
If anyone decides to look at all this information, thank you for your time and effort! I will keep trying to get both scripts to function. Also, if the Primal Boost scene is needed, I can post that script as well. I will be watching this thread. These scripts are some of the last to complete my game.
The first script is for my Pokemon Broker event. It calculates the value of the chosen pokemon using pbChooseAblePokemon and allows the player to sell that pokemon if they want. The script allows two different script commands. The first allows any pokemon type to be sold 'sellPokemonToNPC' and the second 'sellPokemonToNPC(:WATER)' allows the Pokemon Broker event to specify a specific pokemon type, and the player may only select and sell the specified type of pokemon.
The second script is for a custom mechanic called Primal Boost, which is similar to Hyper Training and requires level 100, except it raises IV's and lowers the selected pokemon's level. Primal Boost also calls its own scene from a separate script when it is performed. These are the script commands for the event I am using. 'primal_boost = PokemonPrimalBoost.new' and 'primal_boost.primal_boost_pokemon'
When I wrote these scripts, they both playtested fine. It was when I attempted to sell a primal boosted pokemon that I received an error related to 'pbChoosePokemon', and so I began restructuring both scripts along with altering both events so that both mechanics could coexist. This was a long, confusing process that I have worked on for several days now. I have rewritten the scripts so many times! However, I had the common sense to save both the working scripts in Notepad before changing them so many times. I wish I would have done something similar (sceenshots) for the event layouts. Anyway, all my modifications only led to more error messages, and I have reverted everything back to normal, or at least as far back to working as possible. I thought I would ask for some help and see if anyone has some insight.
Some of my modifications included trying to use pbChooseAblePokemon in the events and even creating separate methods in the UI_Party. I tried not to use pbChoosePokemon but found that it is used when the party screen is called. I had a miserable attempt at trying to create a copy of the party screen too. Maybe I have been wrong about pbChoosePokemon, but that is why I am here now. I will post both scripts below and attach the current error messages and event screenshots. Currently, my Pokemon Broker event has an error, but the line of script in the conditional branch looks correct to me, and I couldn't find anything online or on the Wiki. Please note that I am using v19.1, so it's $trainer, not $player.
Pokemon Broker:
def pbChooseAblePokemon(type = nil)
return pbChoosePokemon(1, 3, 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
pbChooseAblePokemon(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("You declined the sale.")
end
end
# Script Commands:
#sellPokemonToNPC - Will allow selling of any type.
#sellPokemonToNPC(:WATER) - Will allow selling only Water-type Pokémon.
Primal Boost:
################################################################################
# Primal Boost
################################################################################
def pbChooseAblePokemon
return pbChoosePokemon(1, 3, proc { |pkmn|
next false if pkmn.isEgg?
next pkmn.level >= 100
})
end
class PokemonPrimalBoost
def initialize
@pokemon = nil
end
def valid_pokemon?(pokemon)
return true if pokemon.iv.values.any? { |iv| iv < 31 }
false
end
def choose_pokemon
pbChooseAblePokemon { |pkmn|
pkmn.level == 100
}
chosen_pokemon_index = pbGet(1)
return if chosen_pokemon_index == -1
@pokemon = $Trainer.party[chosen_pokemon_index]
end
def primal_boost_pokemon
choose_pokemon
return unless @pokemon
return unless valid_pokemon?(@pokemon)
increase_all_ivs_by_11(@pokemon)
reduce_level_and_experience_by_10(@pokemon)
@pokemon.calc_stats
# Call the original PokemonPrimalBoostScene here
scene = PokemonPrimalBoostScene.new
scene.pbStartScene(@pokemon)
scene.pbPrimalBoost
scene.pbEndScene
pbMessage(_INTL("{1} has been Primal Boosted!", @pokemon.name))
end
def increase_all_ivs_by_11(pokemon)
stats = [:HP, :ATTACK, :DEFENSE, :SPECIAL_ATTACK, :SPECIAL_DEFENSE, :SPEED]
stats.each do |stat|
current_iv = pokemon.iv[stat]
next if current_iv.nil?
# Increase the IV
pokemon.iv[stat] = [current_iv + 11, 31].min
end
end
def reduce_level_and_experience_by_10(pokemon)
new_level = [pokemon.level - 10, 1].max # Ensure level doesn't go below 1
pokemon.level = new_level
pokemon.exp = pokemon.growth_rate.minimum_exp_for_level(new_level)
end
end
If anyone decides to look at all this information, thank you for your time and effort! I will keep trying to get both scripts to function. Also, if the Primal Boost scene is needed, I can post that script as well. I will be watching this thread. These scripts are some of the last to complete my game.