• 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.
  • Reminder: AI-generated content is not allowed on the forums per the Rules and Regulations. Please contact us if you have any questions!
Resource icon

v21.1 Advanced AI System 2.0.1

This resource pertains to version 21.1 of Pokémon Essentials.
### Critical Bug Fixes
#### PBDebug.log ArgumentError Crash

- Issue: PBDebug.log was being called with 2 arguments (message, category) but Pokémon Essentials v21.1 only accepts 1 argument (message)
Caused ArgumentError: wrong number of arguments (given 2, expected 1) crash when AI tried to switch Pokémon with debug mode enabled

  • Files: 4_Battle_Strategy/Switch_Intelligence.rb (lines 1388, 1409, 1430, 1450, 1459, 1468, 1807-1865)
  • Result: Debug logging now works correctly without crashes

#### Knock Off vs Unlosable Items
- Issue: AI was giving +100 bonus for using Knock Off against Mega Stones, but Mega Stones are unlosable items that cannot be removed by Knock Off
AI would incorrectly prioritize Knock Off against Pokémon holding Mega Stones, Z-Crystals, and other unlosable items
If you are upgrading from a previous version you MUST delete the old plugin folder completely before installing this version!


## Version 2.0.0
### Bug Fixes
#### Terastallization AI Improvements
  • Fixed Terastallization Eligibility: Corrected wild Pokémon Terastallization checks to properly allow Boss Pokémon with tera_type > 0 to Terastallize
  • Improved Tera Scoring Logic: Enhanced AI decision-making for when to use Terastallization in battle
  • AIBattler Wrapper Compatibility: Fixed method delegation issues in AIBattler wrapper for Terastallization-related methods
  • Battle Constant Access: Resolved incorrect calls to battle-related methods and constants in Tera intelligence
#### Compatibility Fixes
  • DBK Plugin Compatibility: Improved compatibility with Deluxe Battle Kit plugins, particularly for Terastallization and Dynamax mechanics
  • Method Delegation: Fixed missing method delegations in AIBattler wrapper class to ensure all Battle::Battler methods are properly accessible
  • Plugin Load Order: Resolved issues with plugin initialization and load order dependencies
#### General Stability
  • Nil Safety Checks: Added additional nil-safety checks throughout the codebase to prevent crashes
  • Error Handling: Improved error handling in AI decision-making processes
  • Debug Output: Enhanced debug logging for easier troubleshooting
### Code Quality Improvements
  • Code Documentation: Added inline comments for complex AI logic sections
  • Consistency: Standardized method naming conventions across modules
  • Performance: Minor optimizations in frequently-called AI methods

### New Features
#### Ability Handlers
- Wonder Guard (Shedinja):
- ONLY use super-effective moves (+100 if SE, -200 if neutral/NVE)
- Status moves still work (+40)
- Massively prioritize KO'ing Wonder Guard users (+80)

- Moody (Random stat boosts):
- +45 priority to KO before lucky boosts accumulate
- +35 urgency if already has 2+ boosted stats
- Haze/Clear Smog valued at +60 to reset random boosts
- 1.5x threat multiplier (unpredictable danger)

- Truant (Attacks every other turn):
- -60 threat reduction (massively crippled)
- +40 free setup/switch on rest turns
- +45 for setup moves vs Truant users (free boost time)
- 0.4x threat multiplier

- Slow Start (Halved Atk/Spe for 5 turns):
- +30 base advantage + 5 per remaining turn
- +40 reduced threat during active window
- -30 increased threat after Slow Start ends
- 0.5x threat during, 1.0x after

- Neutralizing Gas (Suppresses all abilities):
- Calculates net impact: our ability reliance vs opponent's
- +30 per critical opponent ability suppressed
- -35 per critical ally ability lost

- Gastro Acid (Permanent ability suppression):
- +90 vs critical abilities (Wonder Guard, Magic Bounce, Huge Power, etc.)
- +40 vs normal abilities
- -50 if target has no ability

#### Hyper-Specific Stat-Boost Items
- Adrenaline Orb (Speed +1 when Intimidated):
- -35 don't switch in Intimidate user (triggers their boost)
- -25 additional if opponent is offensive threat
- +20 if counters opponent's Intimidate

