The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Create & Discover > Game Development > Scripts & Tutorials
Reload this Page Essentials Tutorial Register multiple items
Sign Up Rules/FAQ Daily Battle Blogs Mark Forums Read


Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.

Reply
 
Thread Tools
  #1    
Old July 28th, 2013 (6:13 AM). Edited 3 Days Ago by FL.
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,623
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=([email protected]) ? 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
Attached Images
   
__________________
Reply With Quote

Relevant Advertising!

  #2    
Old July 28th, 2013 (7:34 AM).
Maruno's Avatar
Maruno Maruno is offline
Lead Dev of Pokémon Essentials
 
Join Date: Jan 2008
Location: England
Posts: 5,145
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.
__________________
Reply With Quote
  #3    
Old July 28th, 2013 (8:02 AM).
venom12's Avatar
venom12 venom12 is offline
Pokemon Crystal Rain Relased
 
Join Date: Sep 2006
Age: 25
Gender: Male
Nature: Adamant
Posts: 528
Send a message via Windows Live Messenger to venom12
Yah i also think about the open list something like in Pokemon BW. Btw good tutorial
Reply With Quote
  #4    
Old July 28th, 2013 (7:57 PM).
Black Eternity's Avatar
Black Eternity Black Eternity is offline
Lord of Eternity
 
Join Date: Sep 2012
Age: 23
Gender: Male
Posts: 59
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.
__________________

[Pokemon Essentials Scripts]
Banking System: Here
Berry Trading System: Here
Reply With Quote
  #5    
Old July 28th, 2013 (10:13 PM).
thor348's Avatar
thor348 thor348 is offline
That's Oak to You
 
Join Date: Nov 2012
Location: Albion
Gender: Male
Nature: Calm
Posts: 135
Quote:
Originally Posted by FL . View Post

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.
Reply With Quote
  #6    
Old August 3rd, 2013 (3:01 PM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,623
Quote:
Originally Posted by Maruno View Post
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.

Quote:
Originally Posted by thor348 View Post
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.
__________________
Reply With Quote
  #7    
Old August 4th, 2013 (11:02 AM). Edited August 4th, 2013 by Wootius.
Wootius's Avatar
Wootius Wootius is offline
Glah
 
Join Date: Mar 2013
Gender: Male
Posts: 306
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!
__________________
Pokemon Rebalanced: Red
Where every Pokemon is useful.
Reply With Quote
  #8    
Old August 5th, 2013 (4:52 PM).
Rayd12smitty's Avatar
Rayd12smitty Rayd12smitty is offline
Shadow Maker
 
Join Date: Dec 2011
Gender: Male
Posts: 647
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.
__________________
Reply With Quote
  #9    
Old August 8th, 2013 (3:22 PM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,623
A trivia: I spend more time detailing the steps of where copy/paste the code than making the feature itself.
Quote:
Originally Posted by Rayd12smitty View Post
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.
__________________
Reply With Quote
  #10    
Old December 1st, 2013 (7:14 PM).
Rayd12smitty's Avatar
Rayd12smitty Rayd12smitty is offline
Shadow Maker
 
Join Date: Dec 2011
Gender: Male
Posts: 647
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?
__________________
Reply With Quote
  #11    
Old December 2nd, 2013 (2:06 AM).
venom12's Avatar
venom12 venom12 is offline
Pokemon Crystal Rain Relased
 
Join Date: Sep 2006
Age: 25
Gender: Male
Nature: Adamant
Posts: 528
Send a message via Windows Live Messenger to venom12
Quote:
Originally Posted by Rayd12smitty View Post
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.
Reply With Quote
  #12    
Old December 2nd, 2013 (6:01 PM).
Rayd12smitty's Avatar
Rayd12smitty Rayd12smitty is offline
Shadow Maker
 
Join Date: Dec 2011
Gender: Male
Posts: 647
Quote:
Originally Posted by venom12 View Post
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.
__________________
Reply With Quote
  #13    
Old 5 Days Ago (5:33 AM).
komaoto's Avatar
komaoto komaoto is offline
 
Join Date: Mar 2014
Gender: Male
Posts: 7
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!
Reply With Quote
  #14    
Old 3 Days Ago (12:20 PM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,623
Quote:
Originally Posted by komaoto View Post
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!
__________________
Reply With Quote
  #15    
Old 2 Days Ago (1:15 PM).
komaoto's Avatar
komaoto komaoto is offline
 
Join Date: Mar 2014
Gender: Male
Posts: 7
It worked wonderfully, thank you!!
Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 8:33 PM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2016 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2016 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.

Acknowledgements
Use of PokéCommunity Assets
vB Optimise by DragonByte Technologies Ltd © 2016.