• 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.

Changing HM's to Item's Script(s)

6
Posts
9
Years
    • Seen Sep 11, 2015
    EDIT: I think I've figured out the problem, I changed the code in the original line to && instead of ||. I'm not sure if this is the complete fix but it fixed my problem. Since you will probably read this FL you should change this part of your guide if it is incorrect so other people don't have the same problems. I also had to comment the 'HiddenMoveHandlers::UseMove' part, but I could be doing it wrong but it fixed the problem for me. Cut now works only when I have the item. I'd still appreciate confirmation that I will not run into future errors :-)
    First, in PokemonHiddenMoves script section comment the 'HiddenMoveHandlers::CanUseMove' proc (all the code, inclusive the '})'). Change the line 'if $DEBUG || movefinder' (there's one for each move) to 'if $DEBUG || ($PokemonBag.pbQuantity(PBItems::YOURITEMINTERNALNAME)>0'. There's a item example for item.txt PBs:


    EDIT: I have all the HM's I want in my game as items working so if the code is needed just ask. I have Cut, Flash, Rock Smash, Fly, Surf, Strength


    So I've looked around a bit for the answer to my problem and I can't find it.
    Also, before you tell me to use the guide by FL, I did, and it helped me a lot.
    Thank you FL. (you should update\write it easier to understand :-) )

    I followed the guide as best as I could and pretty much do not understand why the script is not working properly.
    I'm pretty new at reading code for whatever language this is but I have experience in other languages so I find it easier than someone who has never done anything related.


    Now I might be an idiot and it will work properly in game and it's just debug mode. I am trying to change all HM's to items and add their usage with 'use' in the items bag, but here's one example of the problem (I assume it's for all of them because it's doing it for the other HMs code I haven't touched).


    First off I set all of the badge requirements in the Settings scripts to 0 so that you could just use them when you receive the item.


    I added this for the item in .txt file. I assume it's okay. The item name for cut is going to be Tree Zapper
    526,TREEZAPPER,Tree Zapper,8,0,"An invention from a crazy scientist used to remove small trees.",2,0,6


    I added the handlers in ItemEffects scripts

    ItemHandlers::UseFromBag.add(:TREEZAPPER,proc{|item|
    next canUseMoveCut? ? 2 : 0
    })
    ItemHandlers::UseInField.add(:TREEZAPPER,proc{|item|
    useMoveCut if canUseMoveCut?
    })






    And this is all of the code I have for cut in the HiddenMoves scripts including comments




    def Kernel.pbCut
    movefinder=Kernel.pbCheckMove(:CUT)
    if $DEBUG || $PokemonBag.pbQuantity(PBItems::TREEZAPPER) > 0
    Kernel.pbMessage(_INTL("This tree looks like it can be cut down!"))
    if Kernel.pbConfirmMessage(_INTL("Would you like to cut it?"))
    speciesname=!movefinder ? $Trainer.name : movefinder.name
    Kernel.pbMessage(_INTL("{1} used the Tree Zapper!\1",speciesname))
    pbHiddenMoveAnimation(nil)
    return true
    end
    else
    Kernel.pbMessage(_INTL("This tree looks like it can be cut down."))
    return false
    end
    end


    #HiddenMoveHandlers::CanUseMove.add(:CUT,proc{|move,pkmn|
    # if !$DEBUG &&
    # !(HIDDENMOVESCOUNTBADGES ? $Trainer.numbadges>=BADGEFORCUT : $Trainer.badges[BADGEFORCUT])
    # Kernel.pbMessage(_INTL("Sorry, a new Badge is required."))
    # return false
    # end
    # facingEvent=$game_player.pbFacingEvent
    # if !facingEvent || facingEvent.name!="Tree"
    # Kernel.pbMessage(_INTL("Can't use that here."))
    # return false
    # end
    # return true
    #})
    #HiddenMoveHandlers::UseMove.add(:CUT,proc{|move,pokemon|
    # if !pbHiddenMoveAnimation(nil)
    # Kernel.pbMessage(_INTL("{1} used {2}!",$trainer.name,Cut(move)))
    # end
    # facingEvent=$game_player.pbFacingEvent
    # if facingEvent
    # facingEvent.erase
    # $PokemonMap.addErasedEvent(facingEvent.id)
    # end
    # return true
    #})

    def canUseMoveCut?
    if !$DEBUG &&
    !(HIDDENMOVESCOUNTBADGES ? $Trainer.numbadges>=BADGEFORCUT : $Trainer.badges[BADGEFORCUT])
    Kernel.pbMessage(_INTL("Sorry, a new Badge is required."))
    return false
    end
    facingEvent=$game_player.pbFacingEvent
    if !facingEvent || facingEvent.name!="Tree"
    Kernel.pbMessage(_INTL("Can't use that here."))
    return false
    end
    return true
    end


    def useMoveCut
    if !pbHiddenMoveAnimation(nil)
    Kernel.pbMessage(_INTL("{1} used {2}!",$Trainer.name,"the Treezapper!"))
    end
    facingEvent=$game_player.pbFacingEvent
    if facingEvent
    facingEvent.erase
    $PokemonMap.addErasedEvent(facingEvent.id)
    end
    return true
    end


    I included the comments because it was part of the original code.
    Also the HIDDENMOVESCOUNTBADGES where it checks for badges was in the top part but I took it out because it seemed unnecessary and was confusing me, as well as having no difference in-game being there.



    Where did I go wrong? The result is that no matter what it will cut the tree. If it is a different problem, strength is working without any code being changed and having no pokemon with strength. However, the 'use' item (from bag)command works fine but I barely tested once I saw it working and had the bigger problem.
    So basically something is wrong, maybe I changed something and I need help because that code looks like it would work to me and it's not :[ we've all been frustrated at one point or another coding. I barely even ask for help but this is actually wasting too much of my time. All replies appreciated.
    Sorry if it's the wrong section. I didn't post this as a reply to the topic because it was an old topic and a long post. Also sorry it's long as finuck.
     
    Last edited:

    FL

    Pokémon Island Creator
    2,452
    Posts
    13
    Years
    • Seen today
    EDIT: I think I've figured out the problem, I changed the code in the original line to && instead of ||. I'm not sure if this is the complete fix but it fixed my problem. Since you will probably read this FL you should change this part of your guide if it is incorrect so other people don't have the same problems. I also had to comment the 'HiddenMoveHandlers::UseMove' part, but I could be doing it wrong but it fixed the problem for me. Cut now works only when I have the item. I'd still appreciate confirmation that I will not run into future errors :-)
    Yes, you need to remove/comment the HiddenMoveHandlers. otherside the player can use the HM move on pokémon menu.

    I changed the code in the original line to && instead of ||
    What "||"?
     
    Last edited:
    6
    Posts
    9
    Years
    • Seen Sep 11, 2015
    Yes, you need to remove/comment the HiddenMoveHandlers. otherside the player can use the HM move on pokémon menu.

    What "||"?

    "Change the line 'if $DEBUG || movefinder' (there's one for each move) to 'if $DEBUG || ($PokemonBag.pbQuantity(PBItems::YOURITEMINTERNALNAME)>0'"






    I changed it to
    'if $DEBUG && ($PokemonBag.pbQuantity(PBItems::YOURITEMINTERNALNAME)>0'


    And every HM/TM I have as an item works fine as far as I know besides the animation when you 'use' in bag but I don't mind that. I haven't tried dive or waterfall.
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • What you've just done is stonewalled any potential players. Your conditional branch will never return a boolean value of true, if you're not running the game in Debug mode. The "&&" part is the logic operator AND. And since you probably won't give players access to Debug mode, you have a problem on your hands. Not a solution.

    Anywho, you have a syntax error there. You're missing a ")".
     
    6
    Posts
    9
    Years
    • Seen Sep 11, 2015
    What you've just done is stonewalled any potential players. Your conditional branch will never return a boolean value of true, if you're not running the game in Debug mode. The "&&" part is the logic operator AND. And since you probably won't give players access to Debug mode, you have a problem on your hands. Not a solution.

    Anywho, you have a syntax error there. You're missing a ")".


    That doesn't really help me.


    If there is a syntax error, tell me where because the game starts up and there is no error with it.


    I'll post the code I have for cut so you can point out what I need to change to fix this


    Code:
    def Kernel.pbCut
      movefinder=Kernel.pbCheckMove(:CUT)
      if $DEBUG && $PokemonBag.pbQuantity(PBItems::TREEZAPPER) > 0
        Kernel.pbMessage(_INTL("This tree looks like it can be cut down!"))
        if Kernel.pbConfirmMessage(_INTL("Would you like to cut it?"))
          speciesname=!movefinder ? $Trainer.name : movefinder.name
          Kernel.pbMessage(_INTL("{1} used the Tree Zapper 9000!\1",speciesname))
          pbHiddenMoveAnimation(nil)
          return true
        end
      else
        Kernel.pbMessage(_INTL("This tree looks like it can be cut down."))
        return false
      end
    end
    
    
    def canUseMoveCut?
       if !$DEBUG &&
          !(HIDDENMOVESCOUNTBADGES ? $Trainer.numbadges>=BADGEFORCUT : $Trainer.badges[BADGEFORCUT])
         Kernel.pbMessage(_INTL("Sorry, a new Badge is required."))
         return false
       end
       facingEvent=$game_player.pbFacingEvent
       if !facingEvent || facingEvent.name!="Tree"
         Kernel.pbMessage(_INTL("Can't use that here."))
         return false
       end
       return true
    end
    def useMoveCut
       if !pbHiddenMoveAnimation(nil)
         Kernel.pbMessage(_INTL("{1} used {2}!",$Trainer.name,"the Treezapper 9000"))
       end
       facingEvent=$game_player.pbFacingEvent
       if facingEvent
         facingEvent.erase
         $PokemonMap.addErasedEvent(facingEvent.id)
       end
       return true
    end


    There is also 2 handlers for 'use' in the 'PokemonItemEffects' but I really don't see a problem with those.
    With the && it works but I am guessing that is for debug mode only, with the || it works without having the item.
    Will FL's original code work (with the ||), but just not in debug mode? That seems like something that should be added to the guide or changed in Essentials so people don't think it's broken.
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    With the && it works but I am guessing that is for debug mode only, with the || it works without having the item.
    Will FL's original code work (with the ||), but just not in debug mode? That seems like something that should be added to the guide or changed in Essentials so people don't think it's broken.
    It should be ||, not &&, in def Kernel.pbCut. You'd be smart to listen to the people telling you you're wrong.

    If you used &&, then you would only be able to cut shrubs IF you have the appropriate item AND you're playing Debug mode. If you're NOT playing in Debug mode (i.e. all players), then REGARDLESS of whether you have the appropriate item, you will NOT be able to cut shrubs. And that's not the effect you want.

    Debug mode (which you're in if you playtest the game from within RMXP) is for debugging. It is not an authentic presentation of the game. You want to be able to move around and do things quickly, for debugging and troubleshooting purposes. Therefore some scripts are altered to let you do this. You have access to a debug menu which gives you plenty of options, you can hold down Ctrl to walk over any tile at all, and you can use HMs even if you don't have a Pokémon that knows it. In this case, you'd want to be able to cut shrubs in Debug mode even if you don't have the appropriate item. Being able to cut shrubs in Debug mode even if you don't have the appropriate item is not a bug! Try it in the real game (the way everyone else will play) first to see if it works as intended or not, and then only complain about it if it doesn't.

    So you want to be able to cut shrubs in Debug mode regardless, AND be able to cut shrubs with the appropriate item if you're not in Debug mode. Of course, if you have BOTH the appropriate item AND are in Debug mode, you're also able to cut shrubs. The check for these conditions is best written as:

    Code:
    if $DEBUG [COLOR=Red]||[/COLOR] $PokemonBag.pbQuantity(PBItems::TREEZAPPER) > 0
    If the above doesn't get through to you, then consider how this code originally looked when it was checking for a Pokémon that knew the move Cut. It had a || then too, and it worked properly. Why would you change that if all you're doing is swapping a need for a known move to a need for an item?
     
    6
    Posts
    9
    Years
    • Seen Sep 11, 2015
    If the above doesn't get through to you, then consider how this code originally looked when it was checking for a Pokémon that knew the move Cut. It had a || then too, and it worked properly. Why would you change that if all you're doing is swapping a need for a known move to a need for an item?


    Because 3 days of coding experience in this language and using RMXP.
    The only things I have to go off of are other script languages I've learned in the past and testing what works for me when I tested my game.
    I appreciate the reply because I learned something and my code is now correct. I'd offer you and FL credits in my game for the help but you both are already on there at the top of the list... Thanks brother(s)
     
    Back
    Top