- Snowball (Attack +1 when hit by Ice):
- -30 using Ice move triggers +1 Attack on physical attacker
- +50 if KO anyway (override concern)
- +5 if target is special (Attack boost irrelevant)

- Absorb Bulb (SpAtk +1 when hit by Water):
- -35 Water move on special attacker = +1 SpAtk
- +10 if target is physical (SpAtk boost less relevant)

- Luminous Moss (SpDef +1 when hit by Water):
- -25 base penalty, -15 if using special moves
- Makes special attacks weaker

- Cell Battery (Attack +1 when hit by Electric):
- -30 Electric move on physical attacker
- +30 if target is Ground-type (immune, won't trigger)

- Throat Spray (SpAtk +2 when using sound move):
- +50 sound move triggers HUGE +2 SpAtk boost
- +30 for healthy sweepers getting boost
- +20 if have multiple sound moves
- 1.3x threat multiplier if target has sound moves

- Room Service (Speed -1 in Trick Room):
- +30 fast Pokemon in Trick Room (lower speed = better)
- -10 already slow Pokemon (wasteful)
- +20 if can set Trick Room
- +35 synergy with Trick Room setter

#### Combo Move Strategies
- Pledge Combinations (Fire/Water/Grass Pledge):
- +70 base combo score
- Sea of Fire (Fire+Grass): +45 passive burn damage, +25 vs healthy teams
- Rainbow (Water+Fire): +35 double secondary effect chance, +20 if have good effects
- Swamp (Grass+Water): +60 quarter opponent speed, +40 vs faster threats
- +30 combo power boost to 150 BP
- +20 if partner slower (combo this turn), -30 if faster (delayed)

- Fusion Moves (Fusion Flare/Bolt):
- +50 if partner has complementary move
- +30 if partner faster (guaranteed 2x power)
- +40 for 200 BP combined power

- Special Combo Moves:
- Electrify: +60 if we have Ground immunity (target's move becomes useless)
- After You: +40 make slow partner move early, +30 for setup, +25 for strong move
- Instruct: +70 ally repeats powerful move, +90 ally repeats setup (double boost!)

#### Gimmick Strategies
- Tera-Type Prediction:
- Common pattern database (Azumarill → Water/Fairy, Garchomp → Ground/Fire)
- Moveset analysis for STAB tera detection
- +60 if move matches predicted Tera type
- +50 if Tera boost secures KO
- +70 if Tera removes SE weakness
- 1.2x threat for opponents with Tera available

- Max Move Field Effects:
- Max Airstream (Flying): +70 Speed boost to team, +40 in Doubles, +35 to outspeed
- G-Max Steelsurge (Steel): +80 Stealth Rock, +25 per Flying/Fire/Bug/Ice opponent
- Weather Max Moves: Calculated weather benefits (Sun/Rain/Sand/Hail)
- Terrain Max Moves: +40 base, +30 for Electric move boost, +35 priority blocking
- Stat-Boost Max Moves: +50 for beneficial stats, +35 for opponent debuffs

- Z-Move Optimization:
- +90 if secures KO
- +60 if KOs last Pokemon (wins game)
- +40 if KOs win condition
- -40 if doesn't KO (wasted nuke)
- -50 if target already low HP (overkill)

#### Advanced Ability System
- Snowball Detection (Moxie, Beast Boost, Soul-Devouring, Chilling Neigh, Grim Neigh):
- Don't feed kills to Moxie users unless KO'ing them (+30 for KO, -20 for chip damage)
- Urgent priority (+25) if they already have +1 or more boosts
- Prevents snowball scenarios where one KO leads to sweep

- Reverse Ability Strategy (Contrary, Defiant, Competitive):
- NEVER use stat-lowering moves on Contrary (-50 penalty, inverts to buff!)
- Avoid Intimidate switch-ins vs Defiant/Competitive (-40, triggers +2)
- Prioritize KO'ing Contrary users before they set up with Leaf Storm
- Speed Shift Awareness (Unburden, Speed Boost, Slow Start):
- DON'T trigger Unburden with Knock Off (-35 unless KO)
- 2.5x threat multiplier when Unburden is active (no item)
- Detect Slow Start weakness (0.3x threat for 5 turns)
- Switch Ability Strategy (Regenerator, Natural Cure, Shed Skin):
- Predict Regenerator switches at 40-60% HP (free 33% heal)
- Penalty for forcing Regenerator out (-15 on Whirlwind/Roar)
- 1.4x threat multiplier for sustain potential

#### Disruption Move Intelligence
- Taunt Strategy:
- +60 vs setup sweepers (Swords Dance, Nasty Plot, etc.)
- +45 vs walls (blocks Recover, Roost, Wish)
- +35 vs hazard setters (Stealth Rock, Spikes)
- +15 if outspeeding (locks them in helplessly)
- Encore Strategy:
- +80 to lock setup moves (waste their turns)
- +70 to lock into immunity moves (free setup time)
- +50 to lock status moves (Protect, Recover becomes useless)
- -40 if locking into super-effective attacks (bad idea!)
- Knock Off Strategy:
- +100 vs Mega Stones (prevents Mega Evolution!)
- +70 vs Choice items (unlocks their moveset)
- +60 vs Focus Sash at full HP (removes survival)
- +50 vs defensive items (Leftovers, Assault Vest, Eviolite)
- +40 vs Heavy-Duty Boots if hazards are up
- Trick/Switcheroo Strategy:
- +80 to give Choice item to support Pokemon (cripples them)
- +60 to give Lagging Tail/Iron Ball (speed control)
- +50 to steal valuable items
- -40 penalty for losing our own valuable items

#### Advanced Item Awareness
- Pinch Berry Detection (Sitrus, Liechi, Salac, Custap, etc.):
- Don't chip Sitrus Berry into activation range (-20) unless KO through heal
- DON'T trigger stat-boost berries (-35 for Liechi/Petaya/Salac)
- 25%/50% HP activation thresholds per berry type
- Type Resist Berries (Occa, Passho, Wacan, etc.):
- -25 if our SE move will be halved
- +40 if we still KO through resistance
- Eject Mechanics (Eject Button, Red Card, Eject Pack):
- +15 to force weak targets out (Eject Button)
- -30 if Red Card forces us out
- -35 if Eject Pack lets them escape stat drops
- Air Balloon Strategy:
- -80 if using Ground move on balloon holder (immunity)
- +15 to pop it with any other move
- +10 bonus if we have Ground coverage for follow-up
- Weakness Policy:
- +30 if KO before trigger
- -50 if triggering +2/+2 boost
- -30 additional if target is high-offense sweeper
- Contact Damage (Rocky Helmet, Iron Barbs):
- -25 contact penalty at low HP
- +20 if move KOs despite recoil

#### Weather & Terrain Wars
- Weather Strategy:
- +50 to counter opponent's beneficial weather (Sun vs Rain team)
- Auto-calculate weather benefits (Fire moves in Sun, Water in Rain, etc.)
- +40 for ability synergy (Chlorophyll + Sun, Swift Swim + Rain)
- +30 for offensive weather (boosts our moves)
- +15 chip damage weather vs non-immune types
- Terrain Strategy:
- +45 to counter opponent's terrain
- Electric Terrain: +25 per Electric move, +15 sleep prevention
- Grassy Terrain: +20 per Grass move, +20 passive healing
- Misty Terrain: +25 per Dragon move opponent has, +20 status immunity
- Psychic Terrain: +25 per Psychic move, +30 priority blocking
- +35 for terrain ability synergy (Surge Surfer, Grass Pelt)

#### Special Move Strategies
- Pain Split:
- +80 if we're <35% HP and target >60% (huge heal)
- +40 if emergency (<20% HP, could save from KO)
- -40 if we're higher HP than target (lose HP)
- +20 vs high max HP targets (Blissey, Snorlax)
- Healing Wish / Lunar Dance:
- +50 per injured sweeper on team (heal win condition)
- +60 if last hope sacrifice (2v1 scenario)
- -70 if too healthy to sacrifice (>40% HP)
- Lunar Dance +30 for curing status
- Final Gambit:
- +100 if KOs target
- +50 if KOs boosted sweeper
- +80 if KOs last Pokemon (wins game!)
- -60 if doesn't KO and wastes sacrifice
- Memento:
- +70 vs boosted sweepers (cripple -2/-2)
- +50 vs high-offense threats
- -60 if too healthy (>30% HP)
- Rapid Spin / Defog:
- +30 per hazard layer removed
- +25 for Stealth Rock removal
- +15 per teammate weak to hazards
- Defog: +40 to remove opponent screens, -15 per opponent hazard removed
- Endeavor:
- +60 if target HP > 2x our HP
- +40 if we have priority follow-up
- -60 if we're >50% HP (useless)
- False Swipe:
- -999 score in PVP/Trainer battles (never use competitively!)
- Only acceptable in wild battles

---
#### Advanced Damage Calculation System
- Ability-Aware Calculations: Full implementation of 30+ abilities affecting damage:
- Immunities: Levitate (Ground), Volt/Water/Flash Fire Absorb, Sap Sipper, Wonder Guard
- Resistance Modifiers: Thick Fat (0.5x Fire/Ice), Filter/Solid Rock (0.75x super effective)
- Offensive Boosts: Adaptability (2.0x STAB), Huge/Pure Power (2x Attack), Guts (1.5x when statused)
- Defensive Boosts: Marvel Scale (1.5x Def when statused)
- Weather Synergy: Solar Power (1.5x SpA in Sun), Swift Swim/Chlorophyll/Sand Rush speed doubles
- Item-Aware Calculations:
- Offensive: Choice Band/Specs (1.5x), Life Orb (1.3x), type-boost items
- Defensive: Assault Vest (1.5x SpD), Eviolite (1.5x both defenses for NFE Pokemon)
  • Weather/Terrain Integration: Sun boosts Fire 1.5x & nerfs Water 0.5x, Rain opposite
  • Burn Mechanics: Physical moves halved by burn UNLESS attacker has Guts
  • Accurate Formula: Uses official Pokemon damage formula with level scaling, STAB, random roll averaging
#### Setup Move Detection System
  • Setup Move Database: 30+ setup moves tracked (Swords Dance, Dragon Dance, Nasty Plot, etc.)
  • Threat Evaluation: AI assigns threat scores based on opponent stat boosts
- +1 Offensive boost = 20 points threat
- +1 Speed boost = 15 points threat
- Moveset contains setup = +10 points
- Strategic Response: AI prioritizes switching or attacking boosted opponents before they snowball
#### Speed Tier Awareness
- Pre-Switch Speed Calc: Calculates party Pokemon speed BEFORE switching in
- Nature modifiers (Jolly/Timid +10%, Brave/Quiet -10%)
- Item effects (Choice Scarf 1.5x, Iron Ball 0.5x)
- Ability effects (Swift Swim in Rain, Chlorophyll in Sun, etc.)
  • Matchup Evaluation: +15 score for outspeeding opponent, -5 for being slower
  • OHKO Priority: +10 bonus if faster AND can hit super effectively
#### Debug & Analysis Tools
  • Damage Breakdown Logs: Shows complete calculation (effectiveness, stats, modifiers, abilities)
  • Switch Decision Logs: Explains WHY AI switched (or stayed) with detailed reasoning
  • Performance Tracking: Logs execution time for critical AI decisions
#### Performance Optimizations
  • Type Effectiveness Caching: Repeated type checks cached per battle
  • Setup Move Caching: Setup move lookups memoized
  • Constants Extraction: Magic numbers → named constants (STAB_MULTIPLIER, DAMAGE_RANDOM_MULTIPLIER, etc.)
---
### Bug Fixes
#### Critical Damage Calculation Bug
  • Issue: calculate_incoming_damage used hardcoded multipliers (2.0/1.0/0.5) instead of actual effectiveness values
  • Impact: AI overestimated damage by 2x for dual-type resistances (e.g., Ferroseed vs Electric showed 77% instead of 38.5%)
  • Fix: Now uses actual Effectiveness.calculate return value divided by NORMAL_EFFECTIVE_MULTIPLIER

#### Deprecated API Elimination
- Fixed 25 bugs total across 4 files:
- Move_Scorer.rb (4 fixes): user.lastMoveUseduser.battler.lastMoveUsed (AIBattler wrapper)
- Switch_Intelligence.rb (8 fixes): All .type1/.type2.types or .pbTypes(true)
- Pivot_Moves.rb (8 fixes): Fixed Pokemon::Move.damagingMove? error + type API
- Prediction_System.rb (4 fixes): Type access in prediction logic
- Duck-Typing Fix: Line 540 now checks is_a?(Battle::Battler) before choosing type accessor

#### Modularization Preparation
  • Separated cache initialization (initialize_switch_caches)
  • Separated speed calculations (calculate_party_speed)
  • Separated threat evaluation (evaluate_setup_threat)
  • Ready for future file splitting (damage_calculator.rb, setup_detector.rb, etc.)
---
### Testing & Validation
#### Verified Scenarios
  • Ferroseed (GRASS/STEEL) vs Electric = 0.5x damage (GRASS resists)
  • Charizard (FIRE/FLYING) vs Rock = 4.0x damage (both weak)
  • Levitate Pokemon immune to Ground moves
  • Thick Fat halves Fire/Ice damage correctly
  • Choice Band boosts physical damage by 1.5x
  • Burn halves physical damage UNLESS Guts active
  • Rain boosts Water 1.5x, nerfs Fire 0.5x


### Bug Fixes
#### Critical Fixes
  • Damage Calculation Bug: Fixed calculate_incoming_damage using hardcoded multipliers instead of actual effectiveness values
  • Tera Compatibility: Resolved compatibility issues with Terastallization mechanics
  • Division by Zero: Fixed error in PP_Tracker and crash in Hazard_Control
  • Burn Mechanics: Fixed burn damage reduction not applying to physical moves
  • Type-Boosting Items: Fixed items being overlooked in damage calculations
#### Move Behavior Fixes
  • Move Repetition Spam: Implemented score_move_repetition_penalty (-40 for status, -15 for attacks)
  • Move Memory Tracking: Now tracks ALL battlers' moves for proper prediction
  • Redundant Status Moves: Added failure checks for Leech Seed, Substitute, Yawn, Taunt, Encore, etc.
  • Status Condition Spam: Added checks for 20+ status moves vs already-statused targets
  • Screen/Hazard Spam: Fixed setting up already-active screens/hazards
#### API Fixes
  • Deprecated Types API: Fixed 13 instances using .types[0] instead of pbTypes(true)
  • Misty Terrain Bug: Fixed incorrect hasActiveAbility?([:LEVITATE]) syntax
  • AIBattler Wrapper: Fixed user.lastMoveUseduser.battler.lastMoveUsed
  • Duck-Typing Fix: Proper is_a?(Battle::Battler) checks before type accessor
  • Battler Index Safety: Added get_battler_index() helper for handling Battler objects and integer indices
AAi scans now for installed DBK PLugins to prevent Nomethode crashes
### Critical Fixes
  • Move Scoring Integration: Fixed a major bug where score_move_advanced was defined but never called. The AI now correctly uses the intended comprehensive scoring logic (defined in Move_Scorer.rb) instead of falling back to vanilla behavior.
  • AIMove Reliability: Patched Battle::AI::AIMove with method_missing delegation to prevent persistent NoMethodError crashes (e.g., power, multiHitMove?, battler) by forwarding all checks to the underlying move object.
  • Accuracy Crash: Resolved a crash in Move_Scorer.rb related to accuracy checks by accessing the move's raw integer accuracy instead of the context-dependent AIMove#accuracy.
### Technical Details
- Core.rb Hook: Explicitly connected pbGetMoveScore to score_move_advanced for qualified skill levels.
### Critical Fixes
  • Wild Pokemon Visuals: Fixed glitches where Dynamax/Tera sprites reverted immediately after animation.
  • DBK Compatibility: Patched placeholders overriding tera?/dynamax? methods.
  • Crash Fixes: Resolved pbCalcTypeMod Method Error and missing icon crashes.
### New Features
  • Smart Wild AI: Wild Pokemon now use Advanced AI logic (Level 85+).
  • Wild Gimmicks: Wild Pokemon can now use Dynamax.
  • Event-Only Wild Tera: Wild Pokemon only Terastallize if explicitly configured (e.g. setBattleRule("editWildPokemon", { :tera_type => :WATER })).
### Improvements
  • KO Detection: AI heavily penalizes switching if it can secure a KO (-60 score penalty).
  • Switch Safety: Improved damage calculation logic for defensive switching decisions.
  • Debug Mode: Advanced AI automatically activates when DEBUG_MODE is on.
### Added
- KO Opportunity Detection: AI now recognizes when it can secure a knockout and heavily discourages switching in these scenarios
- New can_ko_opponent? method calculates damage estimates for all moves
- Applies -60 point penalty to switch score when KO is available
- Accounts for STAB, type effectiveness, and damage roll variance (85% threshold)
- Prevents AI from losing momentum by switching away from guaranteed KOs
### Fixed
- Console Output Method: Corrected console logging method from Console.echo_li to Console.echoln_li
- Fixes debug messages not appearing during battles
- All AAI debug output now displays correctly with proper formatting
- Colons and category labels now visible in console
### Changed
- Switch Scoring System: Expanded from 10 to 11 evaluation factors
- Factor 11: "Can Secure KO" penalty ensures AI prioritizes finishing weakened opponents
- Debug console now shows [11/11] for the new KO detection factor
### Technical Details
Files Modified:
  • [001] Settings.rb - Fixed console method, added DEBUG_MODE activation
  • [012] Switch_Intelligence.rb - Added KO detection and switch penalty
Switch Intelligence Improvements:
  • KO detection checks all damaging moves against all opponents
  • Conservative damage formula: (Attack * Power / Defense) * STAB * Effectiveness / 100
  • 85% HP threshold accounts for random damage rolls
  • Ignores type-immune moves (can't KO with 0x effectiveness)
Mediafire didnt overide the last upload

Right file is up now
# Advanced AI System - Patch Notes

## Version 1.5.3 (Hotfix & Logic Update)
  • Crash Fix (Field Effects): Resolved undefined method 'priority' error by safely checking move properties.
  • Crash Fix (Mechanics Hooks): Fixed undefined method 'pbRegisterEnemySpecialAction' compatibility issue with Essentials v21.1.
  • Switch Intelligence:
- Ping-Pong Prevention: Increased the penalty for switching immediately after entering battle (-20 -> -40) to stop the AI from rapidly switching back and forth.
- ReserveLastPokemon: Added robust trainer detection and debug logging to ensure the Ace is correctly reserved until the end.
- Setup Logic:
- Curse Support: Added proper support for non-standard setup moves like Curse using the internal move database.
- Safety Check: Fixed a syntax error in the setup safety check.

## Switch Intelligence
  • ReserveLastPokemon Support: Fixed an issue where the AI would switch into its Ace (last Pokemon) prematurely. It now respects the ReserveLastPokemon trainer flag.
  • Switch Loop Fix: Implemented stability checks to prevent the AI from endlessly switching between two Pokemon with similar matchups.

remember if i use the reservelastpokemon option you need to add teh flag in trainers.txt

[LEADER_BROCK,Brock,1]
Items = FULLRESTORE,FULLRESTORE
LoseText = "Good match!"
Skill = 100
Flags = ReserveLastPokemon
Pokemon = GEODUDE,12
Pokemon = VULPIX,12
Moves = EMBER,QUICKATTACK
Pokemon = ONIX,14
Moves = ROCKTOMB,BIND,TACKLE
Switch Intelligence
ReserveLastPokemon Support**: Fixed an issue where the AI would switch into its Ace (last Pokemon) prematurely. It now respects the ReserveLastPokemon trainer flag.
Switch Loop Fix**: Implemented stability checks to prevent the AI from endlessly switching between two Pokemon with similar matchups.

Added a new Rule in Settings
RESPECT_RESERVE_LAST_POKEMON = true

You can turn it off with falsee

Move Scoring (Critical Hits)
Always Critical Hits*: Moves like *Flower Trick and Wiked Blow now correctly calculate their damage with a 1.5x multiplier.
Focus Energy Synergy**: The AI now heavily prioritizes using Focus Energy + High Crit Rate moves to guarantee critical hits.
Smart Stat Bypassing**: The AI now recognizes that critical hits ignore:
The Target's positive Defense/Sp.Def boosts (e.g. counter to Iron Defense).
The User's negative Attack/Sp.Atk drops (e.g. counter to Intimidate).
Immunity Awareness*: The AI will no longer attempt critical hit strategies against targets with *Battle Armor, Shell Armor, or Lucky Chant.
Sticky Web support
Better Crit logic
Smarter Screens (No redundancy + Context awareness)
Code Refactoring (Simpler, cleaner code)
Back
Top