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

[Essentials Tutorial] Register multiple items

FL

Pokémon Island Creator
2,450
Posts
13
Years
    • Seen today
    Essentials has the feature of register a item with a key (F5). This tutorial explain how to add more keys simultaneous. In this example I gonna add F4 and F3, but I teach how to add others.

    At PSystem_Controls script section

    As F4 and F3 aren't mapped in input, we need to map. Before line

    Code:
    when Input::F5

    add

    Code:
    when Input::F3
            return [0x72] # F3
          when Input::F4
            return [0x73] # F4

    The order doens't matter if is in the "case" statement. The 0x72 and 0x73 are the F3/F4 codes in keyboard (there's a list here). Before line:

    Code:
    F5    = 25

    add

    Code:
    F3    = 31
    F4    = 32

    The order and the code doens't matter if they are in the module Input. Just make sure that the numbers (31 and 32) aren't the same as other constants in this module. If the F3 and F4 keys are mapped, we don't have to do the two above code changes. Before line

    Code:
    LeftMouseKey  = 1

    add

    Code:
    ITEMKEYS      = [Input::F5,Input::F4,Input::F3]
    ITEMKEYSNAMES = [_INTL("F5"),_INTL("F4"),_INTL("F3")]

    These two arrays store all the key that you can register items. If you wish to add more keys, just include in these two arrays, map in input (if the keys aren't mapped) and add an icon. Note about keys that do other things, so if you add the F8 (button that take screenshots) every time that you hits F8 you take a screenshot AND do the effects of a registered key.

    The picture that appears at right of the item name at bag is named bagRegX.png in folder Graphics\Pictures, where X is the array index starting in 0, so in this example we need the bagReg0.png (F5), bagReg1.png (F4) and bagReg2.png (F3).

    At Scene_Map script section

    Change:

    Code:
    if Input.trigger?(Input::F5)
      unless pbMapInterpreterRunning?
        $PokemonTemp.keyItemCalling = true if $PokemonTemp
      end
    end

    to

    Code:
    unless pbMapInterpreterRunning?
      for keyNumber in 0...Input::ITEMKEYS.size
        if Input.trigger?(Input::ITEMKEYS[keyNumber]) && $PokemonTemp
          $PokemonTemp.keyItemCalling = keyNumber 
        end
      end
    end

    Change

    Code:
    $PokemonTemp.keyItemCalling=false
    $game_player.straighten
    Kernel.pbUseKeyItem

    to

    Code:
    $game_player.straighten
    Kernel.pbUseKeyItem($PokemonTemp.keyItemCalling)
    $PokemonTemp.keyItemCalling=nil

    At PField_Field script section

    Change

    Code:
    def pbUseKeyItem
      if $PokemonBag.registeredItem==0
        Kernel.pbMessage(_INTL("A Key Item in the Bag can be registered to this key for instant use."))
      else
        Kernel.pbUseKeyItemInField($PokemonBag.registeredItem)
      end
    end

    to

    Code:
    def pbUseKeyItem(itemKeyNumber)
      if $PokemonBag.registeredItem[itemKeyNumber]==nil
        Kernel.pbMessage(_INTL("A Key Item in the Bag can be registered to this key for instant use."))
      else
        Kernel.pbUseKeyItemInField($PokemonBag.registeredItem[itemKeyNumber])
      end
    end

    At PField_Metadata script section

    Change

    Code:
    @keyItemCalling         = false

    to

    Code:
    @keyItemCalling         = nil

    At PScreen_Bag script section

    Change

    Code:
    if @[email protected][self.pocket][index][0]
      pbDrawImagePositions(self.contents,[
         ["Graphics/Pictures/bagReg",rect.x+rect.width-58,ypos+4,0,0,-1,-1]
      ])
    end

    to

    Code:
    i = @bag.registeredItem.index(@bag.pockets[self.pocket][index][0]) 
    if i
      pbDrawImagePositions(self.contents,[
         [sprintf("Graphics/Pictures/bagReg#{i}"),rect.x+rect.width-58,ypos+4,0,0,-1,-1]
      ])
    end

    Change

    Code:
    attr_reader :registeredItem

    to

    Code:
    def registeredItem
      # The below line is to this change don't mess with existing saves
      @registeredItem = [@registeredItem] if [email protected]_a?(Array) 
      while @registeredItem.size<Input::ITEMKEYS.size
        @registeredItem.push(nil)
      end
      return @registeredItem
    end

    Change

    Code:
    @registeredItem=0

    to

    Code:
    @registeredItem=[]

    Change

    Code:
    def pbRegisterKeyItem(item)
      if item.is_a?(String) || item.is_a?(Symbol)
        item=getID(PBItems,item)
      end
      if !item || item<1
        raise ArgumentError.new(_INTL("The item number is invalid."))
        return
      end
      @registeredItem=(item!=@registeredItem) ? item : 0
    end

    to

    Code:
    def pbRegisterKeyItem(item,itemKeyNumber)
      if item.is_a?(String) || item.is_a?(Symbol)
        item=getID(PBItems,item)
      end
      if !item || item<1
        raise ArgumentError.new(_INTL("The item number is invalid."))
        return
      end
      index = registeredItem.index(item)
      registeredItem[index]=nil if index # remove duplicates
      registeredItem[itemKeyNumber]=item if !index || index!=itemKeyNumber
    end

    Change

    Code:
    @registeredItem=0 if @registeredItem==item && !pbHasItem?(item)

    to

    Code:
    index = registeredItem.index(item)
    registeredItem[index]=nil if index && !pbHasItem?(item)

    Change

    Code:
    if @bag.registeredItem==item
      commands[cmdRegister=commands.length]=_INTL("Deselect")
    elsif pbIsKeyItem?(item) && ItemHandlers.hasKeyItemHandler(item)
      commands[cmdRegister=commands.length]=_INTL("Register")
    end

    to

    Code:
    commands[cmdRegister=commands.length]=_INTL("Register") if pbIsKeyItem?(item) && ItemHandlers.hasKeyItemHandler(item)

    Change

    Code:
    @bag.pbRegisterKeyItem(item)

    to

    Code:
    registerCommands = Input::ITEMKEYSNAMES + [_INTL("Back")]
    registerCommand = @scene.pbShowCommands(
        _INTL("Choose a key.",itemname),registerCommands)
    @bag.pbRegisterKeyItem(item,registerCommand) if registerCommand!=-1 && registerCommand!=registerCommands.size
     

    Attachments

    • bagReg0.PNG
      bagReg0.PNG
      365 bytes · Views: 850
    • bagReg1.PNG
      bagReg1.PNG
      380 bytes · Views: 852
    • bagReg2.PNG
      bagReg2.PNG
      381 bytes · Views: 849
    Last edited:

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen yesterday
    Personally I think it'd be easier to make F5 open a menu listing all the registered items, and then choose one of them to use.
     

    venom12

    Pokemon Crystal Rain Relased
    476
    Posts
    17
    Years
    • Age 33
    • Seen Dec 28, 2023
    Yah i also think about the open list something like in Pokemon BW. Btw good tutorial :)
     

    Black Eternity

    Lord of Eternity
    57
    Posts
    11
    Years
    • Seen Jun 30, 2016
    Personally I would rather use FL's method, in the sense that if I just wanted to use Super Rod over and over, it's just a press of a button. With the menu idea, I would have to keep opening the menu and select what I want, with his method you are completely eliminating more key presses.
     

    thor348

    That's Oak to You
    137
    Posts
    11
    Years
  • At Scene_Map script section

    Change

    Code:
    def pbUseKeyItem
      if $PokemonBag.registeredItem==0
        Kernel.pbMessage(_INTL("A Key Item in the Bag can be registered to this key for instant use."))
      else
        Kernel.pbUseKeyItemInField($PokemonBag.registeredItem)
      end
    end

    to

    Code:
    def pbUseKeyItem(itemKeyNumber)
      if $PokemonBag.registeredItem[itemKeyNumber]==nil
        Kernel.pbMessage(_INTL("A Key Item in the Bag can be registered to this key for instant use."))
      else
        Kernel.pbUseKeyItemInField($PokemonBag.registeredItem[itemKeyNumber])
      end
    end

    This is found in PokemonField, not Scene_Map.

    But excellent job on this, I like having multiple buttons to register items.
     

    FL

    Pokémon Island Creator
    2,450
    Posts
    13
    Years
    • Seen today
    Personally I think it'd be easier to make F5 open a menu listing all the registered items, and then choose one of them to use.
    I didn't think this list before. Your way is less practic and less confusing. I prefer my way, but maybe I implements yours in the future.

    This is found in PokemonField, not Scene_Map.

    But excellent job on this, I like having multiple buttons to register items.
    Thanks! I make a mistake while copying/pasting, now it's fixed.
     

    Wootius

    Glah
    300
    Posts
    11
    Years
    • Seen May 31, 2022
    Honestly I prefer separate buttons. I have a whole keyboard and 1-10 just waiting to be used.

    I'm going to go crazy with this, thanks for posting it!
     
    Last edited:

    Rayd12smitty

    Shadow Maker
    645
    Posts
    12
    Years
    • Seen Feb 21, 2016
    So I tried this with using Number keys 1,2, and 3 instead, and my game keeps crashing. (script taking too long) whenever I open the bag, and the game just freezes when I try pressing 1, 2, or 3. I followed your directions exactly, other than switching 1,2 and 3 wherever it said f5, f3, and f4. I looked up the key codes and they are (0x31) (0x32) and (0x33). Any idea what might be going wrong? Here is the controls script where it is changed.

    Code:
    module Input
      DOWN  = 2
      LEFT  = 4
      RIGHT = 6
      UP    = 8
      A     = 11
      B     = 12
      C     = 13
      X     = 14
      Y     = 15
      Z     = 16
      L     = 17
      R     = 18
      SHIFT = 21
      CTRL  = 22
      ALT   = 23
      One   = 31
      Two   = 32
      Three = 33
      F5    = 25
      F6    = 26
      F7    = 27
      F8    = 28
      F9    = 29
      ITEMKEYS      = [Input::One,Input::Two,Input::Three]
      ITEMKEYSNAMES = [_INTL("One"),_INTL("Two"),_INTL("Three")]
      LeftMouseKey  = 1

    and

    Code:
          when Input::One
            return [0x31] # One
          when Input::Two
            return [0x32] # Two
          when Input::Three
            return [0x33] # Three
          when Input::F5
            return [0x74] # F5

    I am using Essentials Version 11 still so that may be part of/all of the problem. I don't plan on switching to Version 12, at least not yet, so I would be really happy if someone could help me.
     

    FL

    Pokémon Island Creator
    2,450
    Posts
    13
    Years
    • Seen today
    A trivia: I spend more time detailing the steps of where copy/paste the code than making the feature itself.
    So I tried this with using Number keys 1,2, and 3 instead, and my game keeps crashing. (script taking too long) whenever I open the bag, and the game just freezes when I try pressing 1, 2, or 3. I followed your directions exactly, other than switching 1,2 and 3 wherever it said f5, f3, and f4. I looked up the key codes and they are (0x31) (0x32) and (0x33). Any idea what might be going wrong? Here is the controls script where it is changed.

    Code:
    module Input
      DOWN  = 2
      LEFT  = 4
      RIGHT = 6
      UP    = 8
      A     = 11
      B     = 12
      C     = 13
      X     = 14
      Y     = 15
      Z     = 16
      L     = 17
      R     = 18
      SHIFT = 21
      CTRL  = 22
      ALT   = 23
      One   = 31
      Two   = 32
      Three = 33
      F5    = 25
      F6    = 26
      F7    = 27
      F8    = 28
      F9    = 29
      ITEMKEYS      = [Input::One,Input::Two,Input::Three]
      ITEMKEYSNAMES = [_INTL("One"),_INTL("Two"),_INTL("Three")]
      LeftMouseKey  = 1

    and

    Code:
          when Input::One
            return [0x31] # One
          when Input::Two
            return [0x32] # Two
          when Input::Three
            return [0x33] # Three
          when Input::F5
            return [0x74] # F5

    I am using Essentials Version 11 still so that may be part of/all of the problem. I don't plan on switching to Version 12, at least not yet, so I would be really happy if someone could help me.
    I believe that this have nothing about the Essentials Version, you probably miss something. I tests in a old Essentials version with these numbers and them are working! Try to change to F5, F4 and F3 and test before changing to numbers.
     

    Rayd12smitty

    Shadow Maker
    645
    Posts
    12
    Years
    • Seen Feb 21, 2016
    Hello again... So I am using essentials Version 12.2 and have followed your steps EXACTLY, double checking 2 or 3 times. Everything we have matches perfectly. Whenever I try pressing F3-F5, the game crashes saying the script is taking too long. If I even have a key item in the bag, registered or not, and try to open the bag, the game crashes. Any ideas?
     

    venom12

    Pokemon Crystal Rain Relased
    476
    Posts
    17
    Years
    • Age 33
    • Seen Dec 28, 2023
    Hello again... So I am using essentials Version 12.2 and have followed your steps EXACTLY, double checking 2 or 3 times. Everything we have matches perfectly. Whenever I try pressing F3-F5, the game crashes saying the script is taking too long. If I even have a key item in the bag, registered or not, and try to open the bag, the game crashes. Any ideas?

    I used this in Essentials 12.2 and followed tutorial step by step and it is working fine for me. Try again on clean script.
     

    Rayd12smitty

    Shadow Maker
    645
    Posts
    12
    Years
    • Seen Feb 21, 2016
    I used this in Essentials 12.2 and followed tutorial step by step and it is working fine for me. Try again on clean script.

    So weird:/ I just downloaded Essentials 13 so I'm going to test it on that before doing any other changes, see if it works, and then add my other script changes one by one to see which one is messing it up, if any.
     
    178
    Posts
    10
    Years
  • Sorry for the necropost, but what are the changes that I need to make in Pokémon Essentials 16.2? There are some sections that don't exist anymore in the recent version, and I guess all the scripts changed their names so I can't easily find which sections I need to modify.

    Before anything, I did Ctrl+F in every scripts, and couldn't find some of the sections that showed-up in the tutorial. So I'm sure that some scripts, despise having similar functionalities, got modifications in the Essentials 16.2 that makes this tutorial rather useless for now.

    I would be glad if you could update the tutorial to make it work with the most recent version.

    I tested in vanilla essentials, only with the Changing Controls feature, made by yourself.

    Thanks in advance!
     

    FL

    Pokémon Island Creator
    2,450
    Posts
    13
    Years
    • Seen today
    Sorry for the necropost, but what are the changes that I need to make in Pokémon Essentials 16.2? There are some sections that don't exist anymore in the recent version, and I guess all the scripts changed their names so I can't easily find which sections I need to modify.

    Before anything, I did Ctrl+F in every scripts, and couldn't find some of the sections that showed-up in the tutorial. So I'm sure that some scripts, despise having similar functionalities, got modifications in the Essentials 16.2 that makes this tutorial rather useless for now.

    I would be glad if you could update the tutorial to make it work with the most recent version.

    I tested in vanilla essentials, only with the Changing Controls feature, made by yourself.

    Thanks in advance!
    Done!
     
    Back
    Top