• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] Trainers using Revives

155
Posts
9
Years
  • Age 31
  • Seen Jun 11, 2021
I'm trying to modify the AI to where Trainers can use items like Revives and Max Revives in battle, but I'm not having a lot of luck with that.
Code:
if fullhp
        pbDisplay(_INTL("{1} became healthy!",battler.pbThis))
      else
        pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
      end
    [B][COLOR=Red]elsif isConst?(item,PBItems,:REVIVE) 
      pokemon.status=0
      pokemon.hp=(pokemon.totalhp/2).floor
      pbDisplay(_INTL("{1} was revived.",pokemon.name))
    elsif isConst?(item,PBItems,:MAXREVIVE)
      pokemon.status=0
      pokemon.hp=(pokemon.totalhp).floor
      pbDisplay(_INTL("{1} was fully revived.",pokemon.name))[/COLOR][/B]
    elsif isConst?(item,PBItems,:FULLHEAL)
      battler.status=0; battler.statusCount=0
      battler.effects[PBEffects::Confusion]=0
      pbDisplay(_INTL("{1} became healthy!",battler.pbThis))
    elsif isConst?(item,PBItems,:XATTACK)
      if battler.pbCanIncreaseStatStage?(PBStats::ATTACK,battler)
        battler.pbIncreaseStat(PBStats::ATTACK,1,battler,true)
      end
This code was what I changed in PokeBattle_Battle.
Code:
elsif isConst?(i,PBItems,:POTION) || 
         isConst?(i,PBItems,:SUPERPOTION) || 
         isConst?(i,PBItems,:HYPERPOTION) || 
         isConst?(i,PBItems,:MAXPOTION)
        return i if battler.hp<=battler.totalhp/4
        return i if battler.hp<=battler.totalhp/2 && pbAIRandom(10)<3
      [B][COLOR=Red]elsif isConst?(i,PBItems,:MAXREVIVE) ||     
         isConst?(i,PBItems,:REVIVE)
         return i if (battler.isFainted?)[/COLOR][/B]
      elsif isConst?(i,PBItems,:FULLHEAL)
        return i if !hashpitem &&
                    (battler.status>0 || battler.effects[PBEffects::Confusion]>0)
And this was what I changed in PokeBattle_AI. Does anyone have any suggestions to help me fix this?
 

Nickalooose

--------------------
1,309
Posts
16
Years
  • Seen Dec 28, 2023
Does the problem have anything to do with your codes having "pokemon." and the rest having "battler."?
 

Nickalooose

--------------------
1,309
Posts
16
Years
  • Seen Dec 28, 2023
The game will never allow an item to be used if a Pokémon is fainted anyway... So you'll have to come up with a solution to that.

Code:
  def pbEnemyItemToUse(index)
    return 0 if !@internalbattle
    items=pbGetOwnerItems(index)
    return 0 if !items
    battler=@battlers[index]
[B]    [COLOR=Red]return 0 if battler.isFainted? ||
                battler.effects[PBEffects::Embargo]>0[/COLOR][/B]
    hashpitem=false
    for i in items
      next if pbEnemyItemAlreadyUsed?(index,i,items)
      if isConst?(i,PBItems,:POTION) || 
         isConst?(i,PBItems,:SUPERPOTION) || 
         isConst?(i,PBItems,:HYPERPOTION) || 
         isConst?(i,PBItems,:MAXPOTION) ||
         isConst?(i,PBItems,:FULLRESTORE)
        hashpitem=true
      end
    end
    for i in items
      next if pbEnemyItemAlreadyUsed?(index,i,items)
      if isConst?(i,PBItems,:FULLRESTORE)
        return i if battler.hp<=battler.totalhp/4
        return i if battler.hp<=battler.totalhp/2 && pbAIRandom(10)<3
        return i if battler.hp<=battler.totalhp*2/3 &&
                    (battler.status>0 || battler.effects[PBEffects::Confusion]>0) &&
                    pbAIRandom(10)<3
      elsif isConst?(i,PBItems,:POTION) || 
         isConst?(i,PBItems,:SUPERPOTION) || 
         isConst?(i,PBItems,:HYPERPOTION) || 
         isConst?(i,PBItems,:MAXPOTION)
        return i if battler.hp<=battler.totalhp/4
        return i if battler.hp<=battler.totalhp/2 && pbAIRandom(10)<3
      elsif isConst?(i,PBItems,:FULLHEAL)
        return i if !hashpitem &&
                    (battler.status>0 || battler.effects[PBEffects::Confusion]>0)
      elsif isConst?(i,PBItems,:XATTACK) ||
            isConst?(i,PBItems,:XDEFEND) ||
            isConst?(i,PBItems,:XSPEED) ||
            isConst?(i,PBItems,:XSPECIAL) ||
            isConst?(i,PBItems,:XSPDEF) ||
            isConst?(i,PBItems,:XACCURACY)
        stat=0
        stat=PBStats::ATTACK if isConst?(i,PBItems,:XATTACK)
        stat=PBStats::DEFENSE if isConst?(i,PBItems,:XDEFEND)
        stat=PBStats::SPEED if isConst?(i,PBItems,:XSPEED)
        stat=PBStats::SPATK if isConst?(i,PBItems,:XSPECIAL)
        stat=PBStats::SPDEF if isConst?(i,PBItems,:XSPDEF)
        stat=PBStats::ACCURACY if isConst?(i,PBItems,:XACCURACY)
        if stat>0 && !battler.pbTooHigh?(stat)
          return i if pbAIRandom(10)<3-battler.stages[stat]
        end
      end
    end
    return 0
  end
I highlighted the reason where/why.
 
Back
Top