• 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?".
  • Forum moderator applications are now open! Click here for details.
  • 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.

[Essentials Tutorial] Turn HM moves into items

195
Posts
7
Years
  • Age 27
  • Seen Mar 25, 2024
You're missing an end for your if
Code:
if $PokemonGlobal.flashUsed
  Kernel.pbMessage(_INTL("This is already in use"))
  return false
[COLOR="Red"]end[/COLOR]
return true

It worked! Thanks very much :)

EDIT: I just realised this code is just the base code for flash...and that doesn't help for me actually turning it into an item.
 
Last edited:
195
Posts
7
Years
  • Age 27
  • Seen Mar 25, 2024
Ok, as I see my previous edit didn't really get an answer, I'll double-post (though I don't want to).
So what I got given when I asked for help getting an alternative (in item form) for Flash was the base code for it. I must have been misunderstood then so I'm clearing it up. Now, can anyone help me with the code for a working Flash item?
 

FL

Pokémon Island Creator
2,434
Posts
13
Years
  • Seen yesterday
Ok, as I see my previous edit didn't really get an answer, I'll double-post (though I don't want to).
So what I got given when I asked for help getting an alternative (in item form) for Flash was the base code for it. I must have been misunderstood then so I'm clearing it up. Now, can anyone help me with the code for a working Flash item?
I tested right now and the method is equals to Cut one. It's even easier, since Flash can't be used outside menu.

The code:

Code:
605,LANTERN,Lantern,Lanterns,8,0,"A lantern that illuminate caves.",2,0,6

I copied the two HiddenMoveHandlers below (these are in base Essentials):

Code:
HiddenMoveHandlers::CanUseMove.add(:FLASH,proc{|move,pkmn|
   if !$DEBUG &&
      !(HIDDENMOVESCOUNTBADGES ? $Trainer.numbadges>=BADGEFORFLASH : $Trainer.badges[BADGEFORFLASH])
     Kernel.pbMessage(_INTL("Sorry, a new Badge is required."))
     return false
   end
   if !pbGetMetadata($game_map.map_id,MetadataDarkMap)
     Kernel.pbMessage(_INTL("Can't use that here."))
     return false
   end
   if $PokemonGlobal.flashUsed
     Kernel.pbMessage(_INTL("This is in use already."))
     return false
   end
   return true
})

HiddenMoveHandlers::UseMove.add(:FLASH,proc{|move,pokemon|
   darkness=$PokemonTemp.darknessSprite
   return false if !darkness || darkness.disposed?
   if !pbHiddenMoveAnimation(pokemon)
     Kernel.pbMessage(_INTL("{1} used {2}!",pokemon.name,PBMoves.getName(move)))
   end
   $PokemonGlobal.flashUsed=true
   while darkness.radius<176
     Graphics.update
     Input.update
     pbUpdateSceneMap
     darkness.radius+=4
   end
   return true
})

For making the two methods below. I added after the handlers:

Code:
def canUseMoveFlash?
  if !$DEBUG &&
    !(HIDDENMOVESCOUNTBADGES ? $Trainer.numbadges>=BADGEFORFLASH : $Trainer.badges[BADGEFORFLASH])
    Kernel.pbMessage(_INTL("Sorry, a new Badge is required."))
    return false
  end
  if !pbGetMetadata($game_map.map_id,MetadataDarkMap)
    Kernel.pbMessage(_INTL("Can't use that here."))
    return false
  end
  if $PokemonGlobal.flashUsed
    Kernel.pbMessage(_INTL("This is in use already."))
    return false
  end
  return true
end
 
def useMoveFlash
  darkness=$PokemonTemp.darknessSprite
  return false if !darkness || darkness.disposed?
  if !pbHiddenMoveAnimation(nil)
    Kernel.pbMessage(_INTL("{1} used {2}!",$Trainer.name,"Flash"))
  end
  $PokemonGlobal.flashUsed=true
  while darkness.radius<176
    Graphics.update
    Input.update
    pbUpdateSceneMap
    darkness.radius+=4
  end
  return true
end

And I added at PokemonItemEffects script section:

Code:
ItemHandlers::UseFromBag.add(:LANTERN,proc{|item|
   next canUseMoveFlash? ? 2 : 0
})

ItemHandlers::UseInField.add(:LANTERN,proc{|item|
   useMoveFlash if canUseMoveFlash?
})
 
195
Posts
7
Years
  • Age 27
  • Seen Mar 25, 2024
I tested right now and the method is equals to Cut one. It's even easier, since Flash can't be used outside menu.

The code:

Code:
605,LANTERN,Lantern,Lanterns,8,0,"A lantern that illuminate caves.",2,0,6

I copied the two HiddenMoveHandlers below (these are in base Essentials):

Code:
HiddenMoveHandlers::CanUseMove.add(:FLASH,proc{|move,pkmn|
   if !$DEBUG &&
      !(HIDDENMOVESCOUNTBADGES ? $Trainer.numbadges>=BADGEFORFLASH : $Trainer.badges[BADGEFORFLASH])
     Kernel.pbMessage(_INTL("Sorry, a new Badge is required."))
     return false
   end
   if !pbGetMetadata($game_map.map_id,MetadataDarkMap)
     Kernel.pbMessage(_INTL("Can't use that here."))
     return false
   end
   if $PokemonGlobal.flashUsed
     Kernel.pbMessage(_INTL("This is in use already."))
     return false
   end
   return true
})

HiddenMoveHandlers::UseMove.add(:FLASH,proc{|move,pokemon|
   darkness=$PokemonTemp.darknessSprite
   return false if !darkness || darkness.disposed?
   if !pbHiddenMoveAnimation(pokemon)
     Kernel.pbMessage(_INTL("{1} used {2}!",pokemon.name,PBMoves.getName(move)))
   end
   $PokemonGlobal.flashUsed=true
   while darkness.radius<176
     Graphics.update
     Input.update
     pbUpdateSceneMap
     darkness.radius+=4
   end
   return true
})

For making the two methods below. I added after the handlers:

Code:
def canUseMoveFlash?
  if !$DEBUG &&
    !(HIDDENMOVESCOUNTBADGES ? $Trainer.numbadges>=BADGEFORFLASH : $Trainer.badges[BADGEFORFLASH])
    Kernel.pbMessage(_INTL("Sorry, a new Badge is required."))
    return false
  end
  if !pbGetMetadata($game_map.map_id,MetadataDarkMap)
    Kernel.pbMessage(_INTL("Can't use that here."))
    return false
  end
  if $PokemonGlobal.flashUsed
    Kernel.pbMessage(_INTL("This is in use already."))
    return false
  end
  return true
end
 
def useMoveFlash
  darkness=$PokemonTemp.darknessSprite
  return false if !darkness || darkness.disposed?
  if !pbHiddenMoveAnimation(nil)
    Kernel.pbMessage(_INTL("{1} used {2}!",$Trainer.name,"Flash"))
  end
  $PokemonGlobal.flashUsed=true
  while darkness.radius<176
    Graphics.update
    Input.update
    pbUpdateSceneMap
    darkness.radius+=4
  end
  return true
end

And I added at PokemonItemEffects script section:

Code:
ItemHandlers::UseFromBag.add(:LANTERN,proc{|item|
   next canUseMoveFlash? ? 2 : 0
})

ItemHandlers::UseInField.add(:LANTERN,proc{|item|
   useMoveFlash if canUseMoveFlash?
})

Thanks very much, it's 100% working! :)
Whilst we're still on the subject, I've tried out your surf one and it no longer works, something about pbIsWaterTag?
 

Attachments

  • surfbug.png
    surfbug.png
    6.6 KB · Views: 4

FL

Pokémon Island Creator
2,434
Posts
13
Years
  • Seen yesterday
Thanks very much, it's 100% working! :)
Whilst we're still on the subject, I've tried out your surf one and it no longer works, something about pbIsWaterTag?
Did you tried the described on latest posts?
 

FL

Pokémon Island Creator
2,434
Posts
13
Years
  • Seen yesterday
I used that code and I got the error I posted before. pbWaterTag isn't being found.
I read the codes again and you was right. Changing 'pbIsWaterTag?(terrain)' to 'PBTerrain.isSurfable?(terrain)' should fix these problems.
 
195
Posts
7
Years
  • Age 27
  • Seen Mar 25, 2024
I read the codes again and you was right. Changing 'pbIsWaterTag?(terrain)' to 'PBTerrain.isSurfable?(terrain)' should fix these problems.

It fixed the initial activating surf animation issue. Now a new one has started, when I move in any direction in the water afterwards. I'll put an image below.
 

Attachments

  • error.png
    error.png
    21.6 KB · Views: 13

FL

Pokémon Island Creator
2,434
Posts
13
Years
  • Seen yesterday
It fixed the initial activating surf animation issue. Now a new one has started, when I move in any direction in the water afterwards. I'll put an image below.
I tested my tutorial again on V 16.2, even on bridges. The working code:

Code:
def canUseMoveSurf?
  if !$DEBUG &&
     !(HIDDENMOVESCOUNTBADGES ? $Trainer.numbadges>=BADGEFORSURF : $Trainer.badges[BADGEFORSURF])
    Kernel.pbMessage(_INTL("Sorry, a new Badge is required."))
    return false
  end
  if $PokemonGlobal.surfing
    Kernel.pbMessage(_INTL("You're already surfing."))
    return false
  end
  if $game_player.pbHasDependentEvents?
    Kernel.pbMessage(_INTL("It can't be used when you have someone with you."))
    return false
  end
  if pbGetMetadata($game_map.map_id,MetadataBicycleAlways)
    Kernel.pbMessage(_INTL("Let's enjoy cycling!"))
    return false
  end
  terrain=Kernel.pbFacingTerrainTag
  notCliff=$game_map.passable?($game_player.x,$game_player.y,$game_player.direction)
  if !PBTerrain.isSurfable?(terrain) || !notCliff
    Kernel.pbMessage(_INTL("No surfing here!"))
    return false
  end
  return true
end
 
def useMoveSurf
  $game_temp.in_menu=false
  if !pbHiddenMoveAnimation(nil)
    Kernel.pbMessage(_INTL("{1} used Surfboard!",$Trainer.name))
  end
  surfbgm=pbGetMetadata(0,MetadataSurfBGM)
  pbCueBGM(surfbgm,0.5) if surfbgm
  pbStartSurfing()
  return true
end
 
195
Posts
7
Years
  • Age 27
  • Seen Mar 25, 2024
I tested my tutorial again on V 16.2, even on bridges. The working code:

Code:
def canUseMoveSurf?
  if !$DEBUG &&
     !(HIDDENMOVESCOUNTBADGES ? $Trainer.numbadges>=BADGEFORSURF : $Trainer.badges[BADGEFORSURF])
    Kernel.pbMessage(_INTL("Sorry, a new Badge is required."))
    return false
  end
  if $PokemonGlobal.surfing
    Kernel.pbMessage(_INTL("You're already surfing."))
    return false
  end
  if $game_player.pbHasDependentEvents?
    Kernel.pbMessage(_INTL("It can't be used when you have someone with you."))
    return false
  end
  if pbGetMetadata($game_map.map_id,MetadataBicycleAlways)
    Kernel.pbMessage(_INTL("Let's enjoy cycling!"))
    return false
  end
  terrain=Kernel.pbFacingTerrainTag
  notCliff=$game_map.passable?($game_player.x,$game_player.y,$game_player.direction)
  if !PBTerrain.isSurfable?(terrain) || !notCliff
    Kernel.pbMessage(_INTL("No surfing here!"))
    return false
  end
  return true
end
 
def useMoveSurf
  $game_temp.in_menu=false
  if !pbHiddenMoveAnimation(nil)
    Kernel.pbMessage(_INTL("{1} used Surfboard!",$Trainer.name))
  end
  surfbgm=pbGetMetadata(0,MetadataSurfBGM)
  pbCueBGM(surfbgm,0.5) if surfbgm
  pbStartSurfing()
  return true
end

It must be something on my end then, because I'm still getting the error with PBEndSurf
 
3
Posts
6
Years
  • Age 29
  • Seen Feb 8, 2018
Hi, I am trying to get surf to work as a surfboard and I can pick up the item but when I go to surf it gives me this error:

[Pokémon Essentials version 17.2]

Exception: NoMethodError

Message: undefined method `hp' for nil:NilClass

Following Pokemon:419:in `check_surf'

Following Pokemon:880:in `pbSurf'

PField_FieldMoves:795

PField_FieldMoves:790:in `call'

EventHandlers:54:in `trigger'

EventHandlers:49:in `each'

EventHandlers:49:in `trigger'

Scene_Map:223:in `follow_update'

Following Pokemon:1551:in `update'

Scene_Map:234:in `main'

My code looks like this:

Code:
def Kernel.pbSurf
if $game_player.pbHasDependentEvents?
return false
end
if $DEBUG || movefinder=Kernel.pbCheckMove(:SURF)
if $DEBUG || $PokemonBag.pbQuantity(PBItems::SURFBOARD)>0
if Kernel.pbConfirmMessage(_INTL("The water is a deep blue, would you like to swim?"))
speciesname=!movefinder ? $Trainer.name : movefinder.name
Kernel.pbMessage(_INTL("You started swimming!",speciesname))

surfbgm=pbGetMetadata(0,MetadataSurfBGM)
if surfbgm
pbCueBGM(surfbgm,0.5)
end

pbStartSurfing()
return true
end
end
end
return false
end

def pbStartSurfing()
Kernel.pbCancelVehicles
$PokemonEncounters.clearStepCount
$PokemonGlobal.surfing=true
Kernel.pbUpdateVehicle
Kernel.pbJumpToward
Kernel.pbUpdateVehicle
$game_player.check_event_trigger_here([1,2])
end

def pbEndSurf(xOffset,yOffset)
return false if !$PokemonGlobal.surfing
x=$game_player.x
y=$game_player.y
currentTag=$game_map.terrain_tag(x,y)
facingTag=Kernel.pbFacingTerrainTag
if pbIsSurfableTag?(currentTag) && !pbIsSurfableTag?(facingTag)
if Kernel.pbJumpToward
Kernel.pbCancelVehicles
$game_map.autoplayAsCue
$game_player.increase_steps
result=$game_player.check_event_trigger_here([1,2])
Kernel.pbOnStepTaken(result)
end
return true
end
return false
end

Events.onAction+=proc{|sender,e|
terrain=Kernel.pbFacingTerrainTag
notCliff=$game_map.passable?($game_player.x,$game_player.y,$game_player.direction)
if PBTerrain.isSurfable?(terrain) && !$PokemonGlobal.surfing && 
!pbGetMetadata($game_map.map_id,MetadataBicycleAlways) && notCliff
Kernel.pbSurf
return
end
}

def canUseMoveSurf?
  if !$DEBUG &&
     !(HIDDENMOVESCOUNTBADGES ? $Trainer.numbadges>=BADGEFORSURF : $Trainer.badges[BADGEFORSURF])
    Kernel.pbMessage(_INTL("Sorry, a new Badge is required."))
    return false
  end
  if $PokemonGlobal.surfing
    Kernel.pbMessage(_INTL("You're already surfing."))
    return false
  end
  if $game_player.pbHasDependentEvents?
    Kernel.pbMessage(_INTL("It can't be used when you have someone with you."))
    return false
  end
  if pbGetMetadata($game_map.map_id,MetadataBicycleAlways)
    Kernel.pbMessage(_INTL("Let's enjoy cycling!"))
    return false
  end
  terrain=Kernel.pbFacingTerrainTag
  notCliff=$game_map.passable?($game_player.x,$game_player.y,$game_player.direction)
  if !PBTerrain.isSurfable?(terrain) || !notCliff
    Kernel.pbMessage(_INTL("No surfing here!"))
    return false
  end
  return true
end
 
def useMoveSurf
  $game_temp.in_menu=false
  if !pbHiddenMoveAnimation(nil)
    Kernel.pbMessage(_INTL("{1} used Surfboard!",$Trainer.name))
  end
  surfbgm=pbGetMetadata(0,MetadataSurfBGM)
  pbCueBGM(surfbgm,0.5) if surfbgm
  pbStartSurfing()
  return true
end

HiddenMoveHandlers::UseMove.add(:SURF,proc{|move,pokemon|
if !pbHiddenMoveAnimation(pokemon)
Kernel.pbMessage(_INTL("{1} used {2}!",pokemon.name,PBMoves.getName(move)))
end
pbStartSurfing()
return true
})

And this is for the item effects:

Code:
ItemHandlers::UseFromBag.add(:SURFBOARD,proc{|item|
   next canUseMoveSurf? ? 2 : 0
})

ItemHandlers::UseInField.add(:SURFBOARD,proc{|item|
   useMoveSurf if canUseMoveSurf?
})

and my item is defined as:
527,SURFBOARD,Surfboard,Surfboards,8,0,"This Surfboard is used to travel across the water.",2,0,6
 
3
Posts
6
Years
  • Age 29
  • Seen Feb 8, 2018
Hi, could I get a little help with my surf code? I am trying to replace the HM with a surfboard item which works up until I try to actually surf then it throws out this error:

[Pokémon Essentials version 17.2]

Exception: NoMethodError

Message: undefined method `hp' for nil:NilClass

Following Pokemon:419:in `check_surf'

Following Pokemon:880:in `pbSurf'

PField_FieldMoves:847

PField_FieldMoves:842:in `call'

EventHandlers:54:in `trigger'

EventHandlers:49:in `each'

EventHandlers:49:in `trigger'

Scene_Map:223:in `follow_update'

Following Pokemon:1551:in `update'

Scene_Map:234:in `main'

This is my code so far:

Code:
def Kernel.pbSurf
if $game_player.pbHasDependentEvents?
return false
end
if $DEBUG || movefinder=Kernel.pbCheckMove(:SURF)
if $DEBUG || $PokemonBag.pbQuantity(PBItems::SURFBOARD)>0
if Kernel.pbConfirmMessage(_INTL("The water is a deep blue, would you like to swim?"))
speciesname=!movefinder ? $Trainer.name : movefinder.name
Kernel.pbMessage(_INTL("You started swimming!",speciesname))

surfbgm=pbGetMetadata(0,MetadataSurfBGM)
if surfbgm
pbCueBGM(surfbgm,0.5)
end

pbStartSurfing()
return true
end
end
end
return false
end

def pbStartSurfing()
Kernel.pbCancelVehicles
$PokemonEncounters.clearStepCount
$PokemonGlobal.surfing=true
Kernel.pbUpdateVehicle
Kernel.pbJumpToward
Kernel.pbUpdateVehicle
$game_player.check_event_trigger_here([1,2])
end

def pbEndSurf(xOffset,yOffset)
return false if !$PokemonGlobal.surfing
x=$game_player.x
y=$game_player.y
currentTag=$game_map.terrain_tag(x,y)
facingTag=Kernel.pbFacingTerrainTag
if pbIsSurfableTag?(currentTag) && !pbIsSurfableTag?(facingTag)
if Kernel.pbJumpToward
Kernel.pbCancelVehicles
$game_map.autoplayAsCue
$game_player.increase_steps
result=$game_player.check_event_trigger_here([1,2])
Kernel.pbOnStepTaken(result)
end
return true
end
return false
end

Events.onAction+=proc{|sender,e|
terrain=Kernel.pbFacingTerrainTag
notCliff=$game_map.passable?($game_player.x,$game_player.y,$game_player.direction)
if PBTerrain.isSurfable?(terrain) && !$PokemonGlobal.surfing && 
!pbGetMetadata($game_map.map_id,MetadataBicycleAlways) && notCliff
Kernel.pbSurf
return
end
}

def canUseMoveSurf?
  if !$DEBUG &&
     !(HIDDENMOVESCOUNTBADGES ? $Trainer.numbadges>=BADGEFORSURF : $Trainer.badges[BADGEFORSURF])
    Kernel.pbMessage(_INTL("Sorry, a new Badge is required."))
    return false
  end
  if $PokemonGlobal.surfing
    Kernel.pbMessage(_INTL("You're already surfing."))
    return false
  end
  if $game_player.pbHasDependentEvents?
    Kernel.pbMessage(_INTL("It can't be used when you have someone with you."))
    return false
  end
  if pbGetMetadata($game_map.map_id,MetadataBicycleAlways)
    Kernel.pbMessage(_INTL("Let's enjoy cycling!"))
    return false
  end
  terrain=Kernel.pbFacingTerrainTag
  notCliff=$game_map.passable?($game_player.x,$game_player.y,$game_player.direction)
  if !PBTerrain.isSurfable?(terrain) || !notCliff
    Kernel.pbMessage(_INTL("No surfing here!"))
    return false
  end
  return true
end
 
def useMoveSurf
  $game_temp.in_menu=false
  if !pbHiddenMoveAnimation(nil)
    Kernel.pbMessage(_INTL("{1} used Surfboard!",$Trainer.name))
  end
  surfbgm=pbGetMetadata(0,MetadataSurfBGM)
  pbCueBGM(surfbgm,0.5) if surfbgm
  pbStartSurfing()
  return true
end

HiddenMoveHandlers::UseMove.add(:SURF,proc{|move,pokemon|
if !pbHiddenMoveAnimation(pokemon)
Kernel.pbMessage(_INTL("{1} used {2}!",pokemon.name,PBMoves.getName(move)))
end
pbStartSurfing()
return true
})

And this is what I have for the effects
Code:
ItemHandlers::UseFromBag.add(:SURFBOARD,proc{|item|
   next canUseMoveSurf? ? 2 : 0
})

ItemHandlers::UseInField.add(:SURFBOARD,proc{|item|
   useMoveSurf if canUseMoveSurf?
})

I have it defined in the items like this:
527,SURFBOARD,Surfboard,Surfboards,8,0,"This Surfboard is used to travel across the water.",2,0,6
 
Back
Top