Fandom

Pokémon Essentials Wiki

Tutorial:Register multiple items at once

227pages on
this wiki
Add New Page
Talk0 Share
Register multiple items at once
This tutorial was written by -FL-. Please give credit.

This tutorial is related to the following pages:

Click here for more tutorials!


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

when Input::F5

add

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 in http://irrlicht.sourceforge.net/docu/_keycodes_8h_source.html). Before line:

F5    = 25

add

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

LeftMouseKey  = 1

add

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:

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

to

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

Change

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

to

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

At PField_Field script section

Change

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

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

@keyItemCalling         = false

to

@keyItemCalling         = nil

At PScreen_Bag script section

Change

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

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

attr_reader :registeredItem

to

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

@registeredItem=0

to

@registeredItem=[]

Change

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
  @registeredItem=(item!=@registeredItem) ? item : 0
end

to

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

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

to

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

Change

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

to

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

Change

@bag.pbRegisterKeyItem(item)

to

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

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.