• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Which Pokémon Masters protagonist do you like most? Let us know by casting a vote in our Masters favorite protagonist poll here!
  • Red, Hilda, Paxton, or Kellyn - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • 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] How do I get the game to identify if the Pokemon is fainted to use the Fly move out of battle?

How do I get the game to identify if the Pokemon is fainted so as not to use the Fly move out of battle?




#===============================================================================
# Fly
#===============================================================================
HiddenMoveHandlers::CanUseMove.add(:FLY,proc { |move,pkmn,showmsg|
next false if !pbCheckHiddenMoveBadge(BADGE_FOR_FLY,showmsg)
if $game_player.pbHasDependentEvents?
pbMessage(_INTL("It can't be used when you have someone with you.")) if showmsg
next false
end
if !pbGetMetadata($game_map.map_id,MetadataOutdoor)
pbMessage(_INTL("Can't use that here.")) if showmsg
next false
end
next true
})

HiddenMoveHandlers::UseMove.add(:FLY,proc { |move,pokemon|
if !$PokemonTemp.flydata
pbMessage(_INTL("Can't use that here."))
next false
end
if !pbHiddenMoveAnimation(pokemon)
pbMessage(_INTL("{1} used {2}!",pokemon.name,PBMoves.getName(move)))
end
pbFadeOutIn {
$game_temp.player_new_map_id = $PokemonTemp.flydata[0]
$game_temp.player_new_x = $PokemonTemp.flydata[1]
$game_temp.player_new_y = $PokemonTemp.flydata[2]
$game_temp.player_new_direction = 2
$PokemonTemp.flydata = nil
$scene.transfer_player
$game_map.autoplay
$game_map.refresh
}
pbEraseEscapePoint
$game_switches[500]=false
$game_switches[554]=false
next true
})
 
You could edit the can use move proc to check if the pkmn variable is fainted and next false if so.
Code:
  if pkmn.fainted?
    pbMessage(_INTL("{1} isn't in a state to fly.", pkmn.name)) if showmsg
    next false
  end

---------------------------
Error
---------------------------
Script '[PField_FieldMoves]' line 597: NameError occurred.

undefined local variable or method `pkmn' for nil:NilClass

from 'PField_FieldMoves' line 597
from 'PField_FieldMoves' line 592 in `call'
from 'Event_Handlers' line 140 in `trigger'
from 'PField_FieldMoves' line 40 in `triggerUseMove'
from 'PField_FieldMoves' line 55 in `pbUseHiddenMove'
from 'PScreen_ReadyMenu' line 265 in `pbStartReadyMenu'
from 'PScreen_ReadyMenu' line 247 in `loop'
from 'PScreen_ReadyMenu' line 288 in `pbStartReadyMenu'
from 'PScreen_ReadyMenu' line 324 in `pbUseKeyItem'
from 'Scene_Map' line 232 in `follow_update'
from '[Follower_Main]' line 1060 in `update'
from 'Scene_Map' line 247 in `main'
---------------------------
OK
---------------------------
 
---------------------------
Error
---------------------------
Script '[PField_FieldMoves]' line 597: NameError occurred.

undefined local variable or method `pkmn' for nil:NilClass

from 'PField_FieldMoves' line 597
from 'PField_FieldMoves' line 592 in `call'
from 'Event_Handlers' line 140 in `trigger'
from 'PField_FieldMoves' line 40 in `triggerUseMove'
from 'PField_FieldMoves' line 55 in `pbUseHiddenMove'
from 'PScreen_ReadyMenu' line 265 in `pbStartReadyMenu'
from 'PScreen_ReadyMenu' line 247 in `loop'
from 'PScreen_ReadyMenu' line 288 in `pbStartReadyMenu'
from 'PScreen_ReadyMenu' line 324 in `pbUseKeyItem'
from 'Scene_Map' line 232 in `follow_update'
from '[Follower_Main]' line 1060 in `update'
from 'Scene_Map' line 247 in `main'
---------------------------
OK
---------------------------

You modified the wrong handler.

Vendily's code should be in:
Code:
 HiddenMoveHandlers::CanUseMove.add(:FLY,proc { |move,pkmn,showmsg|
not in
Code:
 HiddenMoveHandlers::UseMove.add(:FLY,proc { |move,pokemon|
 
Back
Top