The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Creative Discussions > Game Development > Scripts & Tutorials
Sign Up Rules/FAQ Live Battle Blogs Mark Forums Read

Notices

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
Click here to go to the first staff post in this thread.  
Thread Tools
  #1    
Old July 28th, 2013, 06:13 AM
FL's Avatar
FL
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
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 PokemonControls 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 PokemonField 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 PokemonMap script section

Change

Code:
@keyItemCalling=false
to

Code:
@keyItemCalling=nil
At PokemonBag script section

Change

Code:
if @bag.registeredItem==@bag.pockets[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 !@registeredItem.is_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!=@registeredItem
    @registeredItem=item
  else
    @registeredItem=0
  end
end
to

Code:
def pbRegisterKeyItem(item,itemKeyNumber)
  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 && pbQuantity(item)<=0
to

Code:
index = registeredItem.index(item)
registeredItem[index]=nil if index && pbQuantity(item)<=0
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
   
__________________

Last edited by FL; August 3rd, 2013 at 02:54 PM.
Reply With Quote
  #2    
Old July 28th, 2013, 07:34 AM
Maruno's Avatar
Maruno
Lead Dev of Pokémon Essentials
 
Join Date: Jan 2008
Location: England
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, 08:02 AM
venom12's Avatar
venom12
Pokemon Crystal Rain Relased
 
Join Date: Sep 2006
Age: 23
Gender: Male
Nature: Adamant
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, 07:57 PM
Black Eternity's Avatar
Black Eternity
Lord of Eternity
 
Join Date: Sep 2012
Age: 21
Gender: Male
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
That's Oak to You
 
Join Date: Nov 2012
Location: Albion
Gender: Male
Nature: Calm
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, 03:01 PM
FL's Avatar
FL
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
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
lauerolus's Avatar
lauerolus
 
Join Date: Mar 2013
Gender: Male
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 by lauerolus; August 4th, 2013 at 11:07 AM.
Reply With Quote
  #8    
Old August 5th, 2013, 04:52 PM
Rayd12smitty's Avatar
Rayd12smitty
Shadow Maker
 
Join Date: Dec 2011
Gender: Male
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, 03:22 PM
FL's Avatar
FL
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
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, 07:14 PM
Rayd12smitty's Avatar
Rayd12smitty
Shadow Maker
 
Join Date: Dec 2011
Gender: Male
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, 02:06 AM
venom12's Avatar
venom12
Pokemon Crystal Rain Relased
 
Join Date: Sep 2006
Age: 23
Gender: Male
Nature: Adamant
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, 06:01 PM
Rayd12smitty's Avatar
Rayd12smitty
Shadow Maker
 
Join Date: Dec 2011
Gender: Male
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
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
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 12:29 AM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2014 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 - 2014 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